加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

SQLite - oc连接Sqlite

(2013-04-23 20:33:45)
标签:

sqlite连接

it

分类: Mac/IOS那些事
- (const char*)getFilePath{//获取数据库路径
//    NSArray *documentArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
      NSUserDomainMask, YES);
//    NSString *documentDir = [documentArray objectAtIndex:0];
//    [documentDir stringByAppendingString:@"pdb.sqlite"];
//    NSLog(@"documentdir=%@",documentDir)
//    这种方法可以判断pdb.sqlite是否存在
//    NSFileManager *fileManager = [NSFileManager defaultManager];
//    BOOL ifExistDb=[fileManager fileExistsAtPath:documentDir];
//    if(ifExistDb)
//    {
//        NSLog(@"existdb");
//    }else{
//        NSLog(@"null db");
//    }
    NSString *documentDir = [NSString stringWithFormat:@"/Users/loveuu/Documents/pdb.sqlite"];
    //NSLog(@"filepath= %s",[[NSString stringWithFormat:documentDir,NSHomeDirectory() ]
     UTF8String]);//filepath= /Users/loveuu/Documents/pdb.sqlite
    return [[NSString stringWithFormat:documentDir,NSHomeDirectory() ] UTF8String];
}
- (BOOL)createDB{
    //NSLog(@"filepath= %@",NSHomeDirectory());
    int ret = sqlite3_open([self getFilePath], &pdb);//打开数据库,数据库不存在则创建
    if (SQLITE_OK == ret) {//创建成功
        sqlite3_close(pdb);//关闭
        NSLog(@"yes");
        return YES;
    }else{
        NSLog(@"no");
        return NO;//创建失败
    }
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有