question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL keywords in column names

See original GitHub issue

Using 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:closed
  • Created 7 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
AlecStrongcommented, Sep 12, 2016

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

0reactions
mingtaozhangsccommented, Jun 6, 2018

Ohh, that makes sense.

My use case is the former one. Found https://github.com/square/sqldelight/blob/master/ALPHA.md#migrations.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found