SQLite--Embedded relational database

Source: Internet
Author: User
Tags sqlite sqlite database access database

SQLite--Embedded relational database 1. SQLite data type: typelessness (no type) 1, can save no matter what type of data to the table in the Random column 2. Support common types such as: NULL, VARCHAR, TEXT, Integer, BLOB, CLOB, etc. 3, the only exception: integer primary key This field can only store 64-bit integers, That is, when a primary key is defined as an integer, only 64-bit integers can be stored note: Once the column in the SQLite database is created, it must be changed, the table needs to be created again, and the copy data 2,android provides a sqliteopenhelper abstract class. This class is used to manage the version number of the database and is frequently used by 3 methods: OnCreate database when it is created (the first time you connect to a database, run when you get a database object) Note: When is the database created? The database (file) is created the first time the database is connected. At this point OnCreate will be called openhelper.getreadabledatabase (); Openhelper.getwritabledatebase (); Getreadabledatabase () and Getwritabledatabase () differences: Check the Source: Getreadabledatabase () in general, the return is Getwritabledatabase () to get the database. Only run when an exception is thrown when the Onupgrade database update is opened as read-only (typically, the version number is changed every time the update is made) OnOpen the database runs every 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 be loaded to drive, not to get a connection, Run the SQL statement execsql (String sql) method directly with the Sqlitedatabase object to run 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 a SQL statement. The second parameter is the value of the placeholder parameter in the SQL statement. The order of the values in the array should correspond to the position of the placeholder. The Rawquery () method is used to run the SELECT statement. The sqlitedatabase also encapsulates the insert (), DELete (), update (), query () 4 methods. can also operate on a database cursor is a result set cursor. For random access to the result set, the cursor has the same effect as resultset in JDBC. Use the MoveToNext () method to move a cursor from the current row to the next line, assuming that the last row of the result set has been moved, and the result is false. Otherwise, true.

Transaction control in Sqlitedatabase: BeginTransaction () Open transaction settransactionsuccessful () Set Transaction success Token Endtransaction () End Transaction Note: Endtransaction () needs to be run in Finally, otherwise the transaction only has to end itself when the timeout is exceeded, which reduces the database concurrency efficiency


SQLite--Embedded relational 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.