linux C语言 数据库sqlite3的添加,删除,查看
2016-10-30 22:06
357 查看
linux下数据库sqlite3的添加,删除,查看。
这个程序需要先在命令下创建表。
程序:
#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);
}
}
这个程序需要先在命令下创建表。
程序:
#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);
}
}
相关文章推荐
- linux C语言 数据库sqlite3的添加,删除,查看
- linux下添加,删除,修改,查看用户和用户组
- 在Linux下用C语言操作数据库sqlite3(查询)
- sql server 2005 中数据库表 的创建 ,查看表 属性,表的名称重命名,情况表中信息,删除表 ; 表中列重命名,添加新列,修改列的数据类型,删除列,设置列的主键外键
- linux下添加,删除,修改,查看用户和用户组
- linux 下创建查看添加删除用户组
- linux下添加,删除,修改,查看用户和用户组
- linux下添加,删除,修改,查看用户和用户组
- Linux用户与用户组的添加,查看,删除
- 在Linux下用C语言操作数据库sqlite3(查询)
- linux下添加,删除,修改,查看用户和用户组
- Linux防火墙规则的查看、添加、删除和修改
- linux下添加,删除,修改,查看用户和用户组
- linux基本操作:删除,添加,编辑, 安装, 查看版本, top/ps
- Linux怎样查看所有用户以及用户(组)的添加 删除
- linux下添加,删除,修改,查看用户和用户组
- ado.net实现对数据库的添加、删除和查看操作
- linux下添加,删除,修改,查看用户和用户组