gpt4 book ai didi

c++ - WHERE 列 = 值,仅适用于 INTEGER 值

转载 作者:行者123 更新时间:2023-11-28 04:07:58 42 4
gpt4 key购买 nike

我在 C++ 项目上使用 sqlite,但是当我在具有文本值的列上使用 WHERE 时出现问题

我创建了一个 sqlite 数据库:

    CREATE TABLE User( id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(24))

当我尝试获取具有 VARCHAR 值的列的值时,它不起作用,并在 sqlite3_step 之后返回给我一个 STATUS_CODE 101 :

int res = 0;
sqlite3_stmt *request;
char *sqlSelection = (char *)"SELECT * FROM User WHERE name='bob' ";
int id = 0;

res = sqlite3_prepare_v2(db, sqlSelection, strlen(sqlSelection), &request, NULL);

if (!res){
while (res == SQLITE_OK || res == SQLITE_ROW){
res = sqlite3_step(request);
if (res == SQLITE_OK || res == SQLITE_ROW ){
id = sqlite3_column_int(request, 0);
printf("User exist %i \n",id);
}
}
sqlite3_finalize(request);

我也试过 LIKE 但它也不起作用

SELECT * FROM User WHERE name LIKE '%bob%'

但是当我执行相同的代码但得到一个 INTERGER 值时

SELECT * FROM User WHERE id=1

它工作正常。

在 SQLite 的数据库浏览器中,所有请求都可以正常工作。

最佳答案

为了解决这个问题,我搜索了状态码 101 的含义。

这是他们说的。

(101) SQLITE_DONE

The SQLITE_DONE result code indicates that an operation has completed. The SQLITE_DONE result code is most commonly seen as a return value from sqlite3_step() indicating that the SQL statement has run to completion. But SQLITE_DONE can also be returned by other multi-step interfaces such as sqlite3_backup_step().

https://sqlite.org/rescode.html

所以,您得到 101,因为 SELECT SQL 没有更多结果。

关于c++ - WHERE 列 = 值,仅适用于 INTEGER 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58360676/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com