1

I know this is probably a simple syntax error, but I am new to SQLite and I have searched high and low for this simple answer but I can not. I know it is possible to use String Constants when creating a table as I have done it before, but when setting a default text value it is not working for me. Help please!

public static final String USER_TABLE = "USER_TABLE";

   //works fine here!
   db.execSQL("CREATE TABLE " + USER_TABLE+
            "(_id INTEGER PRIMARY KEY AUTOINCREMENT,"
            + FFDBSchema.Colz.MODE_ID_COL + "TEXT DEFAULT NULL,"
            //doesn't work here!
            + FFDBSchema.Colz.TABLE_ID_COL + "TEXT DEFAULT "  + 
            USER_TABLE+","
            + FFDBSchema.Colz.ANOTHER_TABLE+ "TEXT,"  + 

String constants work in other situations but is it simply that I can't use a string constant to set a default column value? Must I insert it?

1 Answer 1

1

You have to quote strings with single quotes, so you need to do something like this:

public static final String USER_TABLE = "USER_TABLE";

db.execSQL("CREATE TABLE " + USER_TABLE+
        "(_id INTEGER PRIMARY KEY AUTOINCREMENT,"
        + FFDBSchema.Colz.MODE_ID_COL + "TEXT DEFAULT NULL,"
        + FFDBSchema.Colz.TABLE_ID_COL + "TEXT DEFAULT '" +USER_TABLE+"',"
        + FFDBSchema.Colz.ANOTHER_TABLE+ "TEXT,"  + 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.