编写程序以从sqlite数据库检索数据时,尽管在sqlite cli中返回预期结果的完全相同的查询,但仍然没有返回任何结果。
#include <stdio.h>
#include <sqlite3.h>
sqlite3 * db;
sqlite3_stmt * locationgetint;
int locationInt(char * string){
sqlite3_bind_text(locationgetint,1,string,-1,SQLITE_STATIC);
sqlite3_step(locationgetint);
int output = sqlite3_column_int(locationgetint,0);
sqlite3_clear_bindings(locationgetint);
sqlite3_reset(locationgetint);
return output;
}
int main(){
sqlite3_open("db.sqlite3",&db);
sqlite3_prepare_v2(db,"SELECT id FROM pfs WHERE name='?';",-1,&locationgetint,0);
printf("%d\n",locationInt("Milky Way")); // Prints 0
return 0;
}
但是Sqlite CLI版本:
sqlite> SELECT id FROM pfs WHERE name='Milky Way';
625
sqlite>
答案 0 :(得分:0)
正如Sjoerd所说,删除引号有效。