C++ SQLite return 一些值?
C++ SQLite return some values?
我正在编写一个使用 SQLite 的服务器端程序。当客户端登录时,我想从 Userinfo
table 中获取其信息。
它的列是
- 用户号(整数),
- 金钱(整数),
- bankmoney(int),
- 性别(字符串),
- 姓名,
- 姓氏
我想将这些信息写入用户结构
struct userstruct
{
int userno;
int money;
int bankmoney
....
}
当用户登录时,我想创建一个新结构并通过 SQLite 从这个 table 设置用户信息。
以下:
static int callback(void *data, int argc, char **argv, char **azColName)
void *data
- 可用于提供指向对象的指针 - 即 this 或其他任何东西,可以为 null
int argc
- 列数 - 所选记录数
char **argv
- 列值数组。
char **azColName
- 列名数组
顺便说一句:最好使用 prepare - bind - step,就像下面的示例一样,这样它就可以在没有回调的情况下工作:
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 */
}
我正在编写一个使用 SQLite 的服务器端程序。当客户端登录时,我想从 Userinfo
table 中获取其信息。
它的列是
- 用户号(整数),
- 金钱(整数),
- bankmoney(int),
- 性别(字符串),
- 姓名,
- 姓氏
我想将这些信息写入用户结构
struct userstruct
{
int userno;
int money;
int bankmoney
....
}
当用户登录时,我想创建一个新结构并通过 SQLite 从这个 table 设置用户信息。
以下:
static int callback(void *data, int argc, char **argv, char **azColName)
void *data
- 可用于提供指向对象的指针 - 即 this 或其他任何东西,可以为 nullint argc
- 列数 - 所选记录数char **argv
- 列值数组。char **azColName
- 列名数组
顺便说一句:最好使用 prepare - bind - step,就像下面的示例一样,这样它就可以在没有回调的情况下工作:
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 */
}