sqlite3基本命令
1. 系统命令
以‘.‘开头的命令
.table
.help
.quit
.exit
.schema
2. sql 命令
分号;结尾
创建
create table stu(name type); //创建
插入
insert into stu values(value,value,value); //插入完全符合表结构
insert into stu (name,name)values(value,value);//插入部分字段
查询
select * from stu; //查询所有字段
select name from stu; //查询部分
select * from stu where name=xx and name =xx;
select * from stu where name=xx or name =xx;
删除
delete from stu where name=xx;
更新
update stu set name=xx ,name=xx where name=xx;
插入一列
alter table stu add column address char;
删除一列
1. 创建一张新表
...
2. 删除原有的表
drop table stu
3. 将新表改为原有的旧表的名字
alter table xxx rename to xxx;
3. sqlite 3 函数接口
打开数据库
int sqlite3_open(
const char *文件名,/ *数据库文件名(UTF-8)* /
sqlite3 ** ppDb / * OUT:SQLite数据库句柄* /
//打开成功返回SQLITE_OK
);
关闭
int sqlite3_close(sqlite3 *);
//成功返回SQLITE_OK
错误信息
const char *sqlite3_errmsg(sqlite3*);
//返回错误信息的首地址
int sqlite3_exec(
sqlite3 *,/ *一个打开的数据库* /
const char * sql,/ *要执行的SQL语句 * /
int(* callback)(void *,int,char **,char **),/ *回调函数* /
void*,/ *回调的第一个参数* /
char ** errmsg / *错误消息写在这里* /
);
//callback 回调函数,只有sql为查询语句的时候,才会执行此语句