要转载请表明链接地址:http://blog.sina.com.cn/bbsme
作者:Amor Yin(makaymose)
在头文件里加入
#import"/usr/include/sqlite3.h"
下来按照我的习惯先把常用的字符串与定义出来,这是一个好的习惯
#define
#define
接下来我们初始化数据库
- (NSString*)dataFilePath
{
NSArray *paths =NSSearchPathForDirectori
NSString *documentsDirectory = [pathsobjectAtIndex:0];
return [documentsDirectorystringByAppendingPathCom
}
nbsp;* 判断数据库是否存在能否正确打开
if (sqlite3_open([[self dataFilePath]UTF8String],&database) != sqlITE_OK) {
sqlite3_close(database);
NSAssert(0,@"Failed to open database");
}
char *errorMsg;
NSString *createsql= @"CREATE TABLE IF NOT EXISTS USERSINFO (NAME TEXT PRIMARYKEY,CONTEXT TEXT);";
if (sqlite3_exec(database,[createsql
sqlite3_close(database);
NSAssert1(0,@"Error creating table: %s",errorMsg);
}
NSString *query =@"SELECT
sqlite3_stmt*statement;
if(sqlite3_prepare_v2( database,[queryUTF8String],-1,&statement,nil) == sqlITE_OK) {
原文链接:https://www.f2er.com/sqlite/202509.html