diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2016-05-05 16:33:03 +0200 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2016-05-05 16:37:42 +0200 |
commit | 5f46f90f39b947affd0e2e37add753eb6285da93 (patch) | |
tree | 6876d2b7fff4d572086441a5a95c911a46d150ec /wizards | |
parent | e6c8d8a75f2d985ea9a14e2108d9dda89b6fd00d (diff) |
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
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/access2base/Database.xba | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/wizards/source/access2base/Database.xba b/wizards/source/access2base/Database.xba index 84f1112d745c..968d394aa8ee 100644 --- a/wizards/source/access2base/Database.xba +++ b/wizards/source/access2base/Database.xba @@ -979,19 +979,29 @@ Dim oStatement As Object 'For CreateStatement method Dim sExpr As String 'For inclusion of aggregate function Dim sTempField As String 'Random temporary field in SQL expression - vResult = Null +Dim sTarget as String, sWhere As String, sOrderBy As String, sLimit As String - If psFunction = "" Then sExpr = "TOP 1 " & psExpr Else sExpr = UCase(psFunction) & "(" & psExpr & ")" + vResult = Null Randomize 2^14-1 - sTempField = "TEMP" & Right("00000" & Int(100000 * Rnd), 5) - sSql = "SELECT " & sExpr & " AS [" & sTempField & "] FROM " & psDomain - If pvCriteria <> "" Then - sSql = sSql & " WHERE " & pvCriteria - End If - If pvOrderClause <> "" Then - sSql = sSql & " ORDER BY " & pvOrderClause - End If + sTempField = "[TEMP" & Right("00000" & Int(100000 * Rnd), 5) & "]" + If pvCriteria <> "" Then sWhere = " WHERE " & pvCriteria Else sWhere = "" + If pvOrderClause <> "" Then sOrderBy = " ORDER BY " & pvOrderClause Else sOrderBy = "" + sLimit = "" + + Select Case UCase(MetaData.getDatabaseProductName()) + Case "MYSQL", "SQLITE" + If psFunction = "" Then + sTarget = psExpr + sLimit = " LIMIT 1" + Else + sTarget = UCase(psFunction) & "(" & psExpr & ")" + 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. Set oStatement = Connection.createStatement() |