Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting image in to Database using sqlite in xcode4.6
    primarykey
    data
    text
    <p>im Working on inserting <em>IMAGE in to Database</em> using sqlite in Xcode 4.6 ,i just wanted to insert a <strong>textfield</strong> and <strong>uiimageview</strong>(having dynamically generated barcode image).</p> <p>unfortunately im getting <strong><em>" Error is: out of memory "</em></strong></p> <p>hear is the code I'm using ,plz let me know where my mistake is &amp; Let me know for more details</p> <p><strong>* 1. Database creation*</strong></p> <pre><code>-(void)createoropendb { NSArray *path =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docpath =[path objectAtIndex:0]; dbpathstring =[docpath stringByAppendingPathComponent:@"DataBase.db"]; char *error; NSFileManager *filemanager =[NSFileManager defaultManager]; if (![filemanager fileExistsAtPath:dbpathstring]) { const char *dbpath =[dbpathstring UTF8String]; if (sqlite3_open(dbpath, &amp;barcodeDB) == SQLITE_OK) { const char *sql_start ="CREATE TABLE IF NOT EXISTS DBTABLE1(NAME TEXT UNIQUE,IMAGEURL BLOB)"; NSLog(@"db created"); sqlite3_exec(barcodeDB, sql_start,NULL,NULL, &amp;error); sqlite3_close(barcodeDB); } } } </code></pre> <p><strong>* 2.button to insert data*</strong></p> <pre><code>- (IBAction)savedata:(id)sender { UIImage *image =imageView.image; NSData *imageData=UIImagePNGRepresentation(image); [self SaveImagesToSql: imageData.bytes:Uimagetext.text]; } </code></pre> <p><strong>* 3.method to insert data*</strong></p> <pre><code>- (void) SaveImagesToSql: (NSData*) imgData :(NSString*) mainUrl { const char* sqliteQuery = "INSERT INTO DBTABLE1(NAME,IMAGEURL) VALUES (?, ?)"; sqlite3_stmt* statement; if( sqlite3_prepare_v2(barcodeDB, sqliteQuery, -1, &amp;statement, NULL) == SQLITE_OK ) { sqlite3_bind_text(statement, 1,[mainUrl UTF8String], -1, SQLITE_TRANSIENT); sqlite3_bind_blob(statement, 2,[imgData bytes],[imgData length], SQLITE_TRANSIENT); sqlite3_step(statement); NSLog( @"Saved image successfully" ); } else { NSLog( @"SaveBody: Failed from sqlite3_prepare_v2. Error is: %s",sqlite3_errmsg(barcodeDB) ); } // Finalize and close database. sqlite3_finalize(statement); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload