Skip to content

MySQL string comparison limitation could break some backend operation #356

@j-maxi

Description

@j-maxi

According to MySQL spec (limitation), MySQL VARCHAR ignores trailing spaces on string comparison.
http://dev.mysql.com/doc/refman/5.7/en/char.html

MySQL collations are of type PADSPACE. This means that all CHAR, VARCHAR, and TEXT values in MySQL are compared without regard to any trailing spaces.

Also, the comparison is not case sensitive.
http://dev.mysql.com/doc/refman/5.7/en/case-sensitivity.html

Using MySQL as a DB and having "relation" between two resources in gohan schema, we rely on MySQL's foreign key constraint for validation. With the above limitation, I realized that resource relation could be created with case insensitive manner or ignoring trailing spaces. If we have some backend which resolves resource relation in strict string comparison, the backend cannot find the proper relation and could fail.

For example, if we have a schema like below, we can create resources customer.id = "abc" and device.customer_id = "ABC ". And as a results, backend operation will fail if it tried to resolve customer resource from device.customer_id with strict string comparison.

schemas:
- id: customer
  plural: customers
  schema:
      id:
        permission:
        - create
        type: string
    propertiesOrder:
    - id
    required:
    - id
    type: object
  singular: customer
  title: Customers
- description: Devices
  id: device
  plural: devices
  schema:
    properties:
      customer_id:
        permission:
        - create
        relation: customer
        type: string
        unique: false
      name:
        permission:
        - create
        - update
        type: string
    propertiesOrder:
    - name
    - customer_id
    required:
    - customer_id
    type: object
  singular: device
  title: Devices

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions