下载此文档

IOS开发之数据sqlite使用.docx


文档分类:IT计算机 | 页数:约3页 举报非法文档有奖
1/3
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/3 下载此文档
文档列表 文档介绍
IOS开发之数据sqlite使用
一、引入工具包
,该工具包为C语言工具包。
二、代码操作数据库
1、创建并且链接数据库 
- (void) _connectDB{

//1>获取沙盒路径作为数据库创建时候的初始化路径
NSString * path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
path=[path ponent:@""];
NSLog(@"%@",path);

//2>如果存在则打开当前链接,如果不存在则创建
if(SQLITE_OK==sqlite3_open(, &sqlite)){
NSLog(@"数据库创建成功!");
}else {
NSLog(@"数据库创建失败!");
}

}
2、操作数据库 
/**
* 创建表
*/
- (void) _createTable{
NSString *create=@" create table if not exists t_Person (id integer primary key autoincrement,name text,age integer,tel text)";
[self _execSql:create andTip:@"创建表操作"];

}
/**
* 插入数据操作
*
* ***@param name 姓名
* ***@param age 年龄
* ***@param tel 电话
*/
- (void) _insertName:(NSString *) name andAge:(int )age andTel:(NSString *) tel{

NSString * insert=[NSString stringWithFormat:@" insert into t_Person(name,age,tel) values('%@',%d,'%@')",name,age,tel];
[self _execSql:insert andTip:@"插入操作"];

}
/**
* 执行数据库操作
*
* ***@param sql 要执行的sql
* ***@param tip 要执行的操作标题
*/
- (void) _execSql:(NSString *) sql andTip:(NSString *) tip{
char * result;
if(SQLITE_OK==sqlite3_exec(sqlite, , NULL, NULL, &result)){
NSLog(@"%@成功!",tip);
}else{
NSLog(@"%@失败!",tip);
}
}
3、查询数据库 
/**
* 读取数据
*/
- (void)_readData{
//1> 定义sql语句
NSString * sql=@"select id,name

IOS开发之数据sqlite使用 来自淘豆网m.daumloan.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数3
  • 收藏数0 收藏
  • 顶次数0
  • 上传人tanfengdao
  • 文件大小80 KB
  • 时间2018-08-13