查询sqlite错误内存xcode

时间:2014-05-11 20:45:50

标签: objective-c sqlite memory out


我有一个错误。准备声明问题:内存不足。 怎么解决? 其他查询正常工作。我不知道会是什么。 也许这是一个问题-(TelefonDetail *)telefonDetails:(int)iDMob ??

-(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;
}

1 个答案:

答案 0 :(得分:13)

“内存不足”错误通常是由于尝试使用数据库而未先打开它(或者如果您不小心将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));

这将生成rc21的返回码(SQLITE_MISUSE)。错误信息是一种误导性的“内存不足”:

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