0

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);
1
  • try some other column name than limit as a pre-caution, because "limit" is actually an sql command to limit the number of rows returned. Commented Nov 6, 2012 at 3:00

1 Answer 1

2

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);
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.