Retrieve nsdata from sqlite stored in Blob data type for iPhone App

前端 未结 1 995
自闭症患者
自闭症患者 2020-12-14 13:37

In iPhone App how to store UIImage converted into NSData to sqlite table in BLOB datatype? Is there any kind of binding needed(NSData ->Blob)?

相关标签:
1条回答
  • 2020-12-14 14:10

    I used something like this:

    // prepare sqlite3 statement before this line
    int res = sqlite3_step(stmt);
    if (res == SQLITE_ROW) {
        const void *ptr = sqlite3_column_blob(stmt, 0);
        int size = sqlite3_column_bytes(stmt, 0);
        data = [[NSData alloc] initWithBytes:ptr length:size];
        sqlite3_reset(stmt);
    
        return [data autorelease];
    } 
    sqlite3_reset(stmt);
    

    For saving as blob you can extract pointer and size of NSData using [data bytes] and [data length]. And then bind to your BLOB row

    sqlite3_bind_blob (stmt, 2, [data bytes], [data length], SQLITE_TRANSIENT);
    
    0 讨论(0)
提交回复
热议问题