HTML5 Web SQL

Source: Internet
Author: User

Original address: http://www.cnblogs.com/xumingxiang/archive/2012/03/25/2416418.html

Web SQL database (detail URL:http://www.w3.org/TR/2008/WD-html5-20080610/structured.html )

Web SQLdatabase: Databases API(IE and Firefox not supported)

HTML5 Database API:

OpenDatabase : Create a Database object using an existing database or creating a new database.

Transaction : Allows the user to control the transaction commit or rollback, depending on the situation.

ExecuteSQL : used to perform a real SQL query.

There are two necessary steps to writing a sqllite database using javascript scripting :

Creates an object that accesses the database.

Use transaction processing.

1. Create or open a database opendatabase

Use the opendatabase method to create an object that accesses the database.

Database OpenDatabase (in domstring name,in domstring version,in domstring displayname,in unsigned long estimatedsize,in o Ptional databasecallback Creationcallback)

OpenDatabase () method: You can open a database that already exists and create it if it does not exist.

Five parameters: Database name, version number, description, database size, and create callback.

Note: To detect whether the connection was successful.

2. Accessing and manipulating Databases transaction

Db.transction (Function (TX) {})

Transaction.executesql (Sqlquery,[],datahandler,errorhandler)

extension: After executing executesql , There is a parameter resultin the DataHandler callback function.

Result: The data set that is queried. Its data type is sqlresultset .  

The SqlResultSet is defined as:

Interface SqlResultSet {

readonly attribute long Insertid;

readonly attribute long rowsaffected;

readonly attribute sqlresultsetrowlist rows;

};

Insertid: is an insert operation that represents the first number of data inserted into a table, when inserting multiple data, returns the ordinal of the last data corresponding

Rowsaffected: Represents the number of rows affected, for example, performing an update operation and updating a data, then it is 1

rows: Returns a sqlresultsetrowlist type of data

Interface Sqlresultsetrowlist {

ReadOnly attribute unsigned long length;

[Indexgetter] Domobject item (in unsigned long index);

};

result.rows.length: Returns the number of items per line

result.rows.item (0) ["id"] or result.rows.item (0). ID; : Returns each item

HTML5 Web SQL

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.