我有一些JavaScript代码可创建3个数据库和3个表。它创建前2个表,但不创建最后1个表。这是PhoneGap / Cordova应用程序,并且在初始化第一页时运行此特定代码。成员,产品和订单数据库可以很好地创建,但是只能创建成员和产品表。不是订单表。任何帮助和建议都非常感谢。
代码如下:
var membersDatabaseHandler = {
db: null,
createDatabase: function(){
this.db = window.openDatabase(
"members.db",
"1.0",
"members database",
1000000);
this.db.transaction(
function(tx){
//Run sql here using tx
tx.executeSql(
"create table if not exists member(_id integer primary key, firstName text, lastName text, phone number)",
[],
function(tx, results){},
function(tx, error){
console.log("Error while creating the member table: " + error.message);
}
);
},
function(error){
console.log("Members DB Transaction error: " + error.message);
},
function(){
console.log("Create Members DB transaction completed successfully");
}
);
}
}
var productsDatabaseHandler = {
db: null,
createDatabase: function(){
this.db = window.openDatabase(
"products.db",
"1.0",
"products database",
1000000);
this.db.transaction(
function(tx){
//Run sql here using tx
tx.executeSql(
"create table if not exists product(_id integer primary key, name text, price number, image text)",
[],
function(tx, results){},
function(tx, error){
console.log("Error while creating the product table: " + error.message);
}
);
},
function(error){
console.log("Products DB Transaction error: " + error.message);
},
function(){
console.log("Create Products DB transaction completed successfully");
}
);
}
}
var ordersDatabaseHandler = {
db: null,
createDatabase: function(){
this.db = window.openDatabase(
"orders.db",
"1.0",
"orders database",
1000000);
this.db.transaction(
function(tx){
//Run sql here using tx
tx.executeSql(
"create table if not exists order(_id integer primary key, memberID number, name text, price number, items text)",
[],
function(tx, results){},
function(tx, error){
console.log("Error while creating the order table: " + error.message);
}
);
},
function(error){
console.log("Orders DB Transaction error: " + error.message);
},
function(){
console.log("Create Orders DB transaction completed successfully");
}
);
}
}
我明显缺少什么吗?
谢谢