rank is an SQL reserved word since MySQL 8.0.2: but we are using it as a field name in the Diagnosis class
Had the below SQL error while trying to create a Visit Note via the OWA; the whole exercise was part of testing my newly added Diagnosis Attribute/Type classes
Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'rank)
values ('09aafee4-c8a1-4f17-a185-c9e2cda72363',
null, 1, null, '2021-10-31' at line 1
mysql --version
mysql Ver 8.0.26 for macos10.15 on x86_64 (Homebrew)
@herbert24, the field named rank was already in the Diagnosis class prior to the changes made to make the Diagnoses Attributable. It may be just a variable but because of usage in other classes and possibly clients, I was hesitant to just rename it.
Renaming rank would imply renaming the associated setters and getters which more certainly than not will be problematic for the Diagnosis clients.
Shouldn’t the fieldnames be quoted in the query?
Using backpacks as quotes around fieldnames removes the risk of a fieldname becoming a reserved word in the future.
I do not know how OpenMRS is building and executing queries, but this is how the Python Django framework handles this issue.
Thanks @burke that should be the most viable and safest solution since we use Liquibase for schema evolution @tansentim OpenMRS core uses Hibernate for mapping Java classes to database tables and Java data types to SQL data types. (The equivalent of SQL Alchemy in the python world). Handling this at query level may require a lot of trivial changes.