0

I'm working with my first android SQL database and I have a strong feeling that something is wrong with my database creation sql statement. What am I missing guys?

private static final String CREATE_MOVES_TABLE = 
    "CREATE TABLE " + TABLE_MOVES + "(" + 
         KEY_ID + " INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1)," + 
         DATE + " TEXT,"  + 
         TRANSPORT + " TEXT," + 
         MARSH + " INTEGER," + 
         TIMEHOPON + " TEXT," + 
         TIMEHOPOFF + " TEXT" + 
    ");";

I don't have a field for key_id in my constructor (I feel that it might be the weak part).

2
  • what did you tried, Post ur code then peoples can able to tell solutions Commented Apr 1, 2017 at 13:54
  • wheres the SQL statement. Edit your post to include the statement. Much appreciated Commented Apr 1, 2017 at 13:54

1 Answer 1

1

There is no need to have KEY_ID passed into your constructor, it should be a constant value.

Also, you are doing a lot of extra work to get an autoincrement on your primary key. You can remove all that generated.. stuff and replace with autoincrement

class DB {

    private static final String KEY_ID = "id";
    private static final String DATE = "date";
    private static final String TRANSPORT = "transport";
    private static final String MARSH = "marsh";
    private static final String TIMEHOPON = "timehopon";
    private static final String TIMEHOPOFF = "timehopoff"; 

    private static final String CREATE_MOVES_TABLE = 
    "CREATE TABLE " + TABLE_MOVES + "(" 
        + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
        + DATE + " TEXT,"
        + TRANSPORT + " TEXT,"
        + MARSH + " INTEGER,"
        + TIMEHOPON + " TEXT,"
        + TIMEHOPOFF + " TEXT" + ");";


    // the rest of the class...

}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I removed generated... part and it works. And it even works correctly without Autoincrement part

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.