if(sqlite3_open([[selfdatabasePath]UTF8String],&database) !=sqlITE_OK) {
sqlite3_close(database);
@H_
502_45@
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)
{
@H_
301_164@ 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