gpt4 book ai didi

C++ SQLite 返回一些值?

转载 作者:行者123 更新时间:2023-12-03 12:49:08 25 4
gpt4 key购买 nike

我正在编写一个使用 SQLite 的服务器端程序。当客户端登录时,我想从 Userinfo 表中获取其信息。

它的列是

  • 用户号(int),
  • 金钱(int),
  • 银行货币(int),
  • 性别(字符串),
  • 姓名,
  • 姓氏

我想将这些信息写入用户结构

struct userstruct
{
int userno;
int money;
int bankmoney
....
}

当用户登录时,我想创建一个新的结构并通过 SQLite 从该表设置用户信息。

最佳答案

以下内容:

static int callback(void *data, int argc, char **argv, char **azColName)
  • void *data - 可用于给出指向对象的指针 - 又名 this 或其他任何内容,可以为 null
  • int argc - 列数 - 所选记录数
  • char **argv - 列值数组。
  • char **azColName - 列名称数组

顺便说一句:更好地使用准备 - 绑定(bind) - 步骤,如下面的示例,这样它就可以在没有回调的情况下工作:

sqlite3_prepare_v2(db, "select distinct name, age from demo where age > ? order by 2,1;", -1, &stmt, NULL);

sqlite3_bind_int(stmt, 1, 16); /* 1 */

while ( (rc = sqlite3_step(stmt)) == SQLITE_ROW) { /* 2 */
printf("%s is %d years old\n", sqlite3_column_text(stmt, 0), sqlite3_column_int(stmt, 1)); /* 3 */
}

关于C++ SQLite 返回一些值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47418273/

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