Use Saturday time to read a bit about the knowledge of SQLite, in this record. See the Wisdom Podcast video
The operation of the data is basically adding and deleting the changes:
static Sqlite3 *db; Declares a database @implementation xsdboperator+ (void) initialize{nsstring *filename = [[Nssearchpathfordirectoriesindomains ( NSDocumentDirectory, Nsuserdomainmask, YES) lastobject]stringbyappendingpathcomponent:@ "Student.sqlite"]; Database file path//If the file exists, open the database file, create if it does not exist, and open int result = Sqlite3_open (filename. Utf8string, &db); Determine if the database is open successfully if (result = = Sqlite_ok) {NSLog (@ "Open database succeeded"); } else {NSLog (@ "Open failed"); }} #pragma mark-Create database table + (BOOL) creattable{char *sql = "CREATE table if not exists t_student (ID integer PRIMARY key aut Oincrement,name text,age integer,score integer); "; char *ERRORMESG = NULL; int result = SQLITE3_EXEC (db, SQL, NULL, NULL, &ERRORMESG);//For manipulating database if (result = = SQLITE_OK) {return YES; } else {NSLog (@ "Failed to create table, reason for failure:%s", ERRORMESG); return NO; }}+ (BOOL) insert{char *sql = "INSERT into t_table (name,age) VALUES (' Jack ', 20)"; char *ERRORMESG = NULL; int Result = sqlite3_exec (db, SQL, NULL, NULL, &ERRORMESG); if (result = = SQLITE_OK) {return YES; } else {NSLog (@ "Failed to insert data, failure reason:%s", ERRORMESG); return NO; }}+ (BOOL) updata{char *sql = "Updata t_table set age = 12"; char *ERRORMESG = NULL; int result = SQLITE3_EXEC (db, SQL, NULL, NULL, &ERRORMESG); if (result = = SQLITE_OK) {return YES; } else {NSLog (@ "Failed to update data, reason for failure:%s", ERRORMESG); return NO; }}+ (void) query{char *sql = "Select Id,name,age from T_student;"; Query results Save collection sqlite3_stmt *stmt= NULL; int result = SQLITE3_PREPARE_V2 (db, SQL,-1, &stmt, NULL); if (result = = Sqlite_ok) {NSLog (@ "query statement is legal"); while (Sqlite3_step (stmt) = = Sqlite_row) {//go through the rows until the int sid = Sqlite3_column_int (stmt, 0);//Take the value of the first column of the current row Const unsigned char *sname = Sqlite3_column_text (stmt, 1); int sage = Sqlite3_column_int (stmt, 2); NSLog (@ "%d,%s,%d", Sid,snamE,sage); }} else {NSLog (@ "query statement is not valid"); }} @end
IOS SQLite C language operation