iphone - 插入命令错误 - Appcelerator Titanium

标签 iphone ios sqlite appcelerator titanium-mobile

我是 Appcelerator Titanium 的新手。我已经成功创建了数据库。当我尝试插入一条记录时,它显示错误,

[ERROR] Script Error = Error occurred calling next on a PLSqliteResultSet. 
SQLite error: 'constraint failed' for 'INSERT INTO test (t_Id, t_Name)
VALUES (1,"sam")')' at app.js (line 24).

我的代码是:

Ti.Database.install('myDB.sqlite','myDB'); 
var db = Ti.Database.open('myDB'); 
db.execute('INSERT INTO test (t_Id, t_Name) VALUES (1,"sam")');

请帮帮我!!

最佳答案

像这样做。

db.execute('INSERT INTO credentials(username,password,token) VALUES(?,?,?)',username,password,token);

这是添加动态值。 username password 和 token 是这里的变量。

关于iphone - 插入命令错误 - Appcelerator Titanium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14560848/

相关文章:

ios - 具有多个 NSDateFormatter 的 Swift 代码 - 优化

objective-c - 将一个 iOS Storyboard 项目包含到另一个项目中?

android - 检查 android sqlite 和 IntelliJ

Android 删除 SQLite 表

iphone - CALayer 与 drawInRect : performance?

iphone - 使用 iPhone 相机的点云

ios - react-native:推送通知+解析

ios - 如何在 iphone sdk 中获取 Vfr Reader for Pdf 的目录?

iphone - 停用 UIScrollView 减速

SQLite - 替换字符串的一部分