JS Local Storage: Local Database Storage JS class
Last Update:2017-02-28
Source: Internet
Author: User
JS calls local database main JS file
var HD = {
Is_db:null,
Uid:null,
Ukey:null,
ShortName: ' HD ',
Version: ' 1.0 ',
DisplayName: ' hd_2345 ',
maxsize:100000,
Data:null,
Other:null,
Login:null,
Index:null,
Creating a Database
Initdatabase:function () {
try {
if (!window.opendatabase) {
Alert (' Databases are not supported in this browser. ');
} else {
Demodb = OpenDatabase (This.shortname, This.version,
This.displayname, this.maxsize);
This.createusertable ();
This.createmywebsite ();
This.createmyapp ();
This.createcitysite ();
This.createmyfenlei ();
}
catch (e) {
if (E = = 2) {
Version number mismatch.
} else {
}
Return
}
},
Createusertable:function () {
Demodb
. Transaction (function (transaction) {
var sql = "CREATE TABLE IF not EXISTS hd_users" ("
+ "id INTEGER not NULL PRIMARY KEY AutoIncrement,"
+ "UID integer not null,passid integer not null,uname text not null,ukey text not NULL,"
+ "Uemail text null,city text NULL)";
Transaction.executesql (sql, [], Hd.nulldatahandler,
Hd.errorhandler);
});
},
Createmywebsite:function () {
Demodb.transaction (function (transaction) {
var sql = "CREATE TABLE IF not EXISTS hd_users_website" ("
+ "id INTEGER not NULL PRIMARY KEY AutoIncrement,"
+ "UID INTEGER not null,content TEXT NULL";
Transaction
. ExecuteSQL (sql, [], Hd.nulldatahandler, Hd.errorhandler);
});
},
Createmyapp:function () {
Demodb.transaction (function (transaction) {
var sql = "CREATE TABLE IF not EXISTS Hd_users_app" ("
+ "id INTEGER not NULL PRIMARY KEY AutoIncrement,"
+ "UID INTEGER not null,content TEXT NULL";
Transaction
. ExecuteSQL (sql, [], Hd.nulldatahandler, Hd.errorhandler);
});
},
Createmyfenlei:function () {
Demodb.transaction (function (transaction) {
var sql = "CREATE TABLE IF not EXISTS hd_users_fenlei" ("
+ "id INTEGER not NULL PRIMARY KEY AutoIncrement,"
+ "UID INTEGER not null,content TEXT NULL";
Transaction
. ExecuteSQL (sql, [], Hd.nulldatahandler, Hd.errorhandler);
});
},
Createcitysite:function () {
Demodb.transaction (function (transaction) {
var sql = "CREATE TABLE IF not EXISTS hd_city_site" ("
+ "id INTEGER not NULL PRIMARY KEY AutoIncrement,"
+ "UID INTEGER null,content TEXT NULL";
Transaction
. ExecuteSQL (sql, [], Hd.nulldatahandler, Hd.errorhandler);
});
},
Errorhandler:function (transaction, error) {
Error is a human-readable string.
return false;
},
Nulldatahandler:function () {
},
Insert:function (data, table_name) {
Demodb.transaction (function (transaction) {
var sql_addsub_name = ';
var sql_add_var_name = "";
For (var k in data) {
Sql_addsub_name + = "" + k + "',";
Sql_add_var_name + = "'" + data[k] + "',"; This article links http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20130716/39101.html