SQLite is an open source embedded database engine written in C language. Sql92biaozhun is supported by too many, and can be run on all major operating systems.
- Supports databases up to 2TB in size
- In the form of a single file
- stored in disk in the form of a B-TREE data structure
Characteristics:
- Lightweight a dynamic library, single file
- Independence is not dependent, installation is not required
- Isolation is all in one folder
- Multiple operating systems supported across platforms
- Multi-lingual interface supports many programming languages
- Security transactions
Security issues with Transaction handling:
- Independent transactions with exclusive and shared locks on the database
- Multiple processes can read data from the same database at the same time, but only one can write to the data
Data type of SQLite:
- NULL, Integr, REAL, text, and BLOB data types
- Null, shaped, floating-point, string value, binary value
Dynamic Data type (weak reference) 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.
Sqlitedatabase: Provides some of the classes that manage SQLite databases to provide methods for creating, deleting, executing SQL commands, and performing other common database management tasks each program's database name is unique
- Execsql (SQL)
- Insert (table,nullcolumnhack,values)
- Delete (Table,whereclause,whereargs)
- Update (Table,values,whereclause,whereargs)
- Query (Table,columns,selection,selectionargs,groupby,having,orderby)
- Rawquery (Sql,selectionargs)
Example:--------------------------------------------------------------------------------------------// Each program has its own database, under normal circumstances do not interfere with
Create a database and open
Sqlitedatabase db = Openorcreatedatabase ("User.db", mode_private, NULL);
Db.execsql ("CREATE table if not exites USERTB (_id integer primary key autoincrement,name text not null,age integer not nul L,sex text NOT NULL) ");
Db.execsql ("INSERT into USERTB (name,sex,age) VALUES (' Zhang San ', ' Male ', ' 18 ')");
Db.execsql ("INSERT into USERTB (name,sex,age) VALUES (' John Doe ', ' female ', ' 19 ')");
Db.execsql ("INSERT into USERTB (name,sex,age) VALUES (' Harry ', ' Male ', ' 20 ')");
Cursor c=db.rawquery ("Select * Form USERTB", null);
if (c!=null)
{
while (C.movetonext ())
{
LOG.I ("info", "" "+c.getint (C.getcolumnindex (" _id "));
LOG.I ("info", "" "+c.getstring (C.getcolumnindex (" name "));
LOG.I ("info", "" "+c.getint (C.getcolumnindex (" Age "));
LOG.I ("info", "" "+c.getstring (C.getcolumnindex (" Sex "));
}
C.close ();
}
Db.close ();---------------------------------------------------------------------------------------------------- -----------
Contentvalues:
- Used to store a set of values that can be contentresolver processed.
- Contentvalues value = Newcontentvalues ();
- Similar HashMap key value
- Values.put ("Key", "values");
Example:------------------------------------------------------------------------------------------------------- --------sqlitedatabase db= openorcreatedatabase ("Stu.db", mode_private, NULL);
Db.execsql ("CREATE table if not exists STUTB (_id integer primary key autoincrement,name text not null,sex text not Null,ag e integet NOT null) ");
Contentvalues values = new Contentvalues ();
Values.put ("name", "Wang Nima");
Values.put ("Sex", "male");
Values.put ("Age", 20);
Db.insert ("Stutb", null, values);
Values.clear ();
Values.put ("name", "Linima");
Values.put ("Sex", "male");
Values.put ("Age", 22);
Db.insert ("Stutb", null, values);
Values.clear ();
Values.put ("Sex", "female");
Db.update ("Stutb", Values, "_ID>?", New string[]{"0"});
Db.delete ("Stutb", "Name like", New string[]{"% King"});
Cursor c =db.query ("Stutb", NULL, "_ID>?", New string[]{"0"}, NULL, NULL, "name");
if (c!=null)
{
String []columns= c.getcolumnnames ();
while (C.movetonext ())
{
for (String columnname:columns)
{
LOG.I ("Info", C.getstring (C.getcolumnindex (ColumnName)));
}
}
}
}-------------------------------------------------------------------------------------------------------------- -----------------------------Sqliteopenhelper:
- Sqlitedatabase help class for managing database creation and version updates
- The general usage is to establish a class to inherit it, and override the OnCreate () and Onupgrade () methods
- OnCreate (Sqlitedatabase db) creates a database call,
- Inupgrade (sqlitedatabase db,int oldversion,int newversion) is called when the version is updated
- Getreadabledatabase () Create or open a read-only database
- Getwritedatabase () Create or open a read-write database
Data storage Method-sqlite