【发布时间】:2016-09-29 22:33:15
【问题描述】:
我正在使用 Ionic 和 Cordova SQLite 开发应用程序。如果数据不存在于 sqlite 但如果数据存在于 sqlite 中,则应用程序将数据插入到 sqlite。然后,应用程序正在替换旧数据。以下是我的代码。但是我无法将数据插入到 sqlite 数据库中。
创建数据库
db = window.openDatabase("chatChannel.db", "1", "Demo SQLite Test", "2000");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chat_channel(id interger primary key, channel_name text unique, last_text text)")
插入数据
var query = "INSERT INTO chat_channel (channel_name, last_text) VALUES(?,?) ON DUPLICATE KEY UPDATE (last_text) VALUES (?)";
$cordovaSQLite.execute(db, query, [channel, $scope.messageContent], [$scope.messageContent]);
如果sqlite数据库中不存在记录,我可以知道如何将数据插入cordova sqlite,如果数据库中存在数据,我可以更新数据。
【问题讨论】: