Introduction to the use of SQLite based on Android _android

Source: Internet
Author: User
Tags sqlite

In the Android platform, an embedded relational database is integrated--SQLite, it supportsNull、INTEGER、Real(floating-point numbers),TEXT(string literals) andBlob(binary object) data types, although only five types of data are supported, you can actually accept data types such as varchar (n), char (n), decimal (P,s), and convert to the corresponding five data types when you perform operations or save.
ex: You can hold a string in an integer-type field, or hold a floating-point number in a Boolean type field, or hold a date in a character field, but! a field defined as Integer PRIMARY key can store only 64-bit integers, and in addition to writing the Create Table statement, you can omit the data type following the field name;
CREATE table person (PersonID integer PRIMARY key autoincrement,name varchar (20))// The type of name can be omitted, and the
Select * FROM tablename where Tiaojian GROUP by groups has ... order by sort words
Select * FROM person
Sel ECT * FROM person ORDER by ID desc/asc the
Select name from person group by name has a count (*) >1
Page: SELECT * from A Ccount Limit 5 Offset 3 or select * from account limit3,5
INSERT statement: INSERT INTO TableName (field list) VALUES (value list)
&nb Sp;insert into person (name,age) VALUES ("Livingstone")
UPDATE statement: UPDATE tablename set Field1=val1,field2=val2 Where condition statement
 update person set name= "Livingstone" where id = ten
DELETE statement: Delete from TableName WHERE condition statement br>  delete from where id=10
gets the ID value that grew since the record was added: Select Last_insert_rowid () span>


Sqlitedatabase specifically provides actions for adding, deleting, updating, querying: Insert (), delete (), update (), and query ().

The Insert () method is used to add data, the data for each field is stored using contentvalues, Contentvalues is similar to map, and it provides a put (String key,xxx value) corresponding to the access data relative to the map. and getasxxx (String key) method;
Long rowid=db. Insert ("person", null,values);//Returns the line number of the newly added record, regardless of the primary key ID;
Regardless of whether the third parameter contains data, the insert () method must add a record, and if the third argument is empty, add a single key other than the primary
Records with other field values that are null, the Insert () method internally actually completes the addition of the data by constructing the SQL statement, and the second parameter specifies the name of the null field: If the third parameter values are null or the number of elements is 0, because the insert () method requires that a record be added with a NULL value other than the primary key, in order to satisfy the SQL syntax requirement, the INSERT statement must be given a field name, Ex:insert into person (name) values (NULL), and if the field name is not given, The INSERT statement is: INSERT into person () values (), and for field names, it is recommended that you use a field other than the primary key, if you use an integer type of primary key field, perform a similar insert into person (PersonID) VALUES (NULL) INSERT statement, the primary key field value is also not NULL, if the third argument values are not null and the number of elements is greater than 0, the second argument is set to null.

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.