HTML5 study notes, html5

Source: Internet
Author: User

HTML5 study notes, html5

Google has supported Web SQL Database through SQLite in Chrome

Interface Description:

1. Open a database:

Var db = openDatabase ('mydb', '1. 0', 'test', 2*1024*1024, function (db ){});

Parameter description: Database Name (mydb) | version (1.0) | database description (test) | database size (2*1024*1024) | create callback

2. After the database is created, you can perform SQL query and update operations.

Obtain a transaction connection before executing the SQL statement.

Db. transaction (function (tx ){

// Execute the SQL statement in the connected callback function

Tx.exe cuteSql ('create table if not exists sets (key unique, value )');

});

Tx.exe cuteSql function description:

List of parameters: SQL statement | value ([]) | successful callback function | failed callback function

Example:

Db. transaction (function (tx ){

// Create

Tx.exe cuteSql ('create table if not exists sets (key unique, value )');

// Insert

Tx.exe cuteSql ('insert into sets (key, value) VALUES (?, ?) ', [1, 'asdf'], function (tx, result) {}, function (tx, error ){});

// Query

Tx.exe cuteSql ('select * from sets', [], function (tx, result ){

Var len = result. rows. length;

Var item = result. rows. item (len-1 );

Var key = item ['key'];

}, Function (tx, error ){});

// Modify

Tx.exe cuteSql ('Update sets set value =? WHERE key =? ', ['Hahaha', 1], function (tx, result) {}, function (tx, error ){});

// Delete

Tx.exe cuteSql ('delete from sets', [], function (tx, result) {}, function (tx, error ){});

});

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.