Monday, 9 September 2013

Sqlite table creation does not allow to create table

Sqlite table creation does not allow to create table

@Override
public void onCreate(SQLiteDatabase db) {
final String CREATE_IMAGE_TABLE = "CREATE TABLE " + TABLE_IMG + "("
+ KEY_ID + " INTEGER PRIMARY KEY autoincrement," +
KEY_IMAGE_NAME + " TEXT,"
+ KEY_PATH + " TEXT" + ")";
final String CREATE_TAG_TABLE = "CREATE TABLE " + TABLE_TAG + "("
+ KEY_ID + " INTEGER PRIMARY KEY autoincrement," +
KEY_TAG_NAME + " TEXT,"
+ KEY_TAG_DATE + " INTEGER" + ")";
final String CREATE_IMAGE_TAG_TABLE = "CREATE TABLE " +
TABLE_IMAGE_TAG + "("
+ IMAGE_ID + " INTEGER REFERENCES CREATE_IMAGE_TABLE(id)," +
TAG_ID + " INTEGER REFERENCES CREATE_TAG_TABLE(id),"
+ IMG_TAG + " PRIMARY KEY (IMAGE_ID, TAG_ID) " + ")";
db.execSQL(CREATE_IMAGE_TABLE);
db.execSQL(CREATE_TAG_TABLE);
db.execSQL(CREATE_IMAGE_TAG_TABLE);
Log.i("TAG", "TABLES CREATED" + CREATE_IMAGE_TAG_TABLE);
}
Hello All
I am trying to create 3 tables with image data, tag data and 3rd having
the id's of image and tag data into it. I want to create 3rd table with
the references of image table's Id and tag table's Id which are both
primary key's in their own table. Now if i want to add id's values of
these tables into my third table i have fired the query as above but it
does not let me create it. It gives me syntax error:
09-09 13:12:48.520: E/Database(3944): Failure 1 (near "(": syntax error)
on 0x220680 when preparing 'CREATE TABLE img_tag(img_id INTEGER REFERENCES
CREATE_IMAGE_TABLE(id),tag_id INTEGER REFERENCES
CREATE_TAG_TABLE(id),img_tag PRIMARY KEY (IMAGE_ID, TAG_ID) )'.

No comments:

Post a Comment