objective c - Saving and retrieving images to and from SQLite in iOS -


i trying save images in sqlite , load image in uiimageview. it's not getting work. don't what's getting wrong. here code using. can me solve issue.

- (void)saveimage {     sqlite3_stmt *compiledstmt;     if(sqlite3_open([dbpath utf8string], &db)==sqlite_ok){         const char *insertsql="insert image(image)values(?)";         if(sqlite3_prepare_v2(db,insertsql, -1, &compiledstmt, null) == sqlite_ok){             uiimage *image = [uiimage imagenamed:@"farmhouse.png"];             nsdata *imagedata=uiimagepngrepresentation(image);             sqlite3_bind_blob(compiledstmt, 1, [imagedata bytes], [imagedata length], null);              sqlite3_step(compiledstmt);              char *errmsg;             sqlite3_exec(db, insertsql, null,compiledstmt,&errmsg);          }     } }  - (void)showimage {     sqlite3_stmt *compiledstmt;     if(sqlite3_open([dbpath utf8string], &db)==sqlite_ok){         const char *insertsql = "select image image sl.no = ?";         sqlite3_prepare_v2(db,insertsql, -1, &compiledstmt, null);         if(sqlite3_prepare_v2(db,insertsql, -1, &compiledstmt, null) == sqlite_ok){             sqlite3_bind_int(compiledstmt, 1, 1);             if(sqlite_done != sqlite3_step(compiledstmt)) {                                 nsdata *data = [[nsdata alloc] initwithbytes:sqlite3_column_blob(compiledstmt, 1) length:sqlite3_column_bytes(compiledstmt, 1)];                  if(data == nil)                     nslog(@"no image found.");                 else                     imgview.image = [uiimage imagewithdata:data];               }         }     } } 

can point out issue above code.

thanks in advance

- (void)saveimage  {   sqlite3_stmt *compiledstmt;   sqlite3 *db;   if(sqlite3_open([dbpath utf8string], &db)==sqlite_ok){   nsstring *insertsql=@"insert image(image) values(?)";   if(sqlite3_prepare_v2(db,[insertsql cstringusingencoding:nsutf8stringencoding], -1, &compiledstmt, null) == sqlite_ok){   uiimage *image = [uiimage imagenamed:@"vegextra.png"];   nsdata *imagedata=uiimagepngrepresentation(image);    sqlite3_bind_blob(compiledstmt, 1, [imagedata bytes], [imagedata length], sqlite_transient);    if(sqlite3_step(compiledstmt) != sqlite_done ) {       nslog( @"error: %s", sqlite3_errmsg(db) );   } else {       nslog( @"insert row id = %lld", (sqlite3_last_insert_rowid(db)));   }  sqlite3_finalize(compiledstmt);   }  } sqlite3_close(db); }  - (void)showimage  {    sqlite3_stmt *compiledstmt;    sqlite3 *db;    int = 1;    if(sqlite3_open([dbpath utf8string], &db)==sqlite_ok){    nsstring *insertsql = [nsstring stringwithformat:@"select image image id = %d",i];    if(sqlite3_prepare_v2(db,[insertsql cstringusingencoding:nsutf8stringencoding], -1, &compiledstmt, null) == sqlite_ok) {    while(sqlite3_step(compiledstmt) == sqlite_row) {     int length = sqlite3_column_bytes(compiledstmt, 0);    nsdata *imagedata = [nsdata datawithbytes:sqlite3_column_blob(compiledstmt, 0) length:length];     nslog(@"length : %d", [imagedata length]);    if(imagedata == nil)      nslog(@"no image found.");   else      imgview.image = [uiimage imagewithdata:imagedata];    }  }  sqlite3_finalize(compiledstmt); } sqlite3_close(db); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -