I have 3 SQLite tables. Each has an ID as primary key; if I provide a NULL when inserting a record to ID, it will auto-increment the key (at least that's what the SQLite docs say). I am trying to get the NULL into this insert statement, but it crashes ('NSInvalidArgumentException', reason: '* -[NSPlaceholderString initWithFormat:locale:arguments:]: nil argument' ). Here is a snippet of the statement (dbCmd is defined as NSString):
dbCmd = @"INSERT INTO CustData (ID, BUS_NAME, EMAIL, PHONE, SHOP_NAME, SHOP_ADDR1, SHOP_ADDR2, SHOP_CITY_STATE, SHOP_ZIP, "
"SHIP_NAME, SHIP_ADDR1, SHIP_ADDR2, SHIP_CITY_STATE, SHIP_ZIP, SALES_NAME, NOTES) VALUES('";
dbCmd = [dbCmd stringByAppendingFormat:NULL]; // <--------------------
dbCmd = [dbCmd stringByAppendingString: [methodParameters objectForKey: @"businessName"]];
dbCmd = [dbCmd stringByAppendingString: @"', '"];
dbCmd = [dbCmd stringByAppendingString: [methodParameters objectForKey: @"email"]];
How do I fix this?
From the sqlite docs:
If no ROWID is specified on the insert, or if the specified ROWID has a value of NULL, then an appropriate ROWID is created automatically.
http://www.sqlite.org/autoinc.html
If you have no specific reason to specify the ID, you can simply leave it out!