@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_IMGTAG_TABLE = "CREATE TABLE " + TABLE_IMAGE_TAG + "(" + TAG_ID + " TEXT REFERENCES TABLE_TAG (tag_id)," + IMG_ID + " TEXT REFERENCES TABLE_IMG (img_id),"
+ KEY_ID + " INTEGER, " + "INTEGER PRIMARY KEY(IMG_ID,TAG_ID,KEY_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);
}
大家好
我正在尝试创建 3 个包含图像数据、标签数据的表,第三个将图像和标签数据的 id 放入其中。我想使用图像表的 Id 和标记表的 Id 的引用创建第三个表,它们都是它们自己表中的主键。现在,如果我想将这些表的 id 值添加到我的第三个表中,我已经触发了上面的查询,但它不允许我创建它。它给了我语法错误:
09-10 14:52:13.741: E/Database(9850): Failure 1 (near "(": syntax error) on 0x223a80 when preparing 'CREATE TABLE img_tag_table(tag_id TEXT REFERENCES TABLE_TAG (tag_id),img_id TEXT REFERENCES TABLE_IMG (img_id),id INTEGER, INTEGER PRIMARY KEY(IMG_ID,TAG_ID,KEY_ID))'.