mardi 3 février 2015

Understanding iOS sqlite auto increment field

I have a table in my iOS sqlite database. (sqlite3.h with XCode 6.1.1, iOS SDK 8.1) There is a field 'ID' which is auto increment primary key.



create table IF NOT EXISTS PublicEvents(ID INTEGER PRIMARY KEY, eventName varchar(50), startDate varchar(8), startTime varchar(6), endDate varchar(8), endTime varchar(6), Location varchar(200), Description varchar(1000))"



According to this tutorial: http://ift.tt/M8V74w , The insert command should be:



insert into PublicEvents values(NULL, 'TestEvent', '20150203', '233000', '20150204', '013000', 'Location', 'Description\n\nMultiple Lines Test');



However, I got this error message:



table PublicEvents has 7 columns but 8 values were supplied



Then I tried the following command:



insert into PublicEvents values('TestEvent', '20150203', '233000', '20150204', '013000', 'Location', 'Description\n\nMultiple Lines Test');



It works but I cannot get the 'ID' row. If I do:



sqlite3_column_text(statement, 0);



It will return 'eventName' value not 'ID'


So how can I insert and get 'ID' row correctly?


Aucun commentaire:

Enregistrer un commentaire