Start a transaction with:sqlite3_exec(db,"BEGIN",0);
@H_301_5@
Commit a transaction with: 一下的代码是用transaction的,首先尝试了把两个sql语句链接在一起的,用一个sqlite3_prepare——似乎没成功,分开来写,也没成功,难道是有什么特别的?@H_301_5@
//sqlite3_exec(database,0);@H_301_5@
NSLog(@"querysql :%@",sql1);@H_301_5@
NSLog(@"querysql :%@",sql2);@H_301_5@
if(sqlite3_prepare_v2(database,[sql1 UTF8String],-1,&compiledStatement,NULL) == sqlITE_OK && sqlite3_prepare_v2(database,[sql2 UTF8String],NULL) == sqlITE_OK)@H_301_5@
{@H_301_5@
//sqlite3_exec(database,0);@H_301_5@
retValue=YES;@H_301_5@
}@H_301_5@
else {@H_301_5@
//sqlite3_exec(database,"ROLLBACK",0);@H_301_5@
@H_301_5@
}@H_301_5@
sqlite3_finalize(compiledStatement);@H_301_5@
sqlite3_close(database);@H_301_5@
后来我还是想了好多方法,至少sql语句看起来是可以的,在sql analzer里面是ok的,@H_301_5@
@H_301_5@
if (sqlite3_exec (database,[updatesqlUTF8String],NULL,&errorMsg) != sqlITE_OK)@H_301_5@
{@H_301_5@
NSLog(@"upate error");@H_301_5@
sqlite3_close(database);@H_301_5@
return NO;@H_301_5@
}@H_301_5@
@H_301_5@
【2】创建表格@H_301_5@
//创建表格,假设有五个字段,(id,cid,title,imageData ,imageLen )@H_301_5@
//说明一下,id为表格的主键,必须有。@H_301_5@
//cid,和title都是字符串,imageData是二进制数据,imageLen 是该二进制数据的长度。 - (BOOL) createChannelsTable:(sqlite3*)db{ char *sql = "CREATE TABLE channels (id integer primary key,\ cid text,\ title text,\ imageData BLOB,\ imageLen integer)"; sqlite3_stmt *statement; if(sqlite3_prepare_v2(db,&statement,nil) != sqlITE_OK) { NSLog(@"Error: Failed to prepare statement:create channels table"); return NO; } int success = sqlite3_step(statement); sqlite3_finalize(statement); if ( success != sqlITE_DONE) { NSLog(@"Error: Failed to dehydrate:CREATE TABLE channels"); return NO; } NSLog(@"Create table 'channels' successed."); return YES; }@H_301_5@
@H_301_5@
@H_301_5@
@H_301_5@
@H_301_5@
@H_301_5@