SQLite--Embedded relational database 1,sqlite data type: typelessness (no type) 1, you can save any type of data to any column in the table 2, support common types such as: NULL, VARCHAR, TEXT, INTEGER, BLOB, Clob et 3, the only exception: integer primary key This field can store only 64-bit integers, that is, only 64-bit integers can be stored when the primary key is defined as Integer NOTE: Once the columns in the SQLite database are created, they cannot be modified, and if they are to be modified, the table must be recreated. Copy Data 2,android provides a Sqliteopenhelper abstract class for managing the version of the database, commonly used 3 methods: OnCreate When database is created (the first time you connect to a database and get a database object) Note: When is the database created? The database (file) is created the first time the database is connected, and OnCreate is called openhelper.getreadabledatabase (); Openhelper.getwritabledatebase (); The difference between getreadabledatabase () and Getwritabledatabase (): Look at the source code: Getreadabledatabase () usually returns Getwritabledatabase () The database that is received is only executed when an exception is thrown when the Onupgrade database update is opened as read-only (typically, the version number is modified each time the update is made) OnOpen the database is executed each time it is opened (called every time the database is opened, after the Oncreate,onupgrade method 3,android provides a sqlitedatabase class that uses this class to perform CRUD operations on data note: Unlike the JDBC Access database, the SQLite database does not need to load the driver, not get the connection, Use the Sqlitedatabase object directly to execute the SQL statement execsql (String sql) method to execute SQL statements that have changed behavior, such as INSERT, delete, update, and create table; Execsql ( The first parameter of the String SQL, object[] Bindargs method is the SQL statement, the second argument is the value of the placeholder parameter in the SQL statement, and the order of the parameter values in the array corresponds to the position of the placeholder. The Rawquery () method is used to execute a SELECT statement. The Sqlitedatabase also encapsulates insert (), delete (), updAte (), query () 4 methods, you can also manipulate the cursor is a result set cursor that is used for random access to the result set, and the cursor is the same as the ResultSet function in JDBC. Use the MoveToNext () method to move a cursor from the current row to the next row, or True if the last row of the result set has been moved and the result is returned as false. Transaction control in Sqlitedatabase: BeginTransaction () Open transaction settransactionsuccessful () Set Transaction success Token Endtransaction () End Transaction Note: Endtransaction () needs to be executed in finally, or the transaction will end automatically only when it is timed out, reducing the database concurrency efficiency
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SQLite--Embedded relational database