English 中文(简体)
如何在SQLite插入语句中获取NULL?
原标题:How do I get a NULL into this SQLite insert statement?

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"]];

我该如何解决这个问题

最佳回答

从sqlite文档中:

如果插入中没有指定ROWID,或者指定的ROWID的值为NULL,则会自动创建适当的ROWID。

http://www.sqlite.org/autoinc.html一

如果你没有具体的理由指定ID,你可以简单地省略它!

问题回答

暂无回答




相关问题
sqlite3 is chopping/cutting/truncating my text columns

I have values being cut off and would like to display the full values. Sqlite3 -column -header locations.dbs " select n.namelist, f.state, t.state from names n left join locations l on l.id = n.id ...

Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Improve INSERT-per-second performance of SQLite

Optimizing SQLite is tricky. Bulk-insert performance of a C application can vary from 85 inserts per second to over 96,000 inserts per second! Background: We are using SQLite as part of a desktop ...

Metadata for columns in SQLite v2.8 (PHP5)

How can I get metadata / constraints (primary key and "null allowed" in particular) for each column in a SQLite v2.8 table using PHP5 (like mysql_fetch_field for MySql)? sqlite_fetch_column_types (OO:...

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...