(2) HTML5 and html5

Source: Internet
Author: User

(2) HTML5 and html5
Introduction

Web SQL Database is the local SQLite Database. The method and method are basically the same as those of SQLite.

Determine whether the browser supports
if (!window.openDatabase) {      alert('Databases are not supported in this browser.');  } 
OpenDatabase

Open or create a database. The openDatabase method uses an existing database or creates a new database to create a database object.

OpenDatabase (DbName, DBVersion, DBDescribe, DBSize, Callback ());

1 db=openDatabase('Student','1.0','StuManage',2*1024*1024,function(){2     console.log('create db success');3 });

 

Transaction executes transaction processing through the transaction method in the database object. Each transaction processing request is used as an independent database operation, which effectively avoids conflicts during data processing. Syntax: transaction (TransCallback, ErrorCallback, SuccessCallback); execute SQL
1 db.transaction(function(tx) { 2     tx.executeSql("CREATE TABLE IF NOT EXISTS test (id int UNIQUE, title TEXT, content TEXT)"); 3 }); 

 

Execute real SQL queries.

ExecuteSql (strSQL, [arguments], SuccessCallback, ErrorCallback); parameters are the statements to be executed, the required real parameters, the success callback function, and the Failure callback function.
// Create a data Table test db. transaction (function (tx) {tx.exe cuteSql ("create table if not exists test (id int UNIQUE, title TEXT, content TEXT)") ;}); // execute add db. transaction (function (tx) {tx.exe cuteSql ("create table test (id, title)"); tx.exe cuteSql ("insert into test values (1, 'ali1 ')"); tx.exe cuteSql ("insert into test values (2, 'ali2', 'test')") ;}); // execute the query database. transaction (function (tx) {tx.exe cuteSql ("select * from test", [], function (tx, result) {for (var I = 0; I <result. rows. length; I ++) {var testObj = result. rows. item (I); alert (testObj. id + "------" + testObj. title );}});});

 

 

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.