我正在爲客戶端使用webdb,並且希望匹配服務器端數據庫,以便Web應用程序可以脫機使用。這這裏是創建服務器端表中的腳本...將SQL命令與數據庫匹配
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)
服務器端是mssql,所以它與webdb不一樣create table部分不是問題。 – FabianCook
那麼,「IDENTITY」附近的語法錯誤表明您的CREATE TABLE語句*是問題所在。你的客戶端數據庫是什麼? –
webdb ...我知道它是創建表。這是唯一正在執行的聲明。問題更多的是針對它有什麼問題 – FabianCook