在Cordova的SQLite中,为什么我会收到“错误准备SQLite语句”错误?

时间:2015-06-01 06:18:41

标签: sqlite cordova windows-8

我正在使用Visual Studio 2015中的Windows 8 Cordova应用程序。现在我只是尝试测试创建表格,但是我收到了错误。

以下是我在控制台日志中的内容:

adding proxy for SQLitePlugin
OPEN database: nanoDB.db
db name: nanoDB.db at full path: .[...]
new transaction is waiting for open operation
DB opened: nanoDB.db
sql exception error: Error preparing an SQLite statement.
sql exception error: Error preparing an SQLite statement.
sql exception error: Error preparing an SQLite statement.
sql exception error: Error preparing an SQLite statement.
sql exception error: Error preparing an SQLite statement.
sql exception error: Error preparing an SQLite statement.
sql exception error: Error preparing an SQLite statement.

这是我在“deviceready”监听器之后运行的脚本:

var nanoDB = window.sqlitePlugin.openDatabase({ name: "nanoDB.db" })

nanoDB.transaction(function (tx) {

    tx.executeSql(nanoDB, "CREATE TABLE IF NOT EXISTS nanoInst (id integer primary key, api_id integer, name text)");
    tx.executeSql(nanoDB, "CREATE TABLE IF NOT EXISTS nonoProd (id integer primary key, api_id integer, name text)");
    tx.executeSql(nanoDB, "CREATE TABLE IF NOT EXISTS nanoInd (id integer primary key, api_id integer, name text)");
    tx.executeSql(nanoDB, "CREATE TABLE IF NOT EXISTS nanoFiles (id integer primary key, api_id integer, name text, fileType text, fileLoc text)");
    tx.executeSql(nanoDB, "CREATE TABLE IF NOT EXISTS nanoRelProd (id integer primary key, inst_id integer, prod_id integer)");
    tx.executeSql(nanoDB, "CREATE TABLE IF NOT EXISTS nanoRelInd (id integer primary key, inst_id integer, ind_id integer)");
    tx.executeSql(nanoDB, "CREATE TABLE IF NOT EXISTS nanoRelFiles (id integer primary key, inst_id integer, file_id integer)");
});

您可以看到数据库已创建但我在尝试添加表时出错。

1 个答案:

答案 0 :(得分:0)

您需要将事务传递给executeSQL调用而不是DB。

tx.executeSql(tx," CREATE TABLE IF NOT NOT EXISTS nanoInst(id integer primary key,api_id integer,name text)");