JS Local Storage: Local Database Storage JS class

Source: Internet
Author: User
Tags integer key sql return version ukey

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

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.