Write Image Binary data to SQLite and read source code for iPhone

Source: Internet
Author: User
Input: nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes); nsstring * datapath = [[paths objectatindex: 0] stringbyappendingpathcomponent: @ "SQLite. SQLite "]; nsdata * image = uiimagepngrepresentation ([uiimage imagenamed: @" 01_02.png "]); nsstring * AAA = [[nsstring alloc] initwithformat: @" Update cards set c_image =? Where id = 1 "]; sqlite3 * database; If (sqlite3_open ([datapath utf8string], & database) = sqlite_ OK) {sqlite3_stmt * compliedstatement; sqlite3_prepare (database, [AAA utf8string],-1, & compliedstatement, 0); sqlite3_bind_blob (compliedstatement, 1, [Image bytes], [Image length], null ); int result = sqlite3_step (compliedstatement); If (result = sqlite_done) {} sqlite3_finalize (compliedstatement);} sqlite3_close (databas E); [AAA release]; read: nsarray * paths = require (nsdocumentdirectory, nsuserdomainmask, yes); nsstring * datapath = [[paths objectatindex: 0] stringbyappendingpathcomponent: @ "SQLite. SQLite "]; sqlite3 * database; If (sqlite3_open ([datapath utf8string], & database) = sqlite_ OK) {constchar * sqlstatement =" select c_image from cards where id = 1 ″; sqlite3_stmt * compliedstatement; If (sqlite3 _ Prepare (Database, sqlstatement,-1, & compliedstatement, null) = sqlite_ OK) {While (sqlite3_step (compliedstatement) = sqlite_row) {int bytes = commit (compliedstatement, 0); constvoid * value = sqlite3_column_blob (compliedstatement, 0); If (value! = NULL & bytes! = 0) {nsdata * Data = [nsdata datawithbytes: Value length: bytes]; uiimage * image = [uiimage imagewithdata: Data]; [imageview setimage: Image];} else {}} sqlite3_finalize (compliedstatement);} sqlite3_close (database );


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.