System.Data.SQLite issue on compact Framework 3.5

2019-07-01 15:19发布

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 end after 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 simulate the environment of fully loaded system and tried on it.

1条回答
聊天终结者
2楼-- · 2019-07-01 15:31

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
    //
}
查看更多
登录 后发表回答