gpt4 book ai didi

sqlite - Servicestack-在SQLite32数据库上按日期查询OrmLite不会返回任何结果

转载 作者:行者123 更新时间:2023-12-02 09:57:38 24 4
gpt4 key购买 nike

今天,我通过使用ServiceStack ORMLite(在Windows 2012 Server,.NET Framework 4.0上进行测试)查询32位SQLite嵌入式数据库而遇到了奇怪的事情。

考虑以下测试查询:

var dateMinimum = DateTime.Now.Subtract(_doNotProcessQueueItemWhenOlderThanHours);
using (var db = DbConnectionFactory.OpenDbConnection())
{
var queueItemsTest1 = db.Select<ProcessQueue>(pc => (pc.Status == ProcessingStatus.Failed.ToString()) && (pc.DateCreated > dateMinimum)).ToList();
var queueItemsTest2 = db.Select<ProcessQueue>(pc => (pc.Status == ProcessingStatus.Failed.ToString())).ToList();
var queueItemsTest3 = db.Select<ProcessQueue>(pc => (pc.DateCreated > dateMinimum)).ToList();


var queueItemsUnparsed = db.Select<ProcessQueue>().ToList();
var queueItems = new List<ProcessQueue>();
foreach (var queueItemUnparsed in queueItemsUnparsed)
{
if ((queueItemUnparsed.Status == ProcessingStatus.Failed.ToString()) && (queueItemUnparsed.DateCreated > dateMinimum))
{
queueItems.Add(queueItemUnparsed);
}
}
}

public class ProcessQueue
{
[AutoIncrement]
public int Id { get; set; }
public DateTime DateCreated { get; set; }
public string Status { get; set; }
}

奇怪的是:
  • queueItemsTest1不返回任何内容
  • queueItemsTest2返回所有正确的行
  • queueItemsTest3不返回任何内容
  • foreach构造返回正确的行。

  • 有什么方法可以记录数据库内部的情况吗?

    我认为这与SQLite有关,因为我还有另一个队列与SQL Server通信,并且可以正常工作。我正在使用SQLite,因为此队列必须嵌入并且找不到使ORMLite与SQL Compact一起工作的方法。

    最佳答案

    Is there some way to log what is going on inside the database?



    最简单的方法是使用 Console.WriteLine(db.GetLastSql());
    因此,在您的情况下:

    var queueItemsTest1 = db.Select<ProcessQueue>(pc => (pc.Status == ProcessingStatus.Failed.ToString()) && (pc.DateCreated > dateMinimum)).ToList();
    Console.WriteLine(db.GetLastSql());

    var queueItemsTest2 = db.Select<ProcessQueue>(pc => (pc.Status == ProcessingStatus.Failed.ToString())).ToList();
    Console.WriteLine(db.GetLastSql());

    var queueItemsTest3 = db.Select<ProcessQueue>(pc => (pc.DateCreated > dateMinimum)).ToList();
    Console.WriteLine(db.GetLastSql());

    然后,您应该能够使用SQL输出确定正在构建的查询。如果要冒一个危险,我会说这与Date处理有关。

    您不能使用 DateTime对象,因为SQLite不支持相应的格式。

    SQLite documentation:

    SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:

    • TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
    • REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
    • INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.

    Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.



    使用 DateTime.Ticks应该提供适当的 long

    关于sqlite - Servicestack-在SQLite32数据库上按日期查询OrmLite不会返回任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21270169/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com