【发布时间】:2017-02-09 19:52:03
【问题描述】:
我正在使用带有 SQLite 的 Ionic2,我有以下内容:
app.ts
private createDatabase(): void {
let db: SQLite = new SQLite();
db.openDatabase({
name: "data.db",
location: "default"
}).then(() => {
db.executeSql("CREATE TABLE IF NOT EXISTS chats (_id TEXT PRIMARY KEY, memberIds TEXT, title TEXT, subTitle TEXT, picture TEXT, lastMessageId TEXT, lastMessageCreatedAt DATE)", {}).then((chatData) => {
console.log("chats TABLE CREATED: ", chatData);
db.executeSql("CREATE TABLE IF NOT EXISTS messages (_id TEXT PRIMARY KEY, chatId TEXT, senderId TEXT, ownership TEXT, content TEXT, createdAt DATE, changeDate BOOLEAN, readByReceiver BOOLEAN)", {}).then((messageData) => {
console.log("messages TABLE CREATED: ", messageData);
}, (error) => {
console.error("Unable to execute messages sql", error);
});
}, (error) => {
console.error("Unable to execute chats sql", error);
});
}, (error) => {
console.error("Unable to open database", error);
});
}
}
storageService.ts
console.log('addMessage: chat '+chat._id);
this.database.executeSql("SELECT * FROM chats where _id = " + chat._id, []).then((data) => {
let chats = [];
if (data.rows.length > 0) {
for (var i = 0; i < data.rows.length; i++) {
this.chats.push({
_id: data.rows.item(i)._id
});
}
}
console.log('addMessage: chats.length = ' + chats.length);
输出
addMessage: chat rSkFGaLgQ554FCCYJ ERROR: {"message":"sqlite3_prepare_v2 failure: no such column: rSkFGaLgQ554FCCYJ","code":0}
问题
你知道我为什么会收到错误吗?据我所知,错误所指的列是_id,但在我创建数据库时它确实存在。
【问题讨论】: