问题
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'))
回答1:
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')) ");
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'));
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"
来源:https://stackoverflow.com/questions/11516419/sqlite-titanium-syntax-error