1:引入类库
2:获得沙盒路径,
3:创建和打开数据库
1:导入#import <sqlite3.h>
2:sqlite3 *db;//声明对象
3:转换成c字符串指针数组 const char *p = sqlitePath.UTF8String;
4:打开数据库 int res =sqlite3_open(p, &db);
第一个参数:sqlite3 *db;//声明对象
第二个参数 sql语句
第三个参数 回调函数
第四个参数 回调函数的参数
// NSString *insert_sql = @"insert into temps(t_name)values('java')";
// NSString *delete_sql = @"delete from temps where t_id = 1";
// NSString *update_sql = @"update temps set t_name = '444' where t_id =3";
// NSString * search_t_id = @"100 or 1=1";//sql注入漏洞
// int search_t_id = 3;
// NSString *search_name = @"j%";
//查询 参数化的sql 语句 防止sql注入漏洞
// NSString *search_sql = @"select * from temps";
// NSString *search_sql = [NSString stringWithFormat:@"select * from temps where t_id = %@",search_t_id];
1: sqlite3 *db;//声明对象
2: 执行的sql语句
3:sql语句的长度,通常用-1来代表,系统自己来计算长度,也可以用strlen()函数来计算
4:执行对象 sqlite3_stmt *stmt;
第一个参数:sqlite_stmt对象
第二个参数:占位符索引,从1开始
//释放stmt
//关掉数据库