31

When typing a SQLite statement as a string literal in a class in Android Studio, the IDE gives me this warning: "<expr> expected, got '?'".

I don't understand what this means, but the code is working fine, and I'd like to disable the inspection. But I don't know which inspection is causing it. There are thousands of them, and searching for or expected yields no useful results.

The version of Android Studio is 3.0. It's happening with a whole bunch of different statements, but a typical one looks like this:

SQLiteStatement st = db.compileStatement(
   "INSERT OR REPLACE INTO routes(route_code, route_desc) VALUES(?,?)"
);
Dmitry
  • 6,716
  • 14
  • 37
  • 39
Flarosa
  • 1,287
  • 1
  • 13
  • 27
  • Can you post your full query statement? Also what version of Android Studio are you using? – cincy_anddeveloper Oct 30 '17 at 17:45
  • Latest version (3.0). It's happening with a whole bunch of different statements, but a typical one looks like this: SQLiteStatement st = db.compileStatement("INSERT OR REPLACE INTO routes(route_code, route_desc) VALUES(?,?)"); – Flarosa Oct 30 '17 at 17:47
  • I looked around and it appears that from Android Studio 3.0+ the SQLite syntax checker is much stricter. But I think it is expecting a space between the last comma and the question mark. Try adding the spacing and see if it works. Here some links: https://stackoverflow.com/questions/44205651/android-studio-3-0-canary-1-sql-syntax-error https://stackoverflow.com/questions/46165045/android-sqlite-queries-marked-as-error-by-android-studio Note: your code should be fine, SQLite still knows how to handle the syntax, AS just wants to enforce better syntactical habits. – cincy_anddeveloper Oct 30 '17 at 17:52
  • 1
    Thanks for the note. Adding the space didn't fix it. In fact it's happening with some statements that only have one ?. How do I access and disable these SQLite warnings? I can't find them in the preferences anywhere. – Flarosa Oct 30 '17 at 18:09
  • 2
    There's a bug report about this: https://issuetracker.google.com/issues/68403417 – laalto Oct 30 '17 at 18:18
  • 3
    Thanks. For now I worked around it by declaring my string on a separate line. – Flarosa Oct 30 '17 at 18:45

1 Answers1

12

This is a bug in Android Studio 3.0 and is already reported here. Also this is now fixed in the 3.1 version. I am using the latest Canary 5 3.1 build and it works fine.

Since there are not going to be anymore 3.0 patches, all you can do for now is to go with the workaround or disable this lint check.

Henry
  • 17,490
  • 7
  • 63
  • 98