博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS_Sqlite
阅读量:6230 次
发布时间:2019-06-21

本文共 3120 字,大约阅读时间需要 10 分钟。

#import "sqlite3.h"@interface CSqlite  : NSObject{    sqlite3 *database;}-(void)openSqlite;-(sqlite3_stmt*)runSql:(char*)sql;-(sqlite3_stmt*)NSRunSql:(NSString*)sql;-(BOOL)NSSendSql:(NSString*)sql;@end

////  CSqlite.m//  WXS////  Created by zili zhu on 12-7-13.//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.//#import "CSqlite.h"@implementation CSqlite-(void)openSqlite{    NSString *sqlFile = @"qxd.db";    NSArray *cachePath= NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);    NSString *cacheDir = [cachePath objectAtIndex:0];    NSString *databasePath = [cacheDir stringByAppendingPathComponent:sqlFile];            NSFileManager *fileManager = [NSFileManager defaultManager];    // Copy the database sql file from the resourcepath to the documentpath    if (![fileManager fileExistsAtPath:databasePath]) {        NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:sqlFile];        NSError *error;        [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:&error];//        if (error != nil) {//            NSLog(@"[Database:Error] %@", error);//        }    }        if(sqlite3_open([databasePath cStringUsingEncoding:NSASCIIStringEncoding], &database)==SQLITE_OK)    {         NSLog(@"open sqlite db ok.");    }    //    if (sqlite3_open([[[[NSBundle mainBundle] pathForResource:@"qxd" ofType:@"db"] retain] fileSystemRepresentation], &database)==SQLITE_OK) { //        NSLog(@"open sqlite db ok."); //    }}-(void)closeSqlite{    sqlite3_close(database);}-(sqlite3_stmt*)runSql:(char*)sql{   // char *errorMsg;    sqlite3_stmt *statement;     if (sqlite3_prepare_v2(database, sql, -1, &statement, nil)==SQLITE_OK) {         NSLog(@"select ok");     }    return statement;}-(sqlite3_stmt*)NSRunSql:(NSString*)sql{   // char *errorMsg;    sqlite3_stmt *statement;     if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) {         NSLog(@"select ok 2");     }    else {        NSLog(@"select error 2");    }    return statement;}-(BOOL)NSSendSql:(NSString*)sql{    char *errorMsg;    if (sqlite3_exec(database, [sql UTF8String], 0, 0, &errorMsg)==SQLITE_OK)    {         NSLog(@"send ok");        return YES;        }    else     {        fprintf(stderr,"Error:  %s",  errorMsg);        return NO;    }    }@end

while (sqlite3_step(stmt)==SQLITE_ROW)    {        str_MemberDetail *node = new str_MemberDetail;        node->Id = sqlite3_column_int(stmt, 0);        node->Name =[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 1) encoding:NSUTF8StringEncoding];        node->Phone =[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 2) encoding:NSUTF8StringEncoding];        node->Photos =[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 3) encoding:NSUTF8StringEncoding];        node->EnName =[[NSString alloc] initWithCString:(char *)sqlite3_column_text(stmt, 4) encoding:NSUTF8StringEncoding];                memberList->push_back(*node);    }

转载于:https://www.cnblogs.com/zzili/archive/2012/12/14/6663216.html

你可能感兴趣的文章
.Net开发笔记(二十一) 反射在.net中的应用
查看>>
ios31--NSThread
查看>>
设计模式总结篇系列:桥接模式(Bridge)
查看>>
ubuntu VNC连接树莓派
查看>>
[nodemon] Internal watch failed: watch ENOSPC错误解决办法
查看>>
全球首发----Tech·Ed 2006中国 实况报道。全程跟踪。(四)
查看>>
向C#的选项卡中添加自定义窗体
查看>>
WPF客户端读取高清图片很卡,缩略图解决方案
查看>>
ubuntu安装和配置SVN【转】
查看>>
通过串口连接控制树莓派
查看>>
线程池系列三:ThreadPoolExecutor讲解
查看>>
wp7 XAML基础
查看>>
机器这次击败人之后,争论一直没平息 | SQuAD风云
查看>>
Oracle中shrink space命令详解
查看>>
验证码 生成变形的文字
查看>>
用cflow工具生成代码函数调用关系【转】
查看>>
ASP.NET MVC5+EF6+EasyUI 后台管理系统(75)-微信公众平台开发-用户管理
查看>>
android用户界面之菜单(Menu)教程实例汇总
查看>>
单链表
查看>>
linux下的僵尸进程处理SIGCHLD信号【转】
查看>>