I think this is a new error since switching to Android Studio 3.0. I am receiving a lint syntax error:
<pragma value> expected, got 'ON'
I get this error only on the first of the following two methods:
private static void setForeignKeyConstraintsEnabled(@NonNull SQLiteDatabase db) {
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=ON;");
}
}
private static void setForeignKeyConstraintsDisabled(@NonNull SQLiteDatabase db) {
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=OFF;");
}
}
I only found one suggested fix on the internet as of writing. It is in german and says that I shouldn't be using constant strings for pragma but should use a string parameter.
String query = String.format ("PRAGMA foreign_keys = %s","ON");
db.execSQL(query);
But I suspect if this removes the error, it only does so by making the code too complicated for the lint rule to detect.
Why would ON throw an error and not OFF? Is my syntax wrong?
Using the signed integer alternative syntax worked.
private static void setForeignKeyConstraintsEnabled(@NonNull SQLiteDatabase db) {
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=1;");
}
}
private static void setForeignKeyConstraintsDisabled(@NonNull SQLiteDatabase db) {
if (!db.isReadOnly()) {
db.execSQL("PRAGMA foreign_keys=0;");
}
}
Interestingly, using the alternative syntax of yes/no flagged an error on no but not yes. I agree with @CommonsWare that this seems to be a lint bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With