通过GUI将日期输入到数据库中,以便FMDatabase读取日期 [英] Date entry into database through GUI for Date which is readable by FMDatabase
问题描述
我有一系列事件,在我发布应用程序之前,必须将这些事件提供给数据库,以便应用程序可以从该数据库中读取数据。
I have a set of events which I will have to feed into the database before I ship the app so that the application is ready to read from this database.
我看到了一些类似的文章,这些文章解释了如何将NSDate输入数据库,以便可以将其读回:
I have seen some posts like these which explain how to enter NSDate into database so that it can be read back:
- iPhone SQLite date problem
- Persisting Dates to SQLite3 in an iPhone Application
现在,我想通过运行以下查询将日期输入数据库:
Now, I want to entry dates into the database by running queries like:
insert into VendorEvents (event_start, event_end, notes, event_name) values (date('2012-01-26'), date('2012-01-26'), 'Republic day of India is the day when our constitution was framed and put into practice', 'Republic day')
当我运行此程序时通过MesaSQLite应用程序进行查询,返回的结果是理想的:
When I run this query through MesaSQLite application, the returned results are perfect as expected:
select * from VendorEvents where ((event_start between '2011-12-01 00:00:00 +0000' and '2012-02-01 00:00:00 +0000') or (event_end between '2011-12-01 00:00:00 +0000' and '2012-02-01 00:00:00 +0000'))
但是当我通过FMDatabase运行相同的查询时
But when I run the same query through FMDatabase inside the application, no records are returned.
我数据库中VendorEvents中第一个字段和第二个字段的数据类型为日期。我输入数据的唯一区别是使用MesaSQLite应用程序。那么,由于没有在FMDatabase中得到结果,我可能会犯任何错误吗?
The datatype of the first and second field in VendorEvents in my database is of type "Date". The only difference in the way I am entering the data is by using MesaSQLite application. So, is there any mistake I might be doing due to which I am not getting the results in FMDatabase?
谢谢,
Raj
Thanks, Raj
推荐答案
使用 date()
函数。试试看:
select * from VendorEvents
where ((event_start between date('2011-12-01 00:00:00 +0000') and date('2012-02-01 00:00:00 +0000'))
or (event_end between date('2011-12-01 00:00:00 +0000') and date('2012-02-01 00:00:00 +0000')))
这篇关于通过GUI将日期输入到数据库中,以便FMDatabase读取日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!