SQL keywords in column names
See original GitHub issueUsing SQL keyword in CreateTable statement ends with crash for SQLDelight. For example for this:
CREATE TABLE TEST (
Id INTEGER NOT NULL,
Action TEXT,
TestInt INTEGER
);
build fails with this:
Error:Execution failed for task ':app:generateQaDebugSqlDelightInterface'.
test.sq line 3:0 - no viable alternative at input ',\r\nAction'
So I simply add “[]” around keyword, and it builds with success but column name generates with this brackets.
Example:
CREATE TABLE TEST (
Id INTEGER NOT NULL,
[Action] TEXT,
TestInt INTEGER
);
generates:
String TABLE_NAME = "TEST";
String ID = "Id";
String ACTION = "[Action]";
String TESTINT = "TestInt";
String CREATE_TABLE = ""
+ "CREATE TABLE TEST (\r\n"
+ "Id INTEGER NOT NULL,\r\n"
+ "[Action] TEXT,\r\n"
+ "TestInt INTEGER\r\n"
+ ")";
In my opinion String ACTION = "[Action]";
should be String ACTION = "Action";
For now every usage of cursor.getColumnIndexOrThrow(ACTION)
ends with java.lang.IllegalArgumentException: column '[Action]' does not exist
Issue Analytics
- State:
- Created 7 years ago
- Comments:13
Top Results From Across the Web
sql server - How to deal with SQL column names that look like ...
Use double quotes " " to name such columns. E.g. type is a SQL reserved keyword, and when used within quotes, type is...
Read more >How to Use Reserved Words as Column Names in SQL?
Step 3: Create a table inside the database GeeksForGeeks. We will name the table BIKE. It will contain 2 columns named SELECT and...
Read more >SQL Keywords Reference - W3Schools
This SQL keywords reference contains the reserved words in SQL. ... ALTER COLUMN, Changes the data type of a column in a table....
Read more >Reserved Keywords (Transact-SQL) - Microsoft Learn
Transact-SQL reserved keywords can be used as identifiers or names of databases or database objects, such as tables, columns, views, and so on....
Read more >Cannot handle column names that match SQL keywords. #186
Putting the table name and column names in a quote (') works fine: SELECT `Areas`.`uuid`,`Areas`.`order` FROM `Areas`. But I have not find where ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
oh nevermind you’re saying the cursor doesn’t know about that column name so it errors. Gotchya. This would actually be a good case for the android tests #315 since the sqlite query works fine but the android bindings behave differently and require the string constant to not have braces
Ohh, that makes sense.
My use case is the former one. Found https://github.com/square/sqldelight/blob/master/ALPHA.md#migrations.