Basic operation of SQLite database

Source: Internet
Author: User
Tags sqlite database

1, the use of SQLite database, you need to first add libsqlite3.dylib on the system framework, as follows

2. Open the Database

Add the-DB member variable to the header file:

{

Sqlite3 * _DB; DB represents the entire database and is a DB instance

}

///1, get the database file name in the sandbox

NSString * FileName = Nsuserdomainmask, YES) lastobject]stringbyappendingpathcomponent:@ "Student.sqlite"];

2. Open the Database

int result = Sqlite3_open (filename.utf8string, &_db);

if (result = = SQLITE_OK) {

NSLog (@ "Successfully open database");

2. Create a table

const char * sql = "CREATE table if not exists t_student (ID integer primary key autoincrement,name text,age integer);";

char * ERRORMESG = NULL;

int result = SQLITE3_EXEC (_db, SQL, NULL, NULL, &ERRORMESG);

if (result = = SQLITE_OK) {

NSLog (@ "CREATE table successfully");

}else

{

NSLog (@ "Failed to create table:%s", ERRORMESG);

}

}else

{

NSLog (@ "Failed to open database");

}

3. Query statements

4, the implementation of the INSERT statement:

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.