IOS SQLite C language operation

Source: Internet
Author: User

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

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.