Android Development Tutorial SQL statements (SQLite) Use the detailed

Source: Internet
Author: User
Tags sqlite

SQLite is a lightweight database that complies with acid's relational database management system and is designed to be embedded and has been used in a number of embedded products today.


Characteristics of 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 belief that we all know!

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.

It is believed that the children's shoes that have studied the database are not unfamiliar to these data types!!!!!!!!!!

First, create/delete table

The code is as follows Copy Code

String sql= "Create table" +table_name+ "(" +field_id+ "Integer primary key AutoIncrement," +field_title+ "text);";

Db.execsql (SQL);

String sql= "DROP TABLE IF EXISTS" +table_name;

Db.execsql (SQL);

Second, inquiries

Query data from a table (in) SELECT * from meta where media_id in (1,2,9);

Third, insert

The code is as follows Copy Code

Sqlitedatabase db=this.getwritabledatabase ();

Contentvalues cv=new contentvalues ();

Cv.put (Field_title, TITLE);

Long Row=db.insert (table_name, NULL, CV);

Iv. Update

The code is as follows Copy Code

Sqlitedatabase db=this.getwritabledatabase ();

String where=field_id+ "=?";

String[] wherevalue={integer.tostring (ID)};

Contentvalues cv=new contentvalues ();

Cv.put (Field_title, TITLE);

Db.update (TABLE_NAME, CV, where, wherevalue);

V. Deletion

  code is as follows copy code

Sqlitedatabase Db=this.getwritabledatabase ();

String where=field_id+ "=?";

String[] wherevalue={integer.tostring (ID)};

Db.delete (table_name, where, wherevalue);

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.