Sqlite Select Query在android中给出了错误的结果?

时间:2014-07-15 06:35:47

标签: android android-sqlite select-query

我想从sqlite数据库中选择图像和视频我实现了我的查询但是它给了我错误的结果我当前的日期是2014-07-15但是它提供了我的2014-07-25日期结果是错误的。

我的查询:

SELECT * 
FROM myfiles 
WHERE (( Date('2014-07-15') >= startdate 
AND Date('2014-07-15') <= enddate ) 
AND ( strftime('%H:%M:%S', starttime) >= '02:09:50' 
OR  '02:09:50'  <= strftime('%H:%M:%S', endtime )) 
AND ( strftime('%H:%M:%S',timer_from) >= '02:09:50' 
OR '02:09:50' <= strftime('%H:%M:%S',timer_to )) 
OR ( strftime('%H:%M:%S',timer_from) = '00:00:00' 
OR '00:00:00' = strftime('%H:%M:%S',timer_to ))) 
AND ( Tuesday = 1 OR Everyday = 1) 
AND download = 1 
AND playlist_id = 65 
AND user_id='265' 
ORDER BY position_id ASC, subposition_id ASC 

- &GT;链接下载此图片 http://screencast.com/t/yS4SqUDqhe

Mysqlite原始数据库图像

enter image description here

  

执行查询后   execute query image

enter image description here

1 个答案:

答案 0 :(得分:1)

即使日期无效,以下部分也会将整个检查评估为true

OR ( strftime('%H:%M:%S',timer_from) = '00:00:00' OR '00:00:00' = strftime('%H:%M:%S',timer_to ))

也就是说,结果包含标记的行(timer_from = '00:00:00'timer_to = '00:00:00')就不足为奇了。

更新
尝试在上述查询部分中将OR更改为AND

更新2
ORDER BY position_id ASC, subposition_id ASC之前和AND user_id='265'之后:

之后,在查询结尾添加以下检查
AND (Date('2014-07-25') > startdate)