数据库操作——sqlite3_get_table
来源:互联网 发布:淘宝动漫店 编辑:程序博客网 时间:2024/04/30 07:39
#include <stdio.h>
#include <sqlite3.h>
int main()
{
sqlite3 * db = NULL;
int result = sqlite3_open("student.db", &db);
if (result != SQLITE_OK)
{
printf ("1open student.db error!\n");
return -1;
}
char *errmsg;
result = sqlite3_exec(db, "create table test(ID INTEGER, name TEXT, sex TEXT, age INTEGER, primary key(ID))", NULL, NULL, &errmsg);
if (result != SQLITE_OK && result != 1)
{
printf ("create test table error : %d(%s)!\n", result, errmsg);
return -1;
}
char **resultp = NULL;
int nrow, ncolumn;
result = sqlite3_get_table(db, "select ID,name from test where sex='F'", &resultp, &nrow, &ncolumn, &errmsg);
if (result != SQLITE_OK)
{
printf ("select test table error : %d(%s)!\n", result, errmsg);
return -1;
}
int i;
int count = 0;
for (i = 0; i < (nrow+1)*ncolumn; i++)
{
count++;
printf ("%8s ", resultp[i]);
if (count % ncolumn == 0)
{
printf ("\n");
}
}
printf ("\n");
sqlite3_close(db);
return 0;
}
#include <sqlite3.h>
int main()
{
sqlite3 * db = NULL;
int result = sqlite3_open("student.db", &db);
if (result != SQLITE_OK)
{
printf ("1open student.db error!\n");
return -1;
}
char *errmsg;
result = sqlite3_exec(db, "create table test(ID INTEGER, name TEXT, sex TEXT, age INTEGER, primary key(ID))", NULL, NULL, &errmsg);
if (result != SQLITE_OK && result != 1)
{
printf ("create test table error : %d(%s)!\n", result, errmsg);
return -1;
}
char **resultp = NULL;
int nrow, ncolumn;
result = sqlite3_get_table(db, "select ID,name from test where sex='F'", &resultp, &nrow, &ncolumn, &errmsg);
if (result != SQLITE_OK)
{
printf ("select test table error : %d(%s)!\n", result, errmsg);
return -1;
}
int i;
int count = 0;
for (i = 0; i < (nrow+1)*ncolumn; i++)
{
count++;
printf ("%8s ", resultp[i]);
if (count % ncolumn == 0)
{
printf ("\n");
}
}
printf ("\n");
sqlite3_close(db);
return 0;
}
阅读全文
0 0
- 数据库操作——sqlite3_get_table
- sqlite3_get_table()
- sqlite3_get_table()
- sqlite3_get_table()
- sqlite3_get_table()
- [挖坑]sqlite数据库中的sqlite3_get_table接口为什么不建议使用
- linux下sqlite数据库用c语言sqlite3_get_table查询数据
- sqlite3_get_table()函数
- 数据库—操作
- 数据库操作——附加数据库
- MySQL数据库学习——数据库操作
- MySQL数据库—使用命令行操作数据库
- 数据库操作——视图
- MongoDB——数据库操作
- 数据库操作 ——sqlite3_exec
- 数据库——SQL操作
- T—sql数据库操作
- .Net — MySql数据库操作
- Dubbo分布式框架学习
- 问题 M: 数码管
- 句子逆序
- 【NOIP模拟8.6】
- leetcode(98). Validate Binary Search Tree
- 数据库操作——sqlite3_get_table
- JS的条件与循环语句简介
- jQuery选择器(全)
- Shell脚本查看占用cpu过高的线程信息
- 计算器
- 问题 N: 字母排列
- 文件复制系统调用版
- HTTP协议
- 第三方yum仓库搭建