Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selStmt, 2) length:sqlite3_column_bytes(selStmt, 2)];
- item.archThumb = [UIImage imageWithData:data];
- UIImage *theimage = [[UIImage alloc]init];
- theimage =[UIImage imageWithData:data];
- -(void)readItems{
- if (!database) return; // earlier problems
- // build select statement
- if (!selStmt)
- {
- const char *sql = "SELECT items.arch_id, items.arch_name, arch_thumbs.thumbs_image FROM items LEFT JOIN arch_thumbs ON items.arch_id = arch_thumbs.thumbs_arch_id ORDER BY items.arch_name ASC;";
- if (sqlite3_prepare_v2(database, sql, -1, &selStmt, NULL) != SQLITE_OK)
- {
- selStmt = nil;
- }
- }
- if (!selStmt)
- {
- NSAssert1(0, @"Can't build SQL to read items [%s]", sqlite3_errmsg(database));
- }
- // loop reading items from list
- int ret;
- while ((ret=sqlite3_step(selStmt))==SQLITE_ROW)
- { // get the fields from the record set and assign to item
- // primary key
- NSInteger n = sqlite3_column_int(selStmt, 0);
- Item *item = [[Item alloc] initWithPrimaryKey:n]; // create item
- // item name
- char *s = (char *)sqlite3_column_text(selStmt, 1);
- if (s==NULL) s = "";
- item.name = [NSString stringWithUTF8String:(char *)s];
- NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selStmt, 2) length:sqlite3_column_bytes(selStmt, 2)];
- if (sqlite3_column_blob(selStmt, 2) != NULL) {
- item.archThumb = [UIImage imageWithData:data];
- NSLog(@"the image is:%@", item.archThumb);
- }
- else{
- NSLog(@"read a NULL image");
- }
- [items addObject:item]; // add to list
- [item release]; // free item
- [data release];
- }
- sqlite3_reset(selStmt); // reset (unbind) statement
Add Comment
Please, Sign In to add comment