2014-05-11 86 views
4


我有一個錯誤。準備陳述的問題:內存不足。 如何解決它? 其他查詢正常工作。我不知道會是什麼。 也許這是一個問題-(TelefonDetail *)telefonDetails:(int)iDMob ??查詢sqlite錯誤內存不足xcode

-(TelefonDetail *)telefonDetails:(int)iDMob 
{ 
TelefonDetail *retvalTelefon = nil; 
NSString *ZaprosTelefons = @"SELECT iDMob , marka, model,wifi, os, razmeri,Display,Camera,Stoimos,imageTel,opisCrat FROM MobTele WHERE iDMob=1"; 
sqlite3_stmt *statement1; 
if (sqlite3_prepare_v2(_database, [ZaprosTelefons UTF8String], -1, &statement1, nil) 
    != SQLITE_OK) { 
    NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(_database)); 
} 
else{ while (sqlite3_step(statement1) == SQLITE_ROW) { 
     int iDMob = sqlite3_column_int(statement1, 0); 
     char *Marka = (char *) sqlite3_column_text(statement1, 1); 
     char *Model = (char *) sqlite3_column_text(statement1, 2); 
     char *Wifi = (char *) sqlite3_column_text(statement1, 3); 
     char *OS = (char *) sqlite3_column_text(statement1, 4); 
     char *Razmeri = (char *) sqlite3_column_text(statement1, 5); 
     char *Display = (char *) sqlite3_column_text(statement1, 6); 
     char *Camera = (char *) sqlite3_column_text(statement1, 7); 
     char *Stoimos = (char *) sqlite3_column_text(statement1, 8); 
     Byte *imgTel = (Byte *) sqlite3_column_blob(statement1, 9); 
     NSString *marka = [[NSString alloc] initWithUTF8String:Marka]; 
     NSString *model = [[NSString alloc] initWithUTF8String:Model]; 
     NSString *wifi = [[NSString alloc] initWithUTF8String:Wifi]; 
     NSString *os = [[NSString alloc] initWithUTF8String:OS]; 
     NSString *razmeri = [[NSString alloc] initWithUTF8String:Razmeri]; 
     NSString *display = [[NSString alloc] initWithUTF8String:Display]; 
     NSString *camera = [[NSString alloc] initWithUTF8String:Camera]; 
     NSString *Stoimost = [[NSString alloc] initWithUTF8String:Stoimos]; 
     int len = sqlite3_column_bytes(statement1, 9); 
     NSData *imgData = [[NSData alloc] initWithBytes:imgTel length:len]; 

    retvalTelefon = [[TelefonDetail alloc]initWhithIDMob:iDMob marka:marka model:model wifi:wifi os:os razmeri:razmeri display:display camera:camera Stoimost:Stoimost imegeTel:imgData]; 
} 
    sqlite3_finalize(statement1); 
} 
return retvalTelefon; 
} 
+0

這通常是由於未能完成語句或類似的聲明。錯誤可能很容易在代碼的另一部分,但這是你得到「位」的地方。 –

+0

搜索S.O.對於「sqlite內存不足」,你會得到很多點擊,例如[爲什麼我得到一個SQLITE_MISUSE:內存不足錯誤?](http://stackoverflow.com/questions/15283117/why-do-i-get-a-sqlite-misuse-out-of-memory-error) – Rob

回答

10

的「內存不足」的錯誤往往是最早打開它引起試圖用一個數據庫,而不誤導性的錯誤消息(或者,如果你不小心的sqlite3數據庫指針設置爲NULL)。例如:

sqlite3 *db = NULL; 
sqlite3_stmt *statement; 
int rc; 

// deliberately did not open database -- ERROR 

// now try to use SQLite without opening database 

if ((rc = sqlite3_prepare_v2(db, "select * from test", -1, &statement, NULL)) != SQLITE_OK) 
    NSLog(@"rc=%d errmsg=%s", rc, sqlite3_errmsg(db)); 

這將生成的21SQLITE_MISUSE一個返回碼(rc)。並且錯誤信息是一個誤導性的「內存不足」:

 
2014-05-11 17:36:22.035 MyApp[19942:60b] rc=21 errmsg=out of memory 
+0

你的回答很有幫助。 – bittu