如何将 SQLite 绑定保存到 NSString 中
我有以下用于绑定 SQLite 列的绑定语句。我想将此值保存到名为 journeyName
的 NSString
中。为此,我写了以下声明:
NSString * journeyName = sqlite3_bind_text( compiledStatement, 1,
[Gjourney UTF8String], -1,
SQLITE_TRANSIENT );
这给了我一个警告:
初始化使指针来自整数而不进行强制转换
,并且我的应用程序崩溃了。
I have the following bind statement for binding an SQLite column. I want to save this value into an NSString
named journeyName
. For this I have written the following statement:
NSString * journeyName = sqlite3_bind_text( compiledStatement, 1,
[Gjourney UTF8String], -1,
SQLITE_TRANSIENT );
This gives me a warning that
initialization makes pointer from integer without a cast
and my app crashes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个。
供参考 - 示例代码
Try this.
For Reference - sample code
我猜你应该写
NSString* JourneyName = sqlite3_bind_text(compileStatement, 1, [Gjourney UTF8String], -1, SQLITE_TRANSIENT);
My guess you should have written
NSString* journeyName = sqlite3_bind_text( compiledStatement, 1, [Gjourney UTF8String], -1, SQLITE_TRANSIENT);
将您的代码替换为以下内容:
这应该可以工作。
Replace your code as the following:
THis should work.
sqlite3_bind_text
在执行 SQL 语句之前将文本值绑定到 SQL 参数。这意味着您已经拥有您传递的NSString*
值。sqlite3_bind_text
的返回值是int
而不是NSString*
。如果您的意思是您想要执行 SQL 语句后返回到 SQL 语句的值,那么您需要查看 sqlite3_column_text。
例如...
sqlite3_bind_text
binds a text value to a SQL parameter prior to executing the SQL statement. This means that you are already in possession of theNSString*
value that you are passing. The return value ofsqlite3_bind_text
is anint
notNSString*
.If you mean that you want to the value that is returned to the SQL statement following executing it, then you need to look at sqlite3_column_text.
For example...