Sunday 15 February 2015

ios - Inserting image in to Database using sqlite in xcode4.6 -


text after "itemprop =" text ">

im working on im image in database using SQLite in Xcode 4.6, I just insert Text field and UIImageView (with dynamically generated barcode images)

Unfortunately getting im "Error: Out of memory".

I'm using the code while listening, tell me where my fault is & amp; Let me know for more information

* 1. Database creation *

  - (zero) createoropendb {NSArray * path = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory , NSUserDomainMask, yes); NSString * docpath = [path objectwithoutx: 0]; Dbpathstring = [Dockpath stringBapensitting path component: @ "Database DSDB"]; Four * error; NSFileManager * Filemanager = [NSFileManager defaultManager]; If (! [Filemaner xxtists atpeth: dbipithstring]) {casts four * dbipith = [dbpithstring utf 8 string]; (Sqlite3_open (dbpath, & barcodeDB) == SQLITE_OK) If {constants four * sql_start = "table creation does not exist, then DBTABLE1 (naming text unique, imageUrl blob)"; NSLog (@ "DB made"); Sqlite3_exec (barcode, sql_start, NULL, NULL, and error); Sqlite3_close (barcodeDB); }}}   

* 2. Button to insert button *

  - (IBAction) saved: (id) Sender {UIImage * image = imageView.image; NSDTa * ImageData = UIImagePNG Mapping (Image); [Self images TOSQL: imageData.bytes: Uimagetext.text]; }   

* 3.Method to insert data

  - (zero) Save images TOSQL: (NSData *) imgData :( NSString *) mainUrl {const char * sqliteQuery = "Include DBTable1 (NAME, IMAGEURL) values ​​(?,?)"; Sqlite3_stmt * statement; If (sqlite3_prepare_v2 (barcodeDB, sqliteQuery, -1, & statement, zero) == SQLITE_OK) {sqlite3_bind_text (statement, 1, [mainUrl UTF8String], -1, SQLITE_TRANSIENT); Sqlite3_bind_blob (statement, 2, [IMGDATA bytes], [length of IMGDT], SQLTITINSIISInt;); Sqlite3_step (statement); NSLog (@ "saved image successfully"); } Else {NSLog (@ "SaveBody: Failed from sqlite3_prepare_v2. Error:% s", sqlite3_errmsg (barcodeDB)); } // final and close database sqlite3_finalize (statement); }    

return code (which is not SQLITE_OK ) undoubtedly is returning to SQLITE_MISUSE , which means that you are trying to use a database that you have not yet opened and is creating your createoropendb If the database is not present, but if it exists, then you are not opening it (and even if it is present, you are closing it after making it).

If you call sqlite3_prepare , then the database will not be opened, then the function will return to SQLITE_MISUSE , sqlite3_errmsg < / Code> will return a misleading "out of memory" text message.

No comments:

Post a Comment