我正在试验一个SQL“无法打开数据库文件我的代码是”执行此代码的错误:
-(void)insertDetail:(NSArray *)platos details:(NSMutableArray *)details integer:(int)i platoID:(int)platoID{
NSString *file = [self getWritableDBPath];
if (sqlite3_open([file UTF8String] , &_database) == SQLITE_OK)
{
const char *query = "INSERT INTO details (id_task ,name, value) VALUES (?,?,?)";
sqlite3_stmt *compiledStatement = nil;
sqlite3_exec(_database, "BEGIN TRANSACTION", 0, 0, 0);
if(sqlite3_prepare_v2(_database, query, -1, &compiledStatement, NULL) == SQLITE_OK){
for (int j = 0; j < [details count]; j++){
NSString *elementoTipo = [details objectAtIndex:j];
NSString *elementoValore = [[platos valueForKey:[details objectAtIndex:j]]objectAtIndex:i];
if (elementoValore == [NSString stringWithFormat:@""]) {
elementoValore=[NSString stringWithFormat:@"null"];
}
sqlite3_bind_text(compiledStatement, 1, [[NSString stringWithFormat:@"%d",platoID] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [[NSString stringWithFormat:@"%@",elementoTipo] UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 3, [[NSString stringWithFormat:@"%@",elementoValore] UTF8String], -1, SQLITE_TRANSIENT);
if (sqlite3_step(compiledStatement) != SQLITE_DONE) NSLog(@"DB not updated. Error: %s",sqlite3_errmsg(_database));
if (sqlite3_reset(compiledStatement) != SQLITE_OK) NSLog(@"SQL Erro1 InsertDetails: %s",sqlite3_errmsg(_database));
}//for
}//prepare
if (sqlite3_finalize(compiledStatement) != SQLITE_OK) NSLog(@"SQL Error2 InsertDetails: %s",sqlite3_errmsg(_database));
if (sqlite3_exec(_database, "COMMIT TRANSACTION", 0, 0, 0) != SQLITE_OK) NSLog(@"SQL Error3 InsertDetails: %s",sqlite3_errmsg(_database));
}
sqlite3_close(_database);
}
在第一次执行中,它不会出现。重复该功能,出现问题。 有什么帮助吗?