【问题标题】:F# query expressions - restriction using string comparison in SqlProvider with SQLiteF# 查询表达式 - 在 SqlProvider 和 SQLite 中使用字符串比较进行限制
【发布时间】:2016-09-01 00:02:24
【问题描述】:

SQLite 并没有真正的日期列。您可以将日期存储为 ISO-8601 字符串、自纪元以来的整数秒数或儒略日数。在我使用的表格中,我希望我的日期是人类可读的,所以我选择使用 ISO-8601 字符串。

假设我想查询所有日期在今天之后的记录。 ISO-8601 字符串将正确排序,因此我应该能够将字符串与今天日期的 ISO-8601 字符串进行比较。

但是,我认为无法使用 F# SqlProvider 类型提供程序进行比较。我希望这只是我缺乏 F# 查询表达式知识的反映。

例如,我做不到:

   query { 
       for calendarEntry in dataContext.``[main].[calendar_entries]`` do
       where (calendarEntry.date >= System.DateTime.Today.ToString("yyyy-MM-dd hh:mm:ss"))        
   ... }

我明白了:

The binary operator GreaterThanOrEqual is not defined for the types 'System.String' and 'System.String'.

我也不能做任何变化:

   query { 
       for calendarEntry in dataContext.``[main].[calendar_entries]`` do
       where (calendarEntry.date.CompareTo(System.DateTime.Today.ToString("yyyy-MM-dd hh:mm:ss")) >= 0)
   ... }

我明白了:

Unsupported expression. Ensure all server-side objects appear on the left hand side of predicates.  The In and Not In operators only support the inline array syntax.

有人知道我可以如何在 where 子句中进行字符串比较吗?似乎我在查询中进行过滤的唯一选择是将 seconds-since-epoch 存储在数据库中并使用整数比较。

【问题讨论】:

    标签: sqlite f#


    【解决方案1】:

    这是旧 SQLProvider 版本的临​​时错误,现在应该可以工作了。如果没有,请在 GitHub 存储库中打开一个新问题:https://github.com/fsprojects/SQLProvider

    【讨论】:

    • 顺便说一句,我也测试了这个,我相信字符串比较仍然显示相同的错误。
    • 已添加Issue 328
    • 谢谢。检查此问题后,SQLite 确实有 DATETIME 列并且它们正在工作。 stackoverflow.com/a/39312904/17791
    • 是的,但让我评论一下 GitHub 为什么修复这个问题(如果可能的话)仍然是一个好主意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2012-10-06
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多