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)