Access2Base - DLookup function works now correctly with MySql and Sqlite

Bug revealed on https://ask.libreoffice.org/en/question/68080/access2base-dfunctions-with-mysql/
Root cause: SELECT TOP 1 construction is invalid for MySql. Use LIMIT keyword instead.

Change-Id: Idb0bebe1adb8ca1f88dbc8f8ba039f117456337c
This commit is contained in:
Jean-Pierre Ledure
2016-05-05 16:33:03 +02:00
parent e6c8d8a75f
commit 5f46f90f39

View File

@@ -979,19 +979,29 @@ Dim oStatement As Object 'For CreateStatement method
Dim sExpr As String 'For inclusion of aggregate function Dim sExpr As String 'For inclusion of aggregate function
Dim sTempField As String 'Random temporary field in SQL expression Dim sTempField As String 'Random temporary field in SQL expression
Dim sTarget as String, sWhere As String, sOrderBy As String, sLimit As String
vResult = Null vResult = Null
If psFunction = "" Then sExpr = "TOP 1 " & psExpr Else sExpr = UCase(psFunction) & "(" & psExpr & ")"
Randomize 2^14-1 Randomize 2^14-1
sTempField = "TEMP" & Right("00000" & Int(100000 * Rnd), 5) sTempField = "[TEMP" & Right("00000" & Int(100000 * Rnd), 5) & "]"
sSql = "SELECT " & sExpr & " AS [" & sTempField & "] FROM " & psDomain If pvCriteria <> "" Then sWhere = " WHERE " & pvCriteria Else sWhere = ""
If pvCriteria <> "" Then If pvOrderClause <> "" Then sOrderBy = " ORDER BY " & pvOrderClause Else sOrderBy = ""
sSql = sSql & " WHERE " & pvCriteria sLimit = ""
End If
If pvOrderClause <> "" Then Select Case UCase(MetaData.getDatabaseProductName())
sSql = sSql & " ORDER BY " & pvOrderClause Case "MYSQL", "SQLITE"
If psFunction = "" Then
sTarget = psExpr
sLimit = " LIMIT 1"
Else
sTarget = UCase(psFunction) & "(" & psExpr & ")"
End If End If
sSql = "SELECT " & sTarget & " AS " & sTempField & " FROM " & psDomain & sWhere & sOrderBy & sLimit
Case Else ' Standard syntax - Includes HSQLDB
If psFunction = "" Then sTarget = "TOP 1 " & psExpr Else sTarget = UCase(psFunction) & "(" & psExpr & ")"
sSql = "SELECT " & sTarget & " AS " & sTempField & " FROM " & psDomain & sWhere & sOrderBy
End Select
'Lookup the value. 'Lookup the value.
Set oStatement = Connection.createStatement() Set oStatement = Connection.createStatement()