-1

I am writing tests for my database and right now the table below is not building and the test is failing with this SQL command being built: " CREATE TABLE location (_id INTEGER PRIMARY KEY,location_setting TEXT UNIQUE NOT NULL, city_name TEXT NOT NULL, coord_lat REAL NOT NULL coord_long REAL NOT NULL ); ". I am pretty certain there is some syntax error yet I am new to databases in android and honestly need help.

Table creation:

@Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +
                LocationEntry._ID + " INTEGER PRIMARY KEY," +
                LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL, " +
                LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +
                LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL " +
                LocationEntry.COLUMN_COORD_LONG + " REAL NOT NULL " +
                " );";
    }

Thanks for the help.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Tom Finet
  • 487
  • 1
  • 7
  • 21

2 Answers2

3

You need to add ',' after every column like this just leave the last.

    final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +
            LocationEntry._ID + " INTEGER PRIMARY KEY," +
            LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL, " +
            LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +
            LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL, " +
            LocationEntry.COLUMN_COORD_LONG + " REAL NOT NULL" +
            " );";
Umer Asif
  • 441
  • 1
  • 4
  • 15
-1

You can not use TEXT with UNIQUE.

For more info: make text column as unique key.

You can try VARCHAR or think of a different implementation to reach your goal.

Bye

Community
  • 1
  • 1
Amedeo Baragiola
  • 314
  • 4
  • 14