Fmdb third-party libraries
Import Header File
#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 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 "]; //read data by line while ([Resultset next]) { //corresponding fields to read 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];}
Create a sms.db database both sides create a message table, insert the data, and then read the data