一个完整的SQLite的应用DEMO

前端之家收集整理的这篇文章主要介绍了一个完整的SQLite的应用DEMO前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
原文地址:一个完整的SQLite的应用DEMO 作者:殷昭
自己写了一个iphone应用sqlite的DEMO;
涉及到添加查询和事务管理
关键代码

if(sqlite3_open([[selfdatabasePath]UTF8String],&database) !=sqlITE_OK) {

sqlite3_close(database);

NSAssert(0,@"open database faild!");

}



char*erroMsg;


NSString*createsql = [NSStringstringWithFormat:@"CREATE TABLE IF NOT EXISTS %@(ROW INTEGER PRIMARY KEY,NAME TEXT,AGE TEXT,SEX TEXT)"
sqlite3_exec
(database,[createsqlNULL,&erroMsg) !=sqlITE_OK) {

sqlite3_close(database);

NSAssert1(0,@"create table %@ faild",TableName);

NSAssert1(@"the error is %s",erroMsg);

}


NSString*insertUser = [NSStringstringWithFormat:@"INSERT INTO %@(NAME,AGE,SEX) VALUES('%@','%@','%@')",TableName,new_user.name,new_user.age,new_user.sex];


NSLog(@"%@",insertUser);


sqlite3_exec(database,[insertUsersqlITE_OK)


{

NSAssert1(

}


User *user = [[Useralloc]init];


*countsql = [:@"SELECT ROW,NAME,SEX FROM UserTable WHERE ROW = %i"id];


sqlite3_stmt*statement;


sqlite3_prepare_v2(database,[countsql1,&statement,162);">nil) ==sqlITE_OK) {

while(sqlite3_step(statement)==sqlITE_ROW) {

user.= [stringWithFormat:@"%d"sqlite3_column_int(statement,0);">)];

name@"%s"sqlite3_column_text1 user.age =[2 user.sex = [3)];

}

sqlite3_finalize(statement);

returnuser;

}

希望对大家有用:sqliteDEMO

原文链接:https://www.f2er.com/sqlite/201111.html

猜你在找的Sqlite相关文章