SQLite, sqlite3

Source: Internet
Author: User

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

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.