SQlite常用语句

1.创建表语句

create table Student (Student 是表名)
IF NOT EXISTS  表不存在 才创建
gender text  表示其类型 字符串

储存类型

NULL 值是空值
INTEGER 值是整型
REAL 值是浮点数
TEXT 值是文本字符串
BLOB 值是一个二进制类型
number integer primary key not NULL 主键值 如果不操作 自增
// 主键不为空,姓名不为空,性别不为空,年龄不为空
create table IF NOT EXISTS lanOuStudent(number integer primary key not NULL, name text not NULL, gender text not NULL, age integer not NULL)

2.插入语句

insert into lanOuStudent 表名
注:单引号 与 顺序对应
// 在创建的表中添加数据
insert into lanOuStudent(name ,gender ,age , number) values('%@' ,'%@' , '%ld' , '%ld')

3.删除语句

delete from lanOuStudent 表名
where 根据条件删除 
// 根据年龄删除表中的数据
delete from lanOuStudent where age > '%ld'

4.更新语句

update lanOuStudent 表名
where 根据条件更新
set age 更新的字段
// 按照姓名更新年龄
update lanOuStudent set age = '%ld' where name = '%@'

5.查询语句

where 根据条件查询  多条件用 and 连接
*表示 查询所有字段
// 根据姓名和年龄查询表中的数据
select * from lanOuStudent where name = '%@' and age = '%ld'
select * from lanOuStudent 查询所有

重要函数参数:

sqlite3_exec(sqlite3 *, const char *sql, int (*callback)(void *, int, char **, char **), void *, char **errmsg)
// 第1个参数  是前面open函数得到的指针。
// 第2个参数  是一条sql语句。
// 第3个参数  是回调,当这条语句执行之后,sqlite3会去调用你提供的这个函数。
// 第4个参数  是你所提供的指针,你可以传递任何一个指针参数到这里,这个参数最终会传到回调函数里面,如果不需要传递指针给回调函数,可以填NULL。等下我们再看回调函数的写法,以及这个参数的使用。
// 第5个参数  是错误信息。
sqlite3_prepare_v2(sqlite3 *db, const char *zSql, int nByte, sqlite3_stmt **ppStmt, const char **pzTail)

// int nByte -1 指sql语句长度 可以无限长
// sqlite3_stmt 跟随指针 地址
// const char **pzTail 截取sql语句未使用部分

绑定查询值

// 第二个参数 指查询的第几个问号 从1开始
sqlite3_bind_text(stmt, 1, name.UTF8String, -1, NULL);

读取数据

// 第二个参数 指的是 表中的列数 从0开始
char *name = (char *)sqlite3_column_text(stmt, 1);
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值