我們正在爲我們的iPad項目使用SQLite。我們正在從另一個SQLite導入數據。導入數據後,我們無法將數據從viewcontroller插入到Sqlite中。 當我們嘗試訪問設備中的相同內容時拋出一個錯誤,而在模擬器中正常工作。將數據導入到Sqlite3
Error from Device: * Assertion failure in -[DataBaseSharedManager insertLoginDetails:], /Users/vidya/Desktop/eDetail_feb27/eDetail/Classs/Database files/DataBaseSharedManager.m:165 Feb 27 18:07:17 unknown eDetail[1866] : Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error:failed to save priority with message 'database disk image is malformed'' ** First throw call stack: (0x33e758bf 0x352901e5 0x33e757b9 0x3289f3b3 0x336b15 0xae887 0x33dd422b 0x32fd8b 0x328fcc39 0x328546e9 0x328546b3 0x328545d5 0x375048a5 0x374f9545 0x374f9639 0x374f9243 0x374f9179 0x33e49b03 0x33e492cf 0x33e48075 0x33dcb4dd 0x33dcb3a5 0x306b6fcd 0x32393743 0xab125 0xab0bc)
注意:我們的SQlite文件是36MB。
代碼以供參考:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"eTest.sqlite"];
if (sqlite3_open([writableDBPath UTF8String], &database) == SQLITE_OK){
NSString *sSqlSelect = [NSString stringWithFormat:@"Insert into LOGIN (LoginId, UserName, Password, LastSyncDate, SFId,SecurityToken, AccountType, SFUserId,Region,ModifiedDate) values (\"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\")", [pDict objectForKey:@"LoginId"],[pDict objectForKey:@"UserName"],[pDict objectForKey:@"Password"],[pDict objectForKey:@"LastSyncDate"],[pDict objectForKey:@"SFId"],[pDict objectForKey:@"SecurityToken"], [pDict objectForKey:@"AccountType"], [pDict objectForKey:@"SFUserId"],[pDict objectForKey:@"Region"],[pDict objectForKey:@"ModifiedDate"]];
sqlite3_stmt *insertValue;
int nResult = sqlite3_prepare_v2(database, [sSqlSelect UTF8String],-1,&insertValue,NULL);
if(nResult == SQLITE_OK){
sqlite3_step(insertValue);
}else{
NSAssert1(0,@"Error:failed to save priority with message '%s'",sqlite3_errmsg(database));
}
sqlite3_finalize(insertValue);
}else{
sqlite3_close(database);
NSAssert1(0, @"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}
對於交易:我們正在從一個的SQLite中的數據導出和導入同一個表到另一個SQLite的。我們正在使用Firefox SQLite Manager進行此操作。
請幫助我們找到上述問題的解決方案.. – 2012-02-27 12:42:37
你能告訴哪一行它是異常嗎? – NSCry 2012-02-27 14:01:18
NSAssert1(0,@「無法用消息'%s'打開數據庫。」,sqlite3_errmsg(database)); – Deepthi 2012-02-27 14:03:31