SQLite plays an important role in Android development, and there are many SQLite tutorials on the web, but most of those tutorials are not very comprehensive. I summed up a number of SQLite orders, by the Forum contest, to share with you.
I. Introduction to SQLite
1.SQLite Introduction
SQLite is a lightweight database, is to comply with acid's relational database management system, its design goal is embedded, and has been used in many embedded products, it occupies very low resources, in embedded devices, may only need hundreds of K of memory is enough. It can support Windows/linux/unix and so on mainstream operating system, simultaneously can with many programming language combination, for instance tcl, PHP, Java, C + +,. NET, as well as ODBC interface, but also compared to Mysql, PostgreSQL these two open source world famous database management system, it processing faster than they.
Features of 2.SQLite:
Lightweight
SQLite and C/s mode of database software is different, it is in-process database engine, so there is no database of clients and servers. Using SQLite generally only need to take a dynamic library of it, you can enjoy its full functionality. And that dynamic library size is also very small, to version 3.6.11 for example, under Windows 487KB, Linux under 347KB.
"Install" is not required
SQLite's core engine itself does not rely on Third-party software, nor does it need to be "installed" to use it. Kind of like that green software.
Single File
All the information in the database (such as tables, views, etc.) is contained within a file. This file can be freely copied to other directories or other machines.
Cross-platform/portability
In addition to the mainstream operating system Windows,linux, SQLite also supports some other infrequently used operating systems.
Weakly-typed fields
Data in the same column can be of different types
Open source
This is a!!!!!!!!!!!! that everyone knows.
3.SQLite data type
The static data type of the general data is fixed, and SQLite uses the Dynamic data type, will automatically judge according to the deposit value. SQLite has the following five commonly used data types:
Null: This value is a null value
VARCHAR (N): A string whose length is not fixed and its maximum length is n, which cannot exceed 4000.
CHAR (N): A string with a length fixed to n, and N cannot exceed 254.
Integer: Values are identified as integers and can be stored sequentially as 1,2,3,4,5,6,7,8 depending on the size of the value.
Real: All values are floating values that are stored as 8-byte IEEE floating tag numbers.
Text: The value is a literal string, using the database encoding store (TUTF-8, utf-16be or Utf-16-le).
Blob: A value is a BLOB block of data that is stored in the data format entered. How to enter on how to store, do not change formatting.
DATA: Contains the year, month, date.
Time: Contains hours, minutes, seconds.
To view the database, you must first find the DB file, if the copy to the computer, see more methods, on the phone, with the command to view more direct and convenient.
To find the location of the database, the general database is stored in the program's private directory, so get root permission.
Make sure the development tool is connected to the phone, open the command line, and enter the ADB shell
There is no root permission, input su, hand opportunity pop-up prompts, allow root permission to get
The suffix becomes "#" and the root permission is successfully obtained, which can then be entered into the application's private directory.
Enter CD data/data/package name/databases/, enter the directory of the database
Here are some basic sqlite commands
First open the database, enter Sqlite3 test_db, and open a file named test_db data.
To view the structure of the database, enter the. Schema
View some of the data
It's a bit hard to look at it, and in order to make the data appear more attractive, enter. Head on, display the column name, enter. Mode column, display by class
It looks more comfortable.
To see how many tables there are, enter. Table
View the structure of a single table. Schema tablename
The above command should be sufficient for a simple view of the database.