"Android 9" Sqlitedatabase class, Contentvalues class

Source: Internet
Author: User

Sqlitedatabase class

Instances of the Android.database.sqlite.SQLiteDatabase class represent the operation of a SQLite database, through which the Sqlitedatabase class can execute SQL statements to perform operations such as adding, modifying, deleting, and querying the data tables. , in which the basic database execution SQL statements are defined and some of the mode constants of the operations are used.

common methods of Operation

Constants or methods

Type

Describe

public static final int open_readonly

Constant

Open a database as read-only

public static final int Open_readwrite

Constant

Open a database in read/write mode

public static final int Create_if_necessary

Constant

If the specified database file does not exist, create a new

public static final int no_localized_collators

Constant

When opening a database, do not place the data in the order of the localization language

public void BeginTransaction()

Ordinary

Start a transaction

public void endtransaction()

Ordinary

End transaction, commit or rollback data

public void Close()

Ordinary

Close the database

public void execsql(String sql)

Ordinary

Execute SQL statement

public void execsql(String sql, object[] bindargs)

Ordinary

Execute the SQL statement while binding the parameters

public static sqlitedatabase OpenDatabase(

String path, sqlitedatabase.cursorfactory factory, int flags)

Ordinary

Opens the database file under the specified path in the specified mode

public static sqlitedatabase openorcreatedatabase(

File file, Sqlitedatabase.cursorfactory Factory)

Ordinary

Open or create a database under a specified path

Public long Insert(String table,

String nullcolumnhack, contentvalues values)

Ordinary

Insert data, table name, Nullcolumnhack represents incoming valuesnull, column is set to Null,values to represent all data to be inserted

Public long insertorthrow(String table,

String nullcolumnhack, contentvalues values)

Ordinary

Inserts data but throws a SqlException exception

public int Update(string table, contentvalues values,string whereclause, string[] whereargs)

Ordinary

Modify the data, table is the name of the tables, values update the data, Wherecluause indicates WHERE clause, Whereargs is the WHERE clause parameter, is used to replace "?"

public int Delete(string table, String Whereclause,

String[] Whereargs)

Ordinary

Delete data, table name, whereclause indicate WHERE clause, Whereargs as parameter, replace "?"

public boolean IsOpen()

Ordinary

Determine if the database is open

public void setversion(int version)

Ordinary

Set the version of the database

Public Cursor Query (boolean distinct, String table,

string[] columns, String selection,

String[]selectionargs,string GroupBy,

String has, string-by-clause, string limit)

Ordinary

Performs a data table query operation where the parameters are distinct (whether duplicate rows are removed), table (table name), columns (column name), selection (WHERE clause), Selectionargs (where condition), GroupBy (group), having (group filter), order by (sort), limit (limit clause)

Public Cursor Query(String table, string[] columns,

String selection, string[] Selectionargs, String groupBy,

String has, string-by-clause)

Ordinary

Perform a data table query operation

Public Cursor rawquery(String sql, string[] selectionargs)

Ordinary

Executes the specified SQL query statement

Contentvalues class

The Contentvalues class wraps the HashMap class, which is used to access data for key-value pairs, each of which represents the column name of a column and the data for that column.

Common methods

1, contentvalues ();

Function: A non-parametric construction method that creates an internal member variable that is an Hashmap<string,object> object. This member variable is named Mvalues

2, void put (String key,object value);

Function: Holds a key-value pair of data into the member variable mvalues

Hint: value can be the type of all basic data types, arrays, objects of Java

3, Object get (String key);

Function: Gets the value corresponding to the key name key.

4, XXX getasxxx (String key);

Function: Returns the value of type XXX

Tip: XXX can be a wrapper class for all basic types

"Android 9" Sqlitedatabase class, Contentvalues class

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.