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: