問題描述
以下 SQL 代碼在 SQLite 管理器和其他 SQLite 系統中運行良好,但是當我在 Titanium 中使用它時,我得到一個Uncaught SyntaxError: Unexpected String".如果我的語法錯誤,應該如何為 Titanium 編碼?
The following SQL code works fine in SQLite Manager and in other SQLite systems, however when I use it in Titanium I get an "Uncaught SyntaxError: Unexpected String." If my syntax is wrong, how should it be coded for Titanium?
SELECT Date, Content
FROM MYDATABASE
WHERE strftime('%m%d', Date) = strftime('%m%d', date('now'))
推薦答案
您是否將您的表稱為 MYDATABASE?您是否正在逐步調試調試器并確認 var rs = db.execute("SELECT Date, Content FROM MYDATABASE WHERE strftime('%m%d', date) = strftime('%m%d', date('現在'))");
Did you call your table MYDATABASE? Are you stepping through the debugger and confirming that var rs = db.execute("SELECT Date, Content FROM MYDATABASE WHERE strftime('%m%d', date) = strftime('%m%d', date('now')) ");
在我的 Titanium Mobile 項目中,我首先定義了數據庫:
In my Titanium Mobile project I first defined the database:
var db = Ti.Database.open('myDb');
db.execute('CREATE TABLE IF NOT EXISTS [MYDATABASE](id INTEGER PRIMARY KEY AUTOINCREMENT, Date DATE, Content TEXT)');
db.close();
然后我從函數調用中執行了這段代碼
I then executed this code from a function call
var db = Ti.Database.open('myDb');
var myresult = db.execute("INSERT INTO MYDATABASE(Date, Content) VALUES (date('now'), '12345')");
myresult = db.execute("SELECT Date, Content FROM MYDATABASE WHERE strftime('%m%d', Date) = strftime('%m%s', date('now')) ");
Ti.API.info('myresult: ' + myresult.fieldByName('Content'));
此代碼在調試窗口中成功返回 myresult: 12345.您可能需要向我們提供源代碼的重要部分,以便我們可以看到代碼的流程.給我們碎片是行不通的.
This code returns myresult: 12345 in the debug window successfully for me. You probably need to provide us with a significant part of the source code so we can see the flow of the code. Giving us pieces isn't working.
不幸的是,我不得不在另一臺計算機上進行測試,希望在這里重新輸入不會出錯"
Unfortunately, I had to test this from another computer and hopefully didn't make any errors re-typing it here"
這篇關于SQLite Titanium 語法錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!