An explanation of the Android Qlite database

Source: Internet
Author: User

Qlite uses a Dynamic data type, when a value is inserted into the database, SQLite checks its type, and if the type does not match the associated column, SQLite attempts to convert the value to the type of the column, and if it cannot, the value is stored as its own type, which SQLite calls " Weak type ". However, there is a special case, if the integer PRIMARY KEY, then the other type will not be converted, will be reported a "datatype Missmatch" error. SQLite supports NULL, Integer, REAL, text, and BLOB data types, representing null values, integer values, floating-point values, string literals, binary objects, SQLite only provides database-level locking. SQLite does not have a user account concept, but instead determines the permissions of all databases based on the file system. After you have completed the operation on the database, remember to call Sqlitedatabase's close () method to release the database connection, otherwise the sqliteexception is prone to occur. SQlite uses a file to save the database, and a file is a database. The database contains several tables, each containing multiple records, each with multiple fields, each with its corresponding value, and each value can specify a type. The database name is the filename, the table has its own name, the record has no name, and each field has a name. In SQLite, the concept of no order is recorded, there is no concept of the first and second such, and only the records satisfying the condition can be obtained by querying. We operate the database by executing SQL instructions. Sqliteopenhelper class Introduction Sqliteopenhelper is a helper class for sqlitedatabase that manages the creation of databases and the updating of versions. The general is to establish a class to inherit it, and implement its OnCreate and Onupgrade method construction method, usually pass a database name to create the parameter Sqliteopenhelper (Context context,string name, Sqlitedatabase.cursorfactory factory,int Version) When you create a database, call OnCreate (Sqlitedatabase db) When the update is called Onupgrade ( Sqlitedatabase db,int oldversion, int newversion) Create or open a read-only database Getreadabledatabase () Create or open a read-write database Getwritabledatabase ( Create a database here is a special place by calling the Sqliteopenhelper class GThe Etreadabledatabase () method implements the Databasehelper database = new Databasehelper (this) that creates a data base;// This code is placed in the activity class only with thissqlitedatabase db = Null;db = Database.getreadalbedatabase (); The Sqlitedatabase class provides us with a number of methods, and the more common method is the following (return value) method name method description (int) Delete (String table,string whereclause,string[] whereargs) Convenient method for deleting data rows (long) Insert (string table,string nullcolumnhack,contentvalues values) Add a convenient method (int) update for the data row (string table, Contentvalues values, String whereclause, string[] whereargs) A convenient way to update data rows (void) execsql (String sql) executes an SQL statement, Can be a select or other SQL statement (void) close () Closed database (Cursor) query (string table, string[] columns, string selection, string[] Selectionargs, String groupBy, String having, string-by-clause, string limit) queries the specified data table to return a data set with a cursor (cursor) rawquery (String SQL, string[] Selectionargs) runs a preset SQL statement that returns a data set with a cursor (the biggest difference from the above statement is the prevention of SQL injection) the data query data query is more complex than the previous methods. Because the query will have many criteria for querying through query public Cursor query (string table, string[] columns, string selection, string[] Selectionargs, String groupBy, String having, string-by-clause, string limit) Parameters Description: Table: Name colums: Column name array selection: Conditional clause, Equivalent to Whereselectionargs: An array of parameters for a conditional statement groupby: Grouping having: grouping conditions Order BY: Sorting class limit: Paging query restrictions cursor: return value, Equivalent to the result set resultset for cursors (cursor) also provides a number of method method name methods that describe the GetCount () total number of record bars Isfirst () determine whether the first record islast () determines whether the last record Movetofirst () Moves to the first record movetolast () moves to the last record move (int offset) moves to the specified record MoveToNext () moves to scare a record movetoprevious () moves to the previous record Getcolumnindex (String columnName) gets the int type value of the specified column index

An explanation of the Android Qlite database

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.