Following code i am Writing to store image in DB.
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO slamDetailsTable (name, gender, phone,email,movie,abt,dob,smiley1,smily2,smily3,image) VALUES (\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",?)", contact.name, contact.gender, contact.phone,contact.email,contact.movies,contact.abtMe,contact.dob,contact.smiley1,contact.smiley2,contact.smiley3];
NSLog(@"query %@",insertSQL);
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL);
sqlite3_bind_blob(statement, 1, [contact.imageData bytes], [contact.imageData length], NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(@"Row added");
}
else {
NSLog(@"Failed to add row");
}
Following line i am adding to get image.
NSData *imageDataFromDb = [[NSData alloc]initWithBytes:sqlite3_column_blob(statement, 11) length:sqlite3_column_int(statement, 11)];
But. imageDataFromDb showing 0 bytes.
You should not use
sqlite3_column_int()to get the length of the blob. The correct call to use issqlite3_column_bytes().