Android---notoginseng---sqlitedatabase

Source: Internet
Author: User

Android provides sqldatabase to represent a database (the underlying is a database file)


The static method opens a database for the file that corresponds to:


Static Sqlitedatabase OpenDatabase (String path,sqlitedatabase.cursor Factory Factory, int flags)


Open the SQL database represented by the path file.


Static Sqlitedatabase openorcreatedatabase (File file,sqlitedatabase.cursor Factory Factory)


Open or create (if not present) the SQL database that the file represents


Static Sqlitedatabase openorcreatedatabase (String path,sqlitedatabase.cursor Factory Factory)


Open or create (if not present) the SQL database that path represents


Once you have obtained the Sqlitedatabase object, you can manipulate the database by:


Execsql (String sql,object[] bindargs): Execute SQL statement with placeholders


Execsql (String SQL): Execute SQL statement


Insert (string table, String nullcolumnhack, contentvalues values): Inserting data into the execution table


Update (string table, contentvalues values, String whereclause, string[] whereargs): Update specific data in the specified table


Delete (Strig table, String whereclause, string[] whereargs): Deletes specific data from the specified table


Cursor Query (string table, string[] columns string whereclause,string[] whereargs,string groupBy, string having,string or DerBy):
Querying the Execution data table


Cursor Query (String table, string[] columns,string whereclause, string[] whereargs,string gruopby,string having,string o Rderby,string limit):
To execute a query against the Execution data table, the limit parameter controls up to several records.


Cursor Query (Boolean distinct,string table,string[] columns, String whereclause,string[] whereargs,string groupBy, String having, string orderby,string limit):
Executes a query statement on the specified table, where the first parameter controls whether duplicate values are removed.


Rawquery (String sql, string[] selectionargs): Execute SQL query with placeholders
BeginTransaction (): Start transaction
Endtransaction (): End transaction




The cursor provides the following ways to move the record pointer of the query result:


Move (int offset): Moves the record pointer up or down by the specified number of rows. Offset is a positive number is the downward movement, negative is the upward
Boolean Movetofirst (): Moves the record pointer to the first row and returns true if the move succeeds
Boolean movetolast (): Moves the record pointer to the last row, moves successfully, returns true
Boolean MoveToNext (): Moves the record pointer to the next row, moves successfully, returns true
Boolean movetoposition (int position): Moves the record pointer to the specified row, moves successfully, and returns True.
Boolean movetoprevious (): Moves the record pointer to the previous row, moves successfully, and returns True.




/************************************/
Create a database:
Sqlitedatabase.openorcreatedatabase ("/MNT/DB/TEMP.DB3", null);




Open or create a database, if the/mn/db/directory temp.db3 file exists, then the program is to open the database, if it does not exist in this directory will create temp.db3 file.


To build a table statement:
String sql = "CREATE table person (_id integer priimary key,name varchar (+), age integer)";
Call Db.execsql (SQL);




Insert:
INSERT into person (name, age) VALUES (' Zhangsan ', 20);
Insert into person (name,age) VALUES ('?,? '); New object[] {person.getname (), Person.getage ()};


Delete:


Delete from person where_id = 1;


Modify:
Update person Set name = ' John Doe ' WHERE name = ' Harry '


Inquire:


SELECT * from person;//query all---> cursor result sets


SELECT * FROM person where name= ' zhangsan '//Query single




Use a specific method to manipulate the database:


Inserting insert:


Long Insert (string table, String nullcolumnhack, contentvalues values):
Table: Represents the names of the tables for which you want to insert data
Nummcolumnhack: Represents the column name for forcibly inserting null worth data columns. This argument is valid when the values parameter is NULL or does not contain any key-value pairs
Values: Represents the data for a row of records.
Returns the line number of the newly added record.


Updating update:


Update (string table, contentvalues values, String whereclause, string[] whereargs)
Table: Represents the names of tables for which you want to update data
Values: Represents the data you want to update
Whereclause: The record that satisfies the sentence will be updated
Whereargs: Used to pass parameters for Whereclause


Returns the number of records affected by this method.




Remove Delete:
Delete (string table, string whereclause,string[] Whereargs):
The method returns the number of records affected by this method.


Querying query:


Cursor query (boolean distinct, string table, string[] columns, string[] selection, string[] Selectionargs, String groupBy , string has, string-by-clause, string limit);


Distinct: Specifies whether duplicate records are removed
Table: The names of the tables that execute the query data
Columns: The column name to query out
Selection: Query criteria
Selectionargs: Used to pass parameters for selection
GroupBy: for controlling grouping
Having: Used to filter groups
ORDER BY: Used to sort records
Limit: Used for paging.

Android---notoginseng---sqlitedatabase

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.