Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax errors for empty strings and string using syntax restricted symbols #42

Open
2shady4u opened this issue Apr 2, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@2shady4u
Copy link
Owner

2shady4u commented Apr 2, 2021

Creation of the following table_dict results in syntax errors of the query:

var table_dict : Dictionary = Dictionary()
table_dict["last_name"] = {"data_type":"char(5)", "default": "Silver"}
table_dict["first_name"] = {"data_type":"char(5)", "default": "Long John"}
table_dict["area"] = {"data_type":"char(5)", "default": ""}
table_dict["color"] = {"data_type":"char(255)", "default": "0,0,0,0"}

Encapsulating all strings with single quotation marks seems to fix the issue:

var table_dict : Dictionary = Dictionary()
table_dict["last_name"] = {"data_type":"char(5)", "default": "'Silver'"}
table_dict["first_name"] = {"data_type":"char(5)", "default": "'Long John'"}
table_dict["area"] = {"data_type":"char(5)", "default": "''"}
table_dict["color"] = {"data_type":"char(255)", "default": "'0,0,0,0'"}

However, the subtleties of adding these quotation marks is never mentioned anywhere in the documentation.
To make it even more confusing, the "Silver" default value (without single quotation marks) actually works and creates the exact same default value in the database.

As it is difficult to know the user's intention, it is quite a hassle to add these quotation marks in the plugin itself as it might not even by the user's intention to add them. . . (since SQLite uses dynamic typing and column types aren't enforced)

Proposed convention:

  • Always encapsulate strings in single quotation marks, especially when:
    • The string is empty
    • The string contains syntax restricted symbols such as commas or spaces

In both cases the user is recommended to find other ways of setting his/her default value, such as:

  • Leaving the default value empty, which results in a NULL value instead of an empty string and is also easily checked for in code.
  • If fixed arrays are to be parsed, switch those arrays to single fields. For example, in case of a 3D position, it is recommended and easy to just make 3 separate columns instead (position_x, position_y, position_z).

For non-fixed length arrays, it might be possible to use this. Although I'm not sure if the cost of implementing and maintaining these structures is worth it in the long run?

@2shady4u 2shady4u added bug Something isn't working question Further information is requested labels Apr 4, 2021
@2shady4u 2shady4u self-assigned this Apr 4, 2021
@2shady4u 2shady4u removed the question Further information is requested label Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant