0

我发现了一个问题,可能是 SQLite ADO.NET Provider 中的一个错误。

环境是 Windows 7 Pro,使用 Visual Studio 2012 Professional,带有 Visual Basic.net 和 ADO.NET 2.0。数据提供者版本 1.0.66.0 - v2.0.50727。

为了测试,我使用了一个只有一个表(“操作”)的简单 SQLite 数据库。

数据如下:

ID|TYPE|CODE|SIGN|DATE 
15|TE|MC_02|ACME|2007-02-13
132|TE|MC_02|ACME|2009-01-16
190|TE|MC_02|ACME|2011-02-18
596|M|MC_02|MA|2009-06-17
703|M|MC_02|MA|2009-11-30
796|M|MC_02|MA|2010-06-10
898|M|MC_02|NQ|2011-07-04
929|M|MC_02|NQ|2011-12-02
980|M|MC_02|NQ|2012-01-02
1011|M|MC_02|NQ|2012-06-29
1061|M|MC_02|NQ|2012-12-05
1062|M|MC_02|AB|2000-01-01

如果我使用命令提示符运行以下 SQL SELECT 语句:

D:\DB>sqlite3 test.db

Sqlite>SELECT *, MAX(DATE) FROM operations WHERE CODE = 'MC_02' GROUP BY TYPE;

我有(正确):

1061|M|MC_02|NQ|2012-12-05|2012-12-05 
190|TE|MC_02|ACME|2011-02-18|2011-02-18

相反,如果我使用下面的 VB.net 代码(只是一个带按钮的表单):

Public Class Form1
    Dim arrSelect As New ArrayList
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim strConnection As String = "data source= D:\DB\test.db"
        Dim strQuery As String = "SELECT *, MAX(DATE) FROM operations WHERE CODE = 'MC_02' GROUP BY TYPE"
        Dim strRecord As String = ""
        arrSelect = SelectSQL(strConnection, strQuery)
        If arrSelect IsNot Nothing Then
            For Each value As Array In arrSelect
                strRecord = ""
                For j As Integer = 0 To value.Length - 1
                    strRecord &= value(j) & "|"
                Next
                Console.WriteLine(strRecord)
            Next
        End If
    End Sub

    Function SelectSQL(ByVal strConn As String, ByVal strCommand As String) As ArrayList
        Try
            Dim SQLconnect As New SQLite.SQLiteConnection()
            Dim SQLcommand As New SQLite.SQLiteCommand
            SQLconnect.ConnectionString = strConn
            SQLconnect.Open()
            SQLcommand = SQLconnect.CreateCommand
            SQLcommand.CommandText = strCommand
            Dim SQLreader As SQLite.SQLiteDataReader = SQLcommand.ExecuteReader()
            Dim listLoc As New ArrayList
            Dim nc As Integer = SQLreader.FieldCount
            Dim arrLoc() As Object
            While SQLreader.Read()
                ReDim arrLoc(nc - 1)
                For j As Integer = 0 To nc - 1
                    arrLoc(j) = SQLreader.Item(j)
                Next
                listLoc.Add(arrLoc)
            End While
            SQLcommand.Dispose()
            SQLconnect.Close()
            Return listLoc
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
End Class

你有这个结果(错误):

1062|M|MC_02|AB|2000-01-01
190|TE|MC_02|ACME|2011-02-18

有人已经遇到过这种行为吗?

这是数据提供者的错误吗?或者我做错了什么?

4

1 回答 1

0

此类查询仅适用于 SQLite 3.7.11 及更高版本,因此您应将提供程序更新到 1.0.80.0 或更高版本。

于 2013-02-28T15:13:33.983 回答