Android-sqlite User Manual

Source: Internet
Author: User
Tags sqlite database sqlite tutorial

sqlite3 User manual View Database VersionSqlite3-version
Open or create a databaseSqlite3DatabaseName.DB
View database file information. Database
View database Tables. Table
exit SQLite . Quit or. Exit
list configurations for the current display format. Show
Show database structure/ show the structure of a table. Schema          .Schema table name
Set delimiter . Separator separators
Show title bar. Headers    on/off
Setting the display mode . mode
Set a NULL value display style . Nullvalue
SQLite Simple Syntax set up a data tableCREATE TABLE table_name (field Type1,fieldtype1,....);table_name is the name of the data table to create, field X is the name of the fields in the database table, and Typex is the field type.
adding data recordsINSERT INTO table_name (column field1,field2,....) VALUES (value Val1,val2,....); For example, add data to the Teacher information table:
Modifying DataUpdate table Set column = ' new value ' [WHERE Condition statement]
Delete DataDelete from table [WHERE condition statement]If you setwherea conditional clause deletes a data record that meets the criteria, or deletes all records if no conditional statement is set.           
Modifying DataUpdate table Set column = ' new value ' [WHERE Condition statement]Updatestatement is used to update a column in a table, and if you do not set a condition, the column for all records is updated, and if the condition is set, the column that meets the criteria is updated .whereclauses are used to set conditions, as in the following example :
Delete DataDelete from table [WHERE condition statement]If you setwherea conditional clause deletes a data record that meets the criteria, or deletes all records if no conditional statement is set.
Querying data recordsquery output lists data records (SELECT * from table_name;)limit the number of output data records (SELECT * FROM table_name limit Val;)output data record in ascending order (SELECT * FROM table_name order BY field ASC;)Descending output data record (SELECT * FROM table order BY field Desc;)Conditional Query (SELECT * from table_name where expression;)                         (SELECT * FROM table_name where field in (' Val1 ', ' val2 ', ' val3 ');)                         (SELECT * FROM table_name where fieldbetween val1 and val2;)number of query records (SELECT COUNT (*) from table_name;)
Delete a data tableDROP table table_name;
Android Coding Manual Creating auxiliary ClassesPublic classDatabasehelperextendsSqliteopenhelper {
private static FinalString name="Count"; //Database name
    private static final int version=1; //Database version
    PublicDatabasehelper (Context context) {
Super(Context,  name, NULL, version);
   }

@Override
    Public voidonCreate(Sqlitedatabase db) {
Db.execsql ("CREATE TABLE IF not EXISTS person (PersonID Integer primary key autoincrement, name varchar (), age integer)");
   }

@Override
    Public voidOnupgrade(Sqlitedatabase DB, intOldversion, intNewVersion) {
Db.execsql ("ALTER TABLE person ADD phone VARCHAR"); //Add a column to the table
   }
}

Inserting Data     Sqlitedatabase db = Databasehelper. (Mcontext,1). Getwritabledatabase ();
Db.execsql (insert into book (name, author, pages, price) VALUES (?,?,?,?) ", new string[] {"The Da Vinci Code", "Dan Brown", "454", "16.96" });
Db.execsql (insert into book (name, author, pages, price) VALUES (?,?,?,?) ", new string[] {"The Lost Symbol", "Dan Brown", "510", "19.95" });
Db.close ();

Delete DataSqlitedatabase db = Databasehelper. (Mcontext, 1). Getwritabledatabase ();
Db.execsql ("Delete from book where pages >?", NewString[] {"a"});
Db.close ();

Update DataSqlitedatabase db = Databasehelper. (Mcontext, 1). Getwritabledatabase ();
Db.execsql ("Update book Set price =?" WHERE name =? ", NewString[] {"10.99",
"The Da Vinci Code"});
Db.close ();

Querying DataSqlitedatabase Db=databasehelper. (Mcontext,1). Getreadabledatabase ();
Cursor Cursor=db.rawquery ("SELECT * from book", NULL);
//Jump to the beginning of the pointer
if(Cursor.movetofirst ()) {
Do{
Get Data
/* cursor.getstring (Cursor.getcolumnindex ("Isremind")) */
   } while(Cursor.movetonext ());
}
Db.close ();
 
ReferenceIntroduction: "First line Code"--6.4---SQLite database Storage SQLite Tutorial: http://www.runoob.com/sqlite/sqlite-tutorial.html

Android-sqlite User Manual

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.