0

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?

SpokaneDude
  • 4,856
  • 13
  • 64
  • 120
  • Do you have a specific reason for not omitting ID in the INSERT altogether? – Kjir May 25 '12 at 17:09
  • I thought I had to have an ID which is the primary key, so SQLite can auto-increment it... are you telling me that if I omit it, it will still work properly? – SpokaneDude May 25 '12 at 17:15
  • Yes! If you omit ID, it will autoincrement (if it's an autoincrement column) – Kjir May 25 '12 at 17:20

1 Answers1

0

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!

Kjir
  • 4,437
  • 4
  • 29
  • 34