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 ){});
});