mercredi 7 janvier 2015

SQLite id field - autofill

I've added a new table to my DB:



CREATE TABLE myTable (
myId ID NOT NULL,
aNumber INTEGER NOT NULL,
anUniqueTextId TEXT NOT NULL,
aText TEXT,
PRIMARY KEY(myId, anUniqueTextId) ON CONFLICT IGNORE,
FOREIGN KEY(anUniqueTextId, aNumber) REFERENCES otherTable(otherTableId, otherTableValue2) ON DELETE CASCADE
);


Now I want to insert values without manually finding out which index should I put in myId field:



[myDatabase inTransaction:^(FMDatabase *db, BOOL *rollback) {
[db executeUpdate:@"INSERT INTO myTable VALUES(?,?,?)",
// @(myData.myId), //I don't want to insert it manually
@(aNumber),
myData.anUniqueTextId,
myData.aText];

if (db.lastErrorCode) {
NSLog(@"Huston, we've got a problem: %@", db.lastError.localizedDescription);
}
}];


Ofc, I get here an error telling:



table myTable has 4 columns but 3 values were supplied


Now the question is how to insert the data to make this field autoinsert myId? I'm not sure if my insert code is invalid or CREATE TABLE statement.


Aucun commentaire:

Enregistrer un commentaire