将 nil 值插入 Sqlite 数据库?
我正在开发一个 iPhone 应用程序,从 XML 文件中提取数据并将其插入到应用程序中的 sqlite 数据库中。我能够成功地完成此过程,但似乎如果我尝试使用值为“nil”的 NSString 来 sqlite3_bind_text,该应用程序很快就会死掉。
这是失败的代码示例:(针对此示例进行了修改)
// idvar = 1
// valuevar = nil
const char *sqlStatement = "insert into mytable (id, value) VALUES(?, ?)";
sqlite3_stmt *compiledStatement = nil;
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
sqlite3_bind_int(compiledStatement, 1, [idvar intValue]);;
sqlite3_bind_text(compiledStatement, 2, [valuevar UTF8String], -1, SQLITE_TRANSIENT);
I am working on an iPhone App where I am pulling data from an XML file and inserting it into a sqlite database located in the App. I am able to successfully do this process, but it appears that if I try to sqlite3_bind_text with a NSString that has a value of "nil", the App quickly dies.
This is an example of code that fails: (modified for this example)
// idvar = 1
// valuevar = nil
const char *sqlStatement = "insert into mytable (id, value) VALUES(?, ?)";
sqlite3_stmt *compiledStatement = nil;
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
sqlite3_bind_int(compiledStatement, 1, [idvar intValue]);;
sqlite3_bind_text(compiledStatement, 2, [valuevar UTF8String], -1, SQLITE_TRANSIENT);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有没有尝试过类似的事情:
Have you tried something like: