linux C语言 数据库sqlite3的添加,删除,查看
2016-11-01 23:17
183 查看
inux下数据库sqlite3的添加,删除,查看。
这个程序需要先在命令下创建表。
程序:
<span style="font-family:SimSun;font-size:18px;">
#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
static sqlite3 *db = NULL;
static char *errmsg = NULL;
char ** result = NULL;
int num = 0;
int display(void *para,int ncolumn, char ** columnvalue,char *columnname[])//回调函数,用于显示
{
int i;
num++;
printf("num = %d\n",num);
printf("total column is %d\n",ncolumn);
for(i = 0; i < ncolumn; i++)
{
printf("%s %s\n",columnname[i],columnvalue[i]);
}
printf("===============================\n");
return 0;
}
int main()
{
int re;
int row;
int column;
int i;
int j;
re = sqlite3_open("test.db",&db);
if(re != 0)
{
printf("open error\n");
exit(1);
}
//sqlite3_exec(db,"insert into test values('chengzi8','321');",0,0,&errmsg);//添加
//sqlite3_exec(db,"delete from test where phone = '321';",0,0,&errmsg);//删除
sqlite3_exec(db,"select * from test;",display,NULL,&errmsg);//显示2使用回调函数
printf("%d\n",num);
#if 0
sqlite3_get_table(db,"select * from test;",&result,&row,&column,&errmsg);//显示
for(i = 0; i <= row; i++)
{
for(j = 0; j < column; j++)
{
printf("%s|",result[i * column + j]);
}
printf("\n");
}
sqlite3_free_table(result);//注销结果集
#endif
re = sqlite3_close(db);//关闭
if(re != 0)
{
printf("open error\n");
exit(1);
}
}</span>
这个程序需要先在命令下创建表。
程序:
<span style="font-family:SimSun;font-size:18px;">
#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
static sqlite3 *db = NULL;
static char *errmsg = NULL;
char ** result = NULL;
int num = 0;
int display(void *para,int ncolumn, char ** columnvalue,char *columnname[])//回调函数,用于显示
{
int i;
num++;
printf("num = %d\n",num);
printf("total column is %d\n",ncolumn);
for(i = 0; i < ncolumn; i++)
{
printf("%s %s\n",columnname[i],columnvalue[i]);
}
printf("===============================\n");
return 0;
}
int main()
{
int re;
int row;
int column;
int i;
int j;
re = sqlite3_open("test.db",&db);
if(re != 0)
{
printf("open error\n");
exit(1);
}
//sqlite3_exec(db,"insert into test values('chengzi8','321');",0,0,&errmsg);//添加
//sqlite3_exec(db,"delete from test where phone = '321';",0,0,&errmsg);//删除
sqlite3_exec(db,"select * from test;",display,NULL,&errmsg);//显示2使用回调函数
printf("%d\n",num);
#if 0
sqlite3_get_table(db,"select * from test;",&result,&row,&column,&errmsg);//显示
for(i = 0; i <= row; i++)
{
for(j = 0; j < column; j++)
{
printf("%s|",result[i * column + j]);
}
printf("\n");
}
sqlite3_free_table(result);//注销结果集
#endif
re = sqlite3_close(db);//关闭
if(re != 0)
{
printf("open error\n");
exit(1);
}
}</span>
相关文章推荐
- linux C语言 数据库sqlite3的添加,删除,查看
- linux C语言数据库sqliet3的添加,删除,查看
- android系统内置数据库SQLite的建库、建表、添加、删除、修改、查询等基本操作
- ado.net实现对数据库的添加、删除和查看操作
- C#-数据库访问技术 ado.net——创建 数据库连接类 与 数据库操作方法 以及简单的数据的添加、删除、修改、查看
- sql server 2005 中数据库表 的创建 ,查看表 属性,表的名称重命名,情况表中信息,删除表 ; 表中列重命名,添加新列,修改列的数据类型,删除列,设置列的主键外键
- android 数据库 SQLiteOpenHelper和ContentProvider学习笔记---添加修改删除数据之联系人(二)
- asp添加数据记录写入,删除,查看实列
- 网站后台只能显示数据库信息 不能更改删除添加信息
- 用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等
- 将dataGridView中的添加/删除等修改保存至数据库 ,支持多条操作,最后一次性保存
- MySql中添加用户,新建数据库,用户授权,删除用户,修改密码
- C++ builder 2007 使用ADO数据库 进行 添加 删除 修改
- Oracle 表空间、查看、添加、删除
- DataGridView控件初始化,添加删除行(不绑定数据库)
- SQL2K数据库开发七之表操作添加删除和修改列 推荐
- 将dataGridView中的添加/删除等修改保存至数据库(winform - VS2005)
- 数据库的相关操作:如连接、查询、添加、删除、修改、分页显示
- 精细化(添加 修改 删除 查看)用户权限分配方法
- 删除数据库中重复记录(添加自己的理解)