SQLite, sqlite3
What is SQLiteSQLite? It is a lightweight embedded database, which occupies very low resources. In embedded devices, it may only require several hundred KB of memory, which is faster than Mysql and PostgreSQL. What is Database) A warehouse database that organizes, stores, and manages data according to the data structure can be divided into two types: relational databases (mainstream) common relational databases of object type databases PC end: oracle, MySQL, SQL Server, Access, DB2, Sybase embedded \ mobile client: the storage structure of a database that stores data in SQLite databases is similar to that in excel) create a table by adding multiple fields (column, column, and attribute)
Data Storage Method for adding multi-row records (row stores values of multiple fields in each row): Plist (NSArray \ NSDictionary) Preference (Preference setting \ NSUserDefaults) NSCoding (NSKeyedArchiver \ NSkeyedUnarchiver) SQLite3Core Data
1. Open the database
Int sqlite3_open (
Const char * filename, // path of the database file
Sqlite3 ** ppDb // database instance
);
2. execute any SQL statement
Int sqlite3_exec (
Sqlite3 *, // an open database instance
Const char * SQL, // SQL statement to be executed
Int (* callback) (void *, int, char **, char **), // callback after the SQL statement is executed
Void *, // The 1st parameters of the callback function
Char ** errmsg // error message
);
3. Check the validity of SQL statements (preparations before query)
Int sqlite3_prepare_v2 (
Sqlite3 * db, // database instance
Const char * zSql, // SQL statement to be checked
Int nByte, // the maximum length of the SQL statement in bytes
Sqlite3_stmt ** ppStmt, // sqlite3_stmt instance for obtaining database data
Const char ** pzTail
);
4. query a row of data
Int sqlite3_step (sqlite3_stmt *); // If a row of data is queried, SQLITE_ROW is returned.
5. Use stmt to obtain the value of a field (the subscript of the field starts from 0)
Double sqlite3_column_double (sqlite3_stmt *, int iCol); // floating point data
Int sqlite3_column_int (sqlite3_stmt *, int iCol); // Integer Data
Sqlite3_int64 sqlite3_column_int64 (sqlite3_stmt *, int iCol); // long integer data
Const void * sqlite3_column_blob (sqlite3_stmt *, int iCol); // binary text data
Const unsigned char * sqlite3_column_text (sqlite3_stmt *, int iCol); // string data