2010-04-09 78 views
0

我試圖在iPhone上使用sqlite3插入一些表中的數據... 我從各個步驟得到的所有錯誤代碼表明操作應該是成功的,但實際上,該表爲空......我覺得我失去了一些東西......sqlite3沒有插入之後完成 - >插入到 - > SQLITE_DONE

這裏的代碼:

sqlite3 *database = nil; 
NSString *dbPath = [[[ NSBundle mainBundle ] resourcePath ] stringByAppendingPathComponent:@"placemarks.sql"]; 

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK){ 

sqlite3_stmt *insert_statement = nil; 
//where int pk, varchar name,varchar description, blob picture 
static char *sql = "INSERT INTO placemarks (pk, name, description, picture) VALUES(99,'nnnooooo','dddooooo', '');"; 
    if (sqlite3_prepare_v2(database, sql, -1, &insert_statement, NULL) != SQLITE_OK) { 
     NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); 
    } 

int success = sqlite3_step(insert_statement); 

int finalized = sqlite3_finalize(insert_statement); 

NSLog(@"success: %i finalized: %i",success, finalized); 

NSAssert1(101, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database)); 


sqlit3_step returns 101, so SQLITE_DONE, which should be ok.. 

如果我執行SQL語句命令行工作正常...

任何人有一個想法? 是否可以在編寫placemarks.sql時遇到問題,因爲它位於資源文件夾中?

RGDS

弗拉

回答

0

發現它是什麼!因爲我認爲......我無法修改資源文件夾中的* .sql,因此我必須首先在應用程序的文檔中創建一個副本並使用該副本!