SQLite Titanium 语法错误[英] SQLite Titanium Syntax Error

本文是小编为大家收集整理的关于SQLite Titanium 语法错误的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

以下SQL代码在SQLITE管理器中和其他SQLITE系统中工作正常,但是当我在钛中使用它时,我得到一个"未捕获的语法error:意外的字符串".如果我的语法错误,那么它应该如何为钛进行编码?

    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('now')) ");

在我的钛移动项目中我第一次定义了数据库:

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();

我从函数调用中执行此代码

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在调试窗口中成功返回给我.您可能需要为我们提供源代码的重要部分,因此我们可以看到代码的流程.给我们的碎片不起作用.

不幸的是,我不得不从另一台计算机测试这一点,希望没有任何错误在这里重新打字"

本文地址:https://www.itbaoku.cn/post/1938202.html

问题描述

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')) 

推荐答案

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"