(Study notes) WebSQL version management

Each local SQL databases only exists a unique database name, and has a unique version number, there can be more than one version of the database
using Database.version property that returns the version number of the database, using Database.changeVersion () the method can change the version number of the database, the method has the following syntax
Database.changeVersion(oldVersion,newVersion[,callback[,errorCallback[,successCallback]]]);
parameter oldVersion current version number of the database definition, generally replaced by Database.version property
parameters newVersion new definition database version number, the version number is a string type
argument callback Alternatively, the definition of a callback function to be executed, execution of the function within SQL operations are transactions, either all succeed or fail. the callback function takes one argument, the argument is SQLtransaction objects, using the object-defined methods can perform SQL operations , syntax is as follows:
function callback(oSQLtransaction){ //执行的操作 }
parameter errcallback change the definition of a callback function version fails to perform the function takes one argument, the argument is SQLError object syntax is as follows
function errorCallback(SQLError){ //执行的操作}
callback function parameters for successCallback define actions to be executed with no parameters.
function errorCallback(SQLError){ //执行的操作}
the method often window.openDatabase () method (I.e. callback function database creation fails to be executed) after use with a parameter, and when changing the version using Database.changeVersion () method can simultaneously perform transaction operations, as follows:

//[03]==================================================================
function callback(tx){
	//可以执行tx.executeSql操作
}
function errorCallback(sqlError){
	//捕捉到SQLError
}
function successCallback(){
//执行成功
}
//[02]======================================================================
function creationCallback(database){
	database.changeVersion(database.version,"1.0",callback,errorCallback,successCallback);
}
//[01]======================================================================
var db=window.openDatabase('myDatabase","",'数据库描述信息',2*1024*1024,creationCallback);

Guess you like

Origin blog.csdn.net/qq_44858021/article/details/90051117