Problem with inserting into android sqlite3 table that has composite primary key -


i have table composite primary key , having trouble inserting. code used create table is:

create table classevent (     eventname varchar(10) not null,      courseid varchar(10) not null,      eventtype varchar(20),      eventweight number(3),      duedate date not null,      foreign key (courseid) references courses(courseid),      primary key (courseid, eventname)); 

the problem having when want insert records have values may not unique columns courseid or eventname, unique combination of 2. example, if try run following 2 inserts:

insert classevent values('assignment 1','60-415','assignment',10,'12/10/2010'); insert classevent values('project 1','60-415','project',15,'5/12/2010'); 

i following error:

error: columns courseid, eventname not unique. 

and second insert not make db. why error out? thought composite primary key requires combination of both values unique. in above inserts, values eventname column different though values courseid same. shouldn't seen 2 unique combinations , 2 different primary keys?

my table needs able hold several different events each courseid, each event must unique each course. need able insert values table like:

eventname courseid assignment 1 60-415 project 1 60-415 assignment2 60-415 project 2 60-415 assignment 1 60-367 project 1 60-367

and on. can tell me how can work? why these composite pk's not being seen unique entries? appreciated.


here java function using insert:

public void addnewclassevent(contentvalues values) {     sqlitedatabase db = openconnection();      db.insert("classevent", null, values);     db.close(); } 

could causing problem?

you can have composite primary key in sqlite, have create key when create table:

   create table example1(       field1 float,       field2 text,       primary key(field1, field2)    ); 

you cannot create primary key after fact using alter table.

on other hand, can create unique index after fact has same effect primary key:

   create unique index pk_index on "table1"("field1","field2"); 

i not sure how have created, tables, , if have added primary index later, grab database desktop, , check out how works in desktop environment.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -