调试sqlite

发布于 2024-09-19 12:29:22 字数 1240 浏览 4 评论 0原文

有没有办法查看 sqlite3_prepare_v2 和 sqlite3_bind_xxx 之后生成的“showStatement”是什么?

运行此查询:

SELECT * 
FROM shows, locations 
WHERE (shows.day_id = 1) 
  AND (shows.id IN (6,7,15,19,23,66)) 
  AND (shows.location_id = locations.id)
ORDER by locations.sort_order

当我完全像这样输入它时,它在 SQLite 管理器和代码中完美运行。但是,如果我进行参数替换,则查询不会返回结果...

if (sqlite3_open([databasePath UTF8String],&showsDatabase) == SQLITE_OK){
    const char *sqlStatement = "SELECT * FROM shows, locations WHERE (shows.day_id = ?) AND (shows.id IN (?)) AND (shows.location_id = locations.id) ORDER by locations.sort_order";
        sqlite3_stmt *showStatement;
        if(sqlite3_prepare_v2(showsDatabase, sqlStatement, -1, &showStatement, NULL) == SQLITE_OK) {
            sqlite3_bind_int(showStatement, 1, forDay);
            sqlite3_bind_text(showStatement, 2, allFavorites,-1,NULL);
            int error = sqlite3_step(showStatement);
            while(sqlite3_step(showStatement) == SQLITE_ROW) {

...

问题必须出在 IN (6,7...) 部分,否则它就可以完美工作。

我的调试器显示 forDay = 1 且 allFavorites = 6,7,15,19,23,66 但错误 = 101 = sqlite3_step() 已完成执行 = 未找到任何行

能够以一种或另一种方式查看“showStatement”变量可以解决问题,但是调试器不会提供该信息

Is there a way to see what the resulting 'showStatement' is after sqlite3_prepare_v2 and sqlite3_bind_xxx ?

Running this query :

SELECT * 
FROM shows, locations 
WHERE (shows.day_id = 1) 
  AND (shows.id IN (6,7,15,19,23,66)) 
  AND (shows.location_id = locations.id)
ORDER by locations.sort_order

runs perfectly in SQLite Manager and in code when I enter it EXACTLY like that. If I however do parameter substitution the query returns no results...

if (sqlite3_open([databasePath UTF8String],&showsDatabase) == SQLITE_OK){
    const char *sqlStatement = "SELECT * FROM shows, locations WHERE (shows.day_id = ?) AND (shows.id IN (?)) AND (shows.location_id = locations.id) ORDER by locations.sort_order";
        sqlite3_stmt *showStatement;
        if(sqlite3_prepare_v2(showsDatabase, sqlStatement, -1, &showStatement, NULL) == SQLITE_OK) {
            sqlite3_bind_int(showStatement, 1, forDay);
            sqlite3_bind_text(showStatement, 2, allFavorites,-1,NULL);
            int error = sqlite3_step(showStatement);
            while(sqlite3_step(showStatement) == SQLITE_ROW) {

...

The problem must lie in the IN (6,7...) part, without that it works perfect.

My debugger shows me that forDay = 1 and that allFavorites = 6,7,15,19,23,66
but the error = 101 = sqlite3_step() has finished executing = no lines found

Being able to see the 'showStatement' variable in one way or another would solve the problem, however the debugger doesn't give that info

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

十雾 2024-09-26 12:29:23

您无法将 IN (?) 与数组绑定。

需要编写 shows.id IN (?, ?, ?, ?, ?, ?) 并分别绑定各个参数。问号的数量还必须与参数的数量相匹配,因此如果数量可能变化,您可能需要动态构建查询。

You can't bind IN (?) with an array.

You need to write shows.id IN (?, ?, ?, ?, ?, ?) and bind each parameter separately. The number of question marks also has to match the number of parameters so you might need to construct the query dynamically if the number can vary.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文