android - creating a foreign key in sqlite database -
i need create foreign key map tables. foreign primary key of table. insert statement creting issue. sqlite database. table primary key is
db.execsql("create table if not exists " + main + "(rowid integer primary key autoincrement not null,appln_date varchar,appln_no varchar,rupees varchar,tenure varchar,asset varchar);");
the table foreign key
db.execsql("create table if not exists " + applicant + "(appid integer primary key autoincrement, " + "app_salutation varchar,app_fname varchar,app_mname varchar,app_lname varchar,app_door varchar,app_street varchar,app_building varchar,app_area varchar,app_post varchar,app_tehsil varchar,app_state varchar,app_landmark varchar,rowid integer references "+main+"(rowid));");
the insert statement
openorcreatedatabase(); createappinfo(); string insertstring = "insert " + applicant + " values("; string instring = ""; (int =0; < data.size(); i++) { instring = instring + "\"" + data.get(i) + "\","; } instring = instring.substring(0, instring.length() - 1); int row=db.rawquery("select * "+main+";" ,null).getcount()+1; insertstring = insertstring + row+"," +instring + ");"; system.out.println("** insert value ** " + insertstring); db.execsql(insertstring); closedatabase();
but code generating error..
04-25 11:43:57.422: e/sqlitelog(17825): (1) table applicanttable has 14 columns 13 values supplied
you should make on database statements this:
create table if not exists "main" (rowid integer primary key autoincrement not null,appln_date varchar,appln_no varchar,rupees varchar,tenure varchar,asset varchar); create table if not exists "applicant" (appid integer primary key autoincrement, app_salutation varchar,app_fname varchar,app_mname varchar,app_lname varchar,app_door varchar,app_street varchar,app_building varchar,app_area varchar,app_post varchar,app_tehsil varchar,app_state varchar,app_landmark varchar,rowid integer references "main"(rowid)); insert "applicant" values("11","a","b","c","d","e","f","g","h","i","j","k","l", (select count(*) +1 main));
the values in example random.
so if 100% sure statement return values except last one. last argument should this:
insertstring = "rowid integer references "main"(rowid);";