"Extraordinary programmer" OC 18th session (Database MySQL and sqlite3 application)

Source: Internet
Author: User

Applying Sqlite3 in your code

ViewController.h file

#import <UIKit/UIKit.h>
#import "Sqlite3.h"

@interface Viewcontroller:uiviewcontroller

{
Sqlite3 * LINK;

NSString *path;

}

@end

VIEWCONTROLLER.M file:

#import "ViewController.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {
[Super Viewdidload];
Additional setup after loading the view, typically from a nib.

//Give the address of the Person.db file to path
Path [email protected]"users/feifanjiaoyu/desktop/person.db";
//OK library file, open database link
Sqlite3_open ([path Utf8string],&link);
//Create
NSString *[email protected] "Create* Table Student (name Varcahr (), age int) ";
//Execute SQL statement
sqlite3_exec (link, [creat utf8string],nil,nil,nil);
Insert
NSString *insert = @ "INSERT into student (Name,age) VALUES (' zhangsuiping ', 17)";
    sqlite3_exec (link, [insert utf8string],nil,nil                                                                                                                                                                                                                                                                                                                    , nil);
//Update
NSString*[email protected]"Updatestudent set age=19 where name= ' zhangsuiping ' ";
Sqlite3_exec (link, [Update utf8string],nil,nil,nil);
//delete
NSString*[email protected]"DeleteFrom student where age=19 ";
Sqlite3_exec (link, [delete utf8string],nil,nil,nil);

Inquire
Sqlite3_stmt *assss;
NSString *select = @ "SELECT *from student";
//Pre-compile check SQL statements
SQLITE3_PREPARE_V2 (link, [select Utf8string],-1, &assss, nil);
while (Sqlite3_step (ASSSS) ==sqlite_row)
{
NSLog (@ "%s%s", Sqlite3_column_text (assss, 0), Sqlite3_column_text (ASSSS, 1));
//---Print the values of the first and second columns of each row of records
}
//Off
Sqlite3_close (link);

}

-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}

@end

"Extraordinary programmer" OC 18th session (Database MySQL and sqlite3 application)

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.