Guest User

Untitled

a guest
Jul 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selStmt, 2) length:sqlite3_column_bytes(selStmt, 2)];
  2.  
  3. item.archThumb = [UIImage imageWithData:data];
  4.  
  5. UIImage *theimage = [[UIImage alloc]init];
  6. theimage =[UIImage imageWithData:data];
  7.  
  8. -(void)readItems{
  9. if (!database) return; // earlier problems
  10.  
  11. // build select statement
  12. if (!selStmt)
  13. {
  14. 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;";
  15. if (sqlite3_prepare_v2(database, sql, -1, &selStmt, NULL) != SQLITE_OK)
  16. {
  17. selStmt = nil;
  18. }
  19. }
  20. if (!selStmt)
  21. {
  22. NSAssert1(0, @"Can't build SQL to read items [%s]", sqlite3_errmsg(database));
  23. }
  24.  
  25. // loop reading items from list
  26. int ret;
  27. while ((ret=sqlite3_step(selStmt))==SQLITE_ROW)
  28. { // get the fields from the record set and assign to item
  29. // primary key
  30. NSInteger n = sqlite3_column_int(selStmt, 0);
  31. Item *item = [[Item alloc] initWithPrimaryKey:n]; // create item
  32. // item name
  33. char *s = (char *)sqlite3_column_text(selStmt, 1);
  34. if (s==NULL) s = "";
  35. item.name = [NSString stringWithUTF8String:(char *)s];
  36.  
  37. NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(selStmt, 2) length:sqlite3_column_bytes(selStmt, 2)];
  38.  
  39. if (sqlite3_column_blob(selStmt, 2) != NULL) {
  40. item.archThumb = [UIImage imageWithData:data];
  41. NSLog(@"the image is:%@", item.archThumb);
  42. }
  43. else{
  44. NSLog(@"read a NULL image");
  45. }
  46.  
  47. [items addObject:item]; // add to list
  48. [item release]; // free item
  49. [data release];
  50. }
  51. sqlite3_reset(selStmt); // reset (unbind) statement
Add Comment
Please, Sign In to add comment