从sqlite数据库中读取图像

时间:2011-03-05 07:30:04

标签: objective-c image

我能够将图像作为blob数据类型插入数据库,但我无法检索它们。这是我试图检索它们的代码。

    -(NSData *) getimage
{

    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
    {       
        sqlStatement="select image from messages";

        if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
        {
            while(sqlite3_step(compiledStatement) == SQLITE_ROW)
            {
            NSData *data = [NSData dataWithBytes:sqlite3_column_blob(compiledStatement, 1) length:sqlite3_column_bytes(compiledStatement, 1)];
                NSLog(@"data length is %d",[data length]);
            ticketsidarray1 = data;

            }
            sqlite3_finalize(compiledStatement);

        }
        sqlite3_close(database);
    }
    NSLog(@"ticketarray lenth is : %d",[ticketsidarray1 length]);

    return ticketsidarray1;
}

ticketsidarray1的类型为NSData,日志打印的数据长度为0.我不知道我哪里出错了。提前谢谢。

0 个答案:

没有答案