将零值插入Sqlite数据库? [英] Inserting nil Values into Sqlite Database?

查看:90
本文介绍了将零值插入Sqlite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iPhone应用程序,在该应用程序中,我从XML文件中提取数据并将其插入到位于该应用程序中的sqlite数据库中.我能够成功完成此过程,但似乎如果我尝试使用值为"nil"的NSString来sqlite3_bind_text,则该应用程序会迅速终止.

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);

推荐答案

您是否尝试过以下方法:

Have you tried something like:

sqlite3_bind_text(compiledStatement, 2, valuevar==nil?"":[valuevar UTF8String], -1, SQLITE_TRANSIENT);

这篇关于将零值插入Sqlite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆