C++、SQLite - 指向字符串指针的指针
我使用 C++ 和 SQLite3(使用 Microsoft Visual C++ 2008),希望从数据库中读取一个值并将其存储在一个变量中以供使用。 select 语句工作正常,但每次我查看回调函数并尝试从 char **argv 读取值时,我“仅”得到内存地址或数据库中该值的第一个 ASCII 字符。我做错了什么? 这是回调函数:
static int callback(void *pArg, int argc, char **argv, char **azColName)
{
fprintf(f, "Callback aufgerufen!\n");
int i;
for(i=0; i<argc; i++)
{
fprintf(f, azColName[i]);
fprintf(f, " = ");
if(argv[i]){
fprintf(f, argv[i]);
//unsigned int x = argv[i];
}
else
fprintf(f, "NULL");
fprintf(f, "\n");
}
fprintf(f, "\n");
return 0;
}
我在没有回调函数的情况下尝试了它,但我再次得到了相同的结果,并且我尝试了不同的方法将值存储在变量中。
while (sqlite3_step(stmt) == SQLITE_ROW)
{
fprintf(f, "%s\n", sqlite3_column_text(stmt, 0));
//const unsigned char *c = sqlite3_column_text(stmt, 0);
fprintf(f, "%u\n", sqlite3_column_int(stmt, 0));
//unsigned int z = *sqlite3_column_int(stmt, 0);
stmt_count++;
}
是否可能无法访问该值或将其存储在变量中?
I work with C++ and SQLite3 (with Microsoft Visual C++ 2008) and would like to read a value from my database and store it in a variable to work with it on.
The select statement works fine, but every time I viewed the callback function and try to read the value from char **argv, I get "only" the memory address, or the first ASCII character of the value, which is in the database. What am I doing wrong?
Here is the callback function:
static int callback(void *pArg, int argc, char **argv, char **azColName)
{
fprintf(f, "Callback aufgerufen!\n");
int i;
for(i=0; i<argc; i++)
{
fprintf(f, azColName[i]);
fprintf(f, " = ");
if(argv[i]){
fprintf(f, argv[i]);
//unsigned int x = argv[i];
}
else
fprintf(f, "NULL");
fprintf(f, "\n");
}
fprintf(f, "\n");
return 0;
}
I tried it without the callback function, but again I get the same result and I've tried different ways to store the value in a variable.
while (sqlite3_step(stmt) == SQLITE_ROW)
{
fprintf(f, "%s\n", sqlite3_column_text(stmt, 0));
//const unsigned char *c = sqlite3_column_text(stmt, 0);
fprintf(f, "%u\n", sqlite3_column_int(stmt, 0));
//unsigned int z = *sqlite3_column_int(stmt, 0);
stmt_count++;
}
Is it perhaps not possible to access the value or to store it in a variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白为什么你需要回调 - 这应该有效(取决于数据的大小):
I don't see why you need a callback - this should work (depending on the size of the data):