I created 4 table on my app. Below is the creation of the last table -
this is the query that i get after the parse of the string
CREATE TABLE IF NOT EXISTS TABLE_1 (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,PK_Person TEXT NOT NULL, FOREIGN KEY ( PK_Person ) REFERENCES TABLE_2 , COLUMN_INDEX_AS_TEXT TEXT NOT NULL, FOREIGN KEY( COLUMN_INDEX_AS_TEXT ) REFERENCES TABLE_3 );
When i run this method of creation - i get an exception that the value near the COLUMN_INDEX_AS_TEXT is
Error Code : 1 (SQLITE_ERROR) Caused By : SQL(query) error or missing database. (near "COLUMN_INDEX_AS_TEXT ": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS ..... ( the query )
I check and all the table that i create before this table are exist.
try
{
SQLiteDatabase db = getWritableDatabase();
String query = "CREATE TABLE IF NOT EXISTS " + TABLE_1 + "("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"
+ "PK_Person TEXT NOT NULL, FOREIGN KEY ( PK_Person )" + " REFERENCES " + TABLE_2 + ", "
+ COLUMN_INDEX_AS_TEXT + " TEXT NOT NULL, FOREIGN KEY( " + COLUMN_INDEX_AS_TEXT + " ) REFERENCES " + TABLE_3 + " );";
db.execSQL(query);
}
catch (Exception e)
{
Log.e(TAG, e.getMessage());
}