Sqlite数据提供程序.net错误:不同的SQL响应命令提示符与SQLite ADO.NET提供程序

时间:2013-02-28 15:00:24

标签: vb.net sqlite sqlite-net

我发现了一个问题,可能是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数据库(“operations”)。

数据如下:

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

是否有人遇到过此行为?

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

1 个答案:

答案 0 :(得分:0)

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