tags:

views:

78

answers:

0

Hello,

How can i update image (blob) field in sqlite.

here is the code which was i using.

UIImage *imgSign = [[UIImage alloc] initWithData:[self StringToData:objSql.signature]];
imgsignature.image = imgSign; 
Imagedata = UIImageJPEGRepresentation(imgSign, 1.0);
empId = createById;
signatureImage = Imagedata;

-(void)UpdateSignature
{
    if(updateStmt == nil) {

        const char *sql = "update tbl_image set image=? where employee_id=?";
        if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK) 
            NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database));
    }

    sqlite3_bind_blob(updateStmt,1, [signatureImage bytes], [signatureImage length], NULL);
    sqlite3_bind_int(updateStmt, 2, empId);

    if(SQLITE_DONE != sqlite3_step(updateStmt))
        NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));
    sqlite3_reset(updateStmt);
    updateStmt = nil;
}

Please does anyone have idea about this. Thank you