如果我有一个 javascipt 对象:
var person = new Object();
person.name = "newPerson";
person.occupation = "Programmer";
person.stateName = function(){
console.log(this.name);
};
使用基于 SQLite 的 Titanium.Database API,如何将此对象存储在单个字段中?以下工作正常:
var db = Titanium.Database.openFile(Titanium.Filesystem.getFile(
Titanium.Filesystem.getApplicationDataDirectory(),'myDatabase.db'));
db.execute("CREATE TABLE IF NOT EXISTS myTable (persons TEXT)");
然后我想将对象存储在表字段中:
db.execute("INSERT INTO myTable (persons) VALUES(?)", JSON.stringify(person));
但返回以下内容:
SQL Statement invalid or database missing
[21:55:35:300] [Titanium.Database.DB] [Error] Exception executing: INSERT INTO myTable
(person) VALUES(?), Error was: SQL Statement invalid or database missing