gpt4 book ai didi

iphone - 如何在 sqlite 和 iPhone 中使用 LIKE 查询

转载 作者:行者123 更新时间:2023-12-03 21:24:22 26 4
gpt4 key购买 nike

我正在使用以下内容进行 LIKE 查询。这种 LIKE 技术正确吗?

selectstmtSearch = nil;

if(selectstmtSearch == nil){
const char *sql = "SELECT col1, col2 FROM table1 t1 JOIN table2 t2 ON t1.cityid = t2.cityid where t1.cityname like ?001 order by t1.cityname";

if(sqlite3_prepare_v2(databaseSearch, sql, -1, &selectstmtSearch, NULL) == SQLITE_OK)
{
sqlite3_bind_text(selectstmtSearch, 1, [[NSString stringWithFormat:@"%%%@%%", searchText] UTF8String], -1, SQLITE_TRANSIENT);
}
}

我遇到的问题是在使用了几次之后,我在 sqlite3_open() 上收到错误 14,该错误无法打开数据库。如果我将 LIKE 替换为以下内容:

SELECT col1, col2 
FROM table1 t1
JOIN table2 t2 ON t1.cityid = t2.cityid
where t1.cityname = ?
order by t1.cityname

效果很好。在上述代码之后,我确实打开/关闭了数据库。有没有办法准确排除数据库无法打开的原因以及它与我的 LIKE 语法的关系是什么?

最佳答案

在关闭数据库连接之前,您必须sqlite3_resetsqlite3_finalize(selectstmtSearch)

关于iphone - 如何在 sqlite 和 iPhone 中使用 LIKE 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1960190/

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