Reputation: 183
I decided to add a second table for my app. I keep getting a syntax error even though its almost exactly the same setup as the first table creation string.
private static final String BUDGET_TABLE = "budgets";
private static final String KEY_ROW_ID_BUDGET = "_id";
private static final String KEY_BUDGET_LIMIT = "limit";
private static final String KEY_BUDGET_CURRENT_AMOUNT = "current_amount";
This string throws the syntax error near 'limit'
private static final String BUDGET_CREATE =
"create table "+ BUDGET_TABLE +" ( "+ KEY_ROW_ID_BUDGET+" integer primary key autoincrement, "
+ KEY_BUDGET_LIMIT+" text not null, "+ KEY_BUDGET_CURRENT_AMOUNT+" text);";
db.execSQL(BUDGET_CREATE);
Upvotes: 0
Views: 67
Reputation: 29670
Its simple, you can/should not use keywords while creating table. You are using limit
as column which is invalid, hence it is giving you runtime error, i suggest you to change it to something like budget_limit
like below, and then try again.
private static final String BUDGET_TABLE = "budgets";
private static final String KEY_ROW_ID_BUDGET = "_id";
private static final String KEY_BUDGET_LIMIT = "budget_limit";
private static final String KEY_BUDGET_CURRENT_AMOUNT = "current_amount";
private static final String BUDGET_CREATE =
"create table "+ BUDGET_TABLE +" ( "+ KEY_ROW_ID_BUDGET+" integer primary key autoincrement, "
+ KEY_BUDGET_LIMIT+" text not null, "+ KEY_BUDGET_CURRENT_AMOUNT+" text);";
db.execSQL(BUDGET_CREATE);
Upvotes: 2