何时使用 SQLITE_TRANSIENT 与 SQLITE_STATIC? [英] When to use SQLITE_TRANSIENT vs SQLITE_STATIC?

查看:50
本文介绍了何时使用 SQLITE_TRANSIENT 与 SQLITE_STATIC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 sqlite3 中创建/更新文本列.在创建/更新后检索行时,文本为?".但是,整数值会正确保留.

I would like to create/update text columns in sqlite3. When i retrieve rows after the create/update, the text is '?'. Integer values are properly persisted however.

我的文本语句如下所示:

My text statements look like this:

const char *sql = "INSERT INTO todo(title, description, priority, status, created, expires, posx, posy, updated)"
                  " VALUES('?', '?', '?', '?', '?', '?', '?', '?', '?');";
if (sqlite3_prepare_v2(database, sql, -1, &insert_statment, NULL) != SQLITE_OK)
    ...
sqlite3_bind_text(update_statment, 5, [[dt stringFromDate:self.updated] UTF8String], -1, SQLITE_TRANSIENT);

我尝试过 SQLITE_TRANSIENT 和 SQLITE_STATIC.这两种情况似乎产生相同的结果('?').我还验证了文本值在此处传递到适当的 sql 语句时是否有效.

I've tried SQLITE_TRANSIENT as well as SQLITE_STATIC. Both cases seem to yield same results ('?'). I have also verified that the text values are valid when they are passed into the appropriate sql statements here.

有什么想法吗?

推荐答案

删除 ' 字符周围的 ?在您的 sql 字符串中.

Remove the ' characters around ? in your sql string.

SQLITE_TRANSIENT 告诉 SQLite 复制你的字符串.当您的字符串(的缓冲区)将在查询执行之前消失时使用它.

SQLITE_TRANSIENT tells SQLite to copy your string. Use this when your string('s buffer) is going to go away before the query is executed.

SQLITE_STATIC 告诉 SQLite,您承诺传递给字符串的指针将在执行查询之前有效.当您的缓冲区是静态的,或者至少具有超出绑定范围的动态范围时,请使用它.

SQLITE_STATIC tells SQLite that you promise that the pointer you pass to the string will be valid until after the query is executed. Use this when your buffer is, um, static, or at least has dynamic scope that exceeds that of the binding.

这篇关于何时使用 SQLITE_TRANSIENT 与 SQLITE_STATIC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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