iOS database Fmdb

Source: Internet
Author: User
<span id="Label3"> </p><pre class="brush:cpp;toolbar: true; auto-links: false;">Fmdb third-party Libraries Import header files #import  "FMDatabase.h" #import   "FMResultSet.h" fmdatabase *_database;//database objects-  ( Void) readdata{    //1. Gets the path to the database file     nsarray *path= Nssearchpathfordirectoriesindomains (nscachesdirectory, nsuserdomainmask, yes);    Nsstring *documentpath=[path objectatindex:0];   nsstring *dbpath=[documentpath  stringbyappendingpathcomponent:@ "sms.db"];    //2. Create database     _database=[[fmdatabase alloc]initwithpath:dbpath];    //3.open//first   Database file if it does not exist then   will create and open         //if it exists   then open it directly     if   ([_database open])  {        nslog (@ "database Open successfully");         //creating A new table does not exist,         nsstring  *[email protected] "create&Nbsp;table if not exists message (serial integer primary key  Autoincrement,guid integer,text string) ";         // In addition to querying everything else with executeupdate        bool issuccess=[_database  executeupdate:sql];        if  (!isSuccess)  {             nslog (@ "creattable error:%@", _ database.lasterrormessage);                    }        //inserting Data          nsstring *[email protected] "insert into message  (serial , Guid,text)  values (?,?,?) ";         bool issuccess2=[_database executeupdate:sql2,@ "111" , @ "119", @ "111"];        if  (!issuccess2)  {             nslog (@ "insert failed");        }else{             nslog (@ "insert succeeded");         }    }    //lookup Table allthequstions     fmresultset *resultset=[_database executequery:@ "select * from message"];     //reading data by line     while  ([resultset next])  {         //the corresponding field to read the data         nsstring * serial=[resultset stringforcolumn:@ "serial"];        nsstring  *guid=[resultset stringforcolumn:@ "guid"];        nsstring  *text=[resultset stringforcolumn:@ "text"];        nslog (@ "serial:% @guid:%@,text:%@", serial, guid,text);     }    [_database close];}</pre> <p><p><br></p></p><p><p>iOS database Fmdb</p></p></span>

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.