Fmdb Common operations

Source: Internet
Author: User

-(nsstring *) databasefilepath{    //access to the database path via     nsstring *url  = [nssearchpathfordirectoriesindomains (Nsdocumentdirectory, nsuserdomainmask, yes) lastobject];    nsstring *filename = [url  stringbyappendingpathcomponent:@ "Sqltjl.sqlite"];    return filename;} -(void) fmdbdata{        //get the database     _db =  [fmdatabase databasewithpath:[self databasefilepath]];    //Open Database      if  ([_db open])  {    //Build table          bool result = [_db executeupdate:@ "Create table if not  exists tjl_student (Name text) "];        if  ( Result)  {          &nbsP; nslog (@ "Build table Success");        }else{             nslog (@ "Build table Failed");         }         [_db close];    }}//inserting data-(void) Insetsqlto: (nsstring *) string{    [_db open];    if  ([_ Db open])  {        BOOL res = [_db  executeupdate:@ "insert into tjl_student  (name)  values (?)", string];         if  (!res)  {             nslog (@ "error");        }else{             nslog (@ "Success to insert");         }        [_db close];    }}//Delete data-(void) Deleteopen: ( nsstring *) dataname{    if  ([_db open])  {         nsstring *deletesql = [nsstring stringwithformat:@ "delete  from tjl_student %@ ", dataname];        bool res =  [_db executeUpdate:deleteSql];        if  (!res)  {             nslog (@ "Error when delete  db table ");        }else{             nslog (@ "success to delete db table");         }        [_db open];     }}//Modifying Data-(void) Updataname: (nsstring *) string{    if  ([_db open])  {         nsstring *updatesql = [nsstring stringwithformat:@ " Update tjl_student '%@ ' ", string];        bool res =  [_db executeUpdate:updatesql];        if  (! RES)  {            nslog (@ "Error when  update db table ");        }else{             nslog (@ "success to insert db able");         }        [_db  close];    }}//query data-(void) Seacher: (nsstring *) seaharname{    if   ([_db open])  {  &Nbsp;     fmresultset *rs = [_db executequery:@ "SELECT *  from tjl_student "];        while  ([Rs next])  {            _Devices = [rs  stringforcolumn:@ "Name"];            nslog (@ "is  text---->>> %@ ", [rs stringforcolumn:@" name "]);         }    }}


Fmdb Common operations

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.