在 Cordova 的 SQLite 中,为什么会出现 "Error preparing SQLite statement" 错误?
In SQLite in Cordova, why do I get "Error preparing SQLite statement" error?
我在 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)");
});
您可以看到数据库已创建,但我在尝试添加表时出错。
您需要将事务传递给 executeSQL 调用而不是数据库。
tx.executeSql(tx, "CREATE TABLE IF NOT EXISTS nanoInst (id integer primary key, api_id integer, name text)");
我在 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)");
});
您可以看到数据库已创建,但我在尝试添加表时出错。
您需要将事务传递给 executeSQL 调用而不是数据库。
tx.executeSql(tx, "CREATE TABLE IF NOT EXISTS nanoInst (id integer primary key, api_id integer, name text)");