It took some time today to sort through the SQLite operations used in previous projects and upload them to GitHub: (Https://github.com/peanutNote/QYSQLiteManagerDemo.git).
As with other third-party purposes, the main purpose is to make the code relevant to the operation of SQLite simple, specific usage:
Add the Qysqlitemanager file to your project and #import "Qysqlitemanager" in the class that you want to manipulate with SQLite.
//INSERT Statement- (void) inserttable{//Creating SQL statementsNSString *sql =@"insert INTO teacher (Name,id) VALUES (?,?)"; //Immutable Parameters//BOOL IsOK = [Qysqlitemanager inserttablewithsqlstring:sql andarray:@[@ "Xiao Ming", @115]]; //variable ParametersBOOL IsOK = [Qysqlitemanager inserttablewithsqlstring:sql andobjects:@"Xiao Ming",@" the", nil]; if(IsOK) {NSLog (@"Data Insertion succeeded"); } Else{NSLog (@"Data Insertion Failure"); }}//Query Statements- (void) selecttable{NSString*sql =@"select * FROM teacher"; [Qysqlitemanager selecttablewithsqlstring:sql Didfinishedblock:^ (Nsarray *datalist, NSString *error) {NSLog (@"%@", dataList); } Andobjects:nil];}//Modify Table Statements- (void) altertable{NSString*sql =@"ALTER TABLE teacher add column pwd integer"; if([Qysqlitemanager altertablewithsqlstring:sql]) {NSLog (@"Modification succeeded"); }}//Update DATA Statement- (void) updatetable{NSString*sql =@"Update teacher Set name =? where id =?"; if([Qysqlitemanager Updatetablewithsqlstring:sql andarray:@[@"Xiao Ming",@ the]]) {NSLog (@"Update Successful"); }}
For the type of data returned by the query statement, students who need it can find "sqlite3_bind_text" in "qysqlitemanager.m", and then
//binding Data for(inti =0; I <params. count;i++) { //If the data is a string if([params[I] iskindofclass:[nsstringclass]]) {Sqlite3_bind_text (stmt, I+1, [params[i] utf8string],-1, NULL); } //If the data is an integer if([params[I] Iskindofclass:[nsnumberclass]]) {sqlite3_bind_int (stmt, I+1, [params[i] intvalue]); } }
Change the type of data you want.
Use of SQLite in iOS