Use of SQLite in iOS

Source: Internet
Author: User
Tags ming

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

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.