本文介绍了Compact Framework 3.5上的System.Data.SQLite问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的小型框架应用程序中使用sqlite来记录系统中的事件。我也使用。事件有时间戳来描述它发生在什么时间。我把这个时间戳记存放在我的桌子里。与此列一起,该表包含另外5列的整数/文本类型。以下是表格式

  CREATE TABLE T1(TimeStamp INTEGER,Col2 INTEGER,Col3 INTEGER,Col4 INTEGER,
Col5 INTEGER ,Col6 TEXT,PRIMARY KEY(TimeStamp DESC));

我正在查询使用ADO的两个时间戳之间的数据与下面的查询

  SELECT TimeStamp,Col1,Col2,Col3,Col4,Col5 FROM T1 WHERE TimeStamp 
BETWEEN @startDate AND @endDate LIMIT 2000;

我将用户给出的时间戳转换为Ticks,并将其作为参数值发送给'@ startDate'和'@endDate'。



在执行上面的查询后,我开始使用 while循环迭代SqLiteDataReader,我发现这个while循环永远不会出现并继续执行不休。理想情况下,在读取2000条记录后,应该结束

以下是代码片段。

  SQLiteDataReader dr = cmd.ExecuteReader(); 

while(dr.Read())
{

:将列中的数据填充到事件类对象

}

请让我知道有人遇到同样的问题。



编辑: - 经过调查,我发现这个问题出现在完全加载的系统上。我模拟
完全加载系统的环境,并尝试使用它。

解决方案

你可以总是以另一种方式解决它,从SQL中删除 LIMIT 2000 ,并略微更改您的读取逻辑,如下所示:

  var dr = cmd.ExecuteReader(); 
var rows = 0;

while(dr.Read())
{
if(++ rows> 2000)break;

//
//将列中的数据填入Event类对象
//
}


I am using sqlite in my compact framework application to log the events in system. I am also using System.Data.SQLite. The event has the time stamp to describe at what time it occurred. I am storing this Time stamp as Ticks in my table. Along with this column the table contains another 5 columns of integer/text type. Below is table schema

CREATE TABLE T1 (TimeStamp INTEGER, Col2 INTEGER, Col3 INTEGER, Col4 INTEGER,
                      Col5 INTEGER, Col6 TEXT, PRIMARY KEY(TimeStamp DESC));

I am querying for the data between two time stamp using ADO with below query

SELECT TimeStamp,Col1,Col2,Col3,Col4,Col5 FROM T1 WHERE TimeStamp
BETWEEN @startDate AND @endDate LIMIT 2000;

I am converting the Time stamp given by the user to Ticks and sending them as parameter values for '@startDate' and '@endDate'.

After I executed above query then I start iterating over SqLiteDataReader using while loop there I found that this while loop never comes out and continue to execute endlessly. Ideally it should endafter reading 2000 records.Below is code snippet.

SQLiteDataReader dr = cmd.ExecuteReader();

    while(dr.Read())
    {
        :
        : Fill the data from column into Event class object
        :
    }

Please let me know if anybody has faced same issue.

EDIT :- After investigation I found that this problem comes up on fully loaded system. I simulatethe environment of fully loaded system and tried on it.

解决方案

You could always solve it in another way, eliminating the LIMIT 2000 from the SQL and slightly changing your read logic like this:

var dr = cmd.ExecuteReader();
var rows = 0;

while(dr.Read())
{
    if(++rows > 2000) break;

    //
    // Fill the data from column into Event class object
    //
}

这篇关于Compact Framework 3.5上的System.Data.SQLite问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:52