SQLite 查询有超过 1 行但不断抛出异常 - Angular、Ionic、Android
SQLite Query has more than 1 row but keeps throwing exceptions - Angular, Ionic, Android
我有一个 Ionic Angular 应用程序(Android 构建)
我有以下内容:
getAllUsers() {
return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`)
.then((data) => {
if (data.rows.length > 0) {
for (let i = 0; i < data.rows.length; i++) {
console.log('hello world');
console.log(JSON.stringify(data.rows.item(i)));
}
}
}).catch(e => {
console.log(JSON.stringify(e));
});
}
当我调用 getAllUsers 时,会自动抛出一个异常,并在 android studio
中使用以下控制台登录
2021-12-30 17:50:32.831 25077-25077/io.ionic.starter I/Capacitor/Console: File: http://localhost/src_app_login_login_module_ts.js - Line 421 - Msg: {"rows":{"length":3},"rowsAffected":0}
这是来自控制台的查询日志:
2021-12-30 17:50:32.815 25077-25292/io.ionic.starter V/Capacitor/Plugin: To native (Cordova plugin): callbackId: SQLitePlugin1622878251, service: SQLitePlugin, action: backgroundExecuteSqlBatch, actionArgs: [{"dbargs":{"dbname":"userParameters.db"},"executes":[{"sql":"SELECT 1","params":[]},{"sql":"SELECT * from userParametersTable","params":[]}]}]
我想知道为什么会出现这种行为以及如何解决这个问题。
谢谢
问题是我需要包含参数(以前是可选的,如下所示:
return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`, [])
而不是
return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`)
我有一个 Ionic Angular 应用程序(Android 构建)
我有以下内容:
getAllUsers() {
return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`)
.then((data) => {
if (data.rows.length > 0) {
for (let i = 0; i < data.rows.length; i++) {
console.log('hello world');
console.log(JSON.stringify(data.rows.item(i)));
}
}
}).catch(e => {
console.log(JSON.stringify(e));
});
}
当我调用 getAllUsers 时,会自动抛出一个异常,并在 android studio
中使用以下控制台登录2021-12-30 17:50:32.831 25077-25077/io.ionic.starter I/Capacitor/Console: File: http://localhost/src_app_login_login_module_ts.js - Line 421 - Msg: {"rows":{"length":3},"rowsAffected":0}
这是来自控制台的查询日志:
2021-12-30 17:50:32.815 25077-25292/io.ionic.starter V/Capacitor/Plugin: To native (Cordova plugin): callbackId: SQLitePlugin1622878251, service: SQLitePlugin, action: backgroundExecuteSqlBatch, actionArgs: [{"dbargs":{"dbname":"userParameters.db"},"executes":[{"sql":"SELECT 1","params":[]},{"sql":"SELECT * from userParametersTable","params":[]}]}]
我想知道为什么会出现这种行为以及如何解决这个问题。
谢谢
问题是我需要包含参数(以前是可选的,如下所示:
return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`, [])
而不是
return this.dbInstance.executeSql(`SELECT * from ${this.db_table}`)