dimanche 3 janvier 2016

Syntax to create unique composite column - Android SQLiteOpenHelper

Hi I have this onCreate method in my SQLiteOpenHelper class and I would like to add a unique constraint and I want it for these two columns (composite unique columns):

SongContract.SongEntry.COLUMN_TITLE

SongContract.SongEntry.COLUMN_RELEASEDATE

The problem is I am getting an error: Cannot resolve method UNIQUE

here is my method:

public void onCreate(SQLiteDatabase db) {

final String SQL_CREATE_SONG_TABLE = "CREATE TABLE " + SongContract.SongEntry.TABLE_SONG + " (" +
        SongContract.SongEntry._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
        SongContract.SongEntry.COLUMN_TITLE + " TEXT NOT NULL, " +
        SongContract.SongEntry.COLUMN_RELEASEDATE + " INTEGER, " +
        UNIQUE(SongContract.SongEntry.COLUMN_TITLE, SongContract.SongEntry.COLUMN_RELEASEDATE) +
        SongContract.SongEntry.COLUMN_RATING + " TEXT);";

db.execSQL(SQL_CREATE_SONG_TABLE);

}

Can anyone please help what is the correct syntax to achieve my goal? Thanks.

Aucun commentaire:

Enregistrer un commentaire