我将 webdb 用于客户端,我想匹配服务器端数据库,以便可以离线使用 Web 应用程序。这是用于创建服务器端表的脚本...
USE [TESTDB]
GO
/****** Object: Table [dbo].[tblInternalMobile_SalesCalls] Script Date: 01/08/2013 11:30:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblInternalMobile_SalesCalls](
[newcall_id] [int] IDENTITY(1,1) NOT NULL,
[companyname] [varchar](30) NOT NULL,
[comment] [varchar](300) NULL,
[dateUTC] [datetime2](7) NOT NULL,
CONSTRAINT [PK_tblInternalMobile_SalesCalls] PRIMARY KEY CLUSTERED
(
[newcall_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
我试图在客户端匹配它但围绕身份我得到一个错误Uncaught Error: [object SQLError], Error Code: 5, Error Message: could not prepare statement (1 near "IDENTITY": syntax error)
这是我的客户端代码...
//Database helper
//I want to use a 'namespace' for this to minimize name conflicts
var DbHelper = {};
//use the webDb 'namespace' so we could use indexDb if need be in the future by making a new 'namespace'
DbHelper.webDb = {};
//To store the database object
DbHelper.webDb.db = null;
//Open the database
DbHelper.webDb.openDb = function() {
var dbSize = 5 * 1024 * 1024 //5MB I believe is the max
DbHelper.webDb.db = openDatabase("TestDB", "1.0", "Database manager", 5 * 1024 * 1024);
};
//If there is an error its going to throw an error, I havent added any handlers for this, so it should be added where the function is called
DbHelper.webDb.onError = function(tx, e) {
throw "Error: " + e + ", Error Code: " + e.code + ", Error Message: " + e.message;
};
//This should be used if we are doing a non query, where we dont need to use the result
DbHelper.webDb.onSuccess = function(tx, r) {
console.log("Database result: " + r)
};
//Create the tables we are going to use
DbHelper.webDb.createTables = function() {
var db = DbHelper.webDb.db;
db.transaction(function(tx) {
//I am using the same tables as I am on the server, so we dont confuse things
tx.executeSql("CREATE TABLE IF NOT EXISTS tblInternalMobile_SalesCalls(newcall_id INT PRIMARY KEY IDENTITY(1,1), companyname varchar(30), comment varchar(300), dateUTC DATETIME2)", [], DbHelper.webDb.onSuccess, DbHelper.webDb.onError);
});
}
DbHelper.webDb.init = function() {
DbHelper.webDb.openDb();
DbHelper.webDb.createTables();
}
$(document).ready(function(e) {
DbHelper.webDb.init();
});
为什么它不起作用?我相信我使用了正确的语法,显然不是。
问题是这个声明CREATE TABLE IF NOT EXISTS tblInternalMobile_SalesCalls(newcall_id INT PRIMARY KEY IDENTITY(1,1), companyname varchar(30), comment varchar(300), dateUTC DATETIME2)