2009-11-09 54 views
1

我目前正在爲iPhone的遊戲工作,圖像從互聯網加載,然後存儲在本地數據庫,所以他們不必再次加載。這一直運行良好。 最近我爲測試組創建了一個新的adhoc發行版(我第一次使用SDK 3.1.2創建發行版),現在每個將iphone升級到3.1.2的人都不再能夠寫入數據庫了,因此必須每次從互聯網加載圖像。 iphone版本低於3.1.2的用戶沒有問題,而以前的版本(用SDK 3.1或更低版本)對於帶有3.1.2的iphones沒有問題。 我對遊戲進行的更新與遊戲中的數據管理員無關。另一個奇怪的是,我不使用下面的代碼中找到在控制檯中的任何消息:sqlite3在iPhone 3.1.2寫入權限問題

- (void) saveImage:(NSString *)imagePath withData:(NSData *)imageData { 
    if (insert_image_statement == nil){ 
     const char *sql2 = "INSERT INTO image (imagePath, imageData) VALUES (?, ?);"; 
     if (sqlite3_prepare_v2(database, sql2, -1, &insert_image_statement, NULL) != SQLITE_OK) { 
      NSLog(@"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database)); 
     } 
    } 
    sqlite3_bind_text(insert_image_statement, 1, [imagePath UTF8String], -1, NULL); 
    sqlite3_bind_blob(insert_image_statement, 2, [imageData bytes], [imageData length], NULL); 
    int success = sqlite3_step(insert_image_statement); 
    if (success == SQLITE_ERROR){ 
     NSLog(@"Error: failed to insert statement with message '%s'.", sqlite3_errmsg(database)); 
    } 
    sqlite3_reset(insert_image_statement); 
} 

所以sqlite3的不放箭,可以點我對這個問題的解決方案的錯誤。有人知道爲什麼使用SDK 3.1.2我似乎沒有將數據寫入數據庫的權限?

+0

你看到了什麼錯誤?你的數據庫在哪裏?你從sqlite3_bind_text和sqlite3_bind_blob得到了什麼結果?我可以向你保證,我們仍然在用3.1.2編寫blob到我們的數據庫,而且我們的SQL比這更復雜。我懷疑你在SQLite中發現了一個錯誤。 – 2009-11-13 16:59:11

+0

我沒有看到任何錯誤,我注意到的唯一情況是該blob沒有寫入數據庫。數據庫位於documentsDirectory中。奇怪的是,它只發生在AdHoc Distribution中,如果我直接在手機上構建應用程序,它不會發生。 – 2009-11-16 08:42:54

回答

0

是否解決了此問題?我遇到了與3.1.2中的Device/Release構建類似的問題,其中在if(sqlite3_exec(...))中引發錯誤;語句,但不返回錯誤消息。

********更新:通過修改引用以在設備上包含完整路徑來達到部分解決方案。谷歌「checkAndCreateDatabase」方法的代碼。我仍然在3.1.2操作系統上的設備上的sqlite prepare語句失敗,我沒有在模擬器中。**********

-(void)initializeDatabaseFunctions { 

databaseName = "RowTable.db"; 
returnCode = sqlite3_open(databaseName, &sqlite); 

NSString *dropRows = [[NSString alloc]initWithFormat:@"DROP TABLE IF EXISTS rows;"]; 
if(sqlite3_exec(sqlite, [dropRows UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK) { 
    NSLog(@"Error DROP TABLE IF EXISTS rows: %s", errorMsg); 
sqlite3_free(errorMsg);}