如何将 SQLite 绑定保存到 NSString 中

发布于 2024-11-07 20:09:24 字数 426 浏览 0 评论 0原文

我有以下用于绑定 SQLite 列的绑定语句。我想将此值保存到名为 journeyNameNSString 中。为此,我写了以下声明:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

我爱人 2024-11-14 20:09:24

试试这个。

    // Read the data from the result row
    NSString * journeyName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
    NSLog(@"journeyName - %@",journeyName);

供参考 - 示例代码

Try this.

    // Read the data from the result row
    NSString * journeyName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
    NSLog(@"journeyName - %@",journeyName);

For Reference - sample code

携君以终年 2024-11-14 20:09:24

我猜你应该写

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

陈独秀 2024-11-14 20:09:24

将您的代码替换为以下内容:

NSString *journeyName = sqlite3_bind_text( compiledStatement, 1, [Gjourney UTF8String], -1, SQLITE_TRANSIENT);

这应该可以工作。

Replace your code as the following:

NSString *journeyName = sqlite3_bind_text( compiledStatement, 1, [Gjourney UTF8String], -1, SQLITE_TRANSIENT);

THis should work.

感悟人生的甜 2024-11-14 20:09:24

sqlite3_bind_text 在执行 SQL 语句之前将文本值绑定到 SQL 参数。这意味着您已经拥有您传递的 NSString* 值。 sqlite3_bind_text 的返回值是 int 而不是 NSString*

如果您的意思是您想要执行 SQL 语句后返回到 SQL 语句的值,那么您需要查看 sqlite3_column_text

例如...

if (sqlite3_step(stmt) == SQLITE_ROW)
{
    char *cstr = (char*)sqlite3_column_text(stmt, 0); // 0 = the param index
    NSString *str = [NSString stringWithUTF8String:cstr];
}

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 the NSString* value that you are passing. The return value of sqlite3_bind_text is an int not NSString*.

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...

if (sqlite3_step(stmt) == SQLITE_ROW)
{
    char *cstr = (char*)sqlite3_column_text(stmt, 0); // 0 = the param index
    NSString *str = [NSString stringWithUTF8String:cstr];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文