From 9c1e73a912b83dd86e17f70c3eceebd4ab70ec5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 14 Jul 2023 19:57:37 +0200 Subject: [PATCH] SQLRequest can return part of SQL requests without action or table. [GB.DB] * NEW: SQLRequest can return part of SQL requests without action or table. --- main/lib/db/gb.db/.component | 2 +- main/lib/db/gb.db/.project | 2 +- main/lib/db/gb.db/.src/Main.module | 3 +- main/lib/db/gb.db/.src/SQLRequest.class | 52 +++++++++++++------------ 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/main/lib/db/gb.db/.component b/main/lib/db/gb.db/.component index 4e93821e6..6ce35719f 100644 --- a/main/lib/db/gb.db/.component +++ b/main/lib/db/gb.db/.component @@ -1,3 +1,3 @@ [Component] Key=gb.db -Version=3.18.0 +Version=3.18.90 diff --git a/main/lib/db/gb.db/.project b/main/lib/db/gb.db/.project index 3b2de210d..48294b6bc 100644 --- a/main/lib/db/gb.db/.project +++ b/main/lib/db/gb.db/.project @@ -1,7 +1,7 @@ # Gambas Project File 3.0 Title=gb.db Startup=Main -Version=3.18.0 +Version=3.18.90 VersionFile=1 Component=gb.db TabSize=2 diff --git a/main/lib/db/gb.db/.src/Main.module b/main/lib/db/gb.db/.src/Main.module index d28a2a969..ee6d1feea 100644 --- a/main/lib/db/gb.db/.src/Main.module +++ b/main/lib/db/gb.db/.src/Main.module @@ -5,9 +5,10 @@ Public Sub Main() Dim hConn As New Connection hConn.Type = "postgresql" - hConn.Options["dbname"] = "omogen_benoit_kubuntu_sanef_fox2" hConn.Open + Print hConn.SQL.From("$").OrderBy(["a DESC", "b"])() + Print hConn.Tables.Count hConn.Close diff --git a/main/lib/db/gb.db/.src/SQLRequest.class b/main/lib/db/gb.db/.src/SQLRequest.class index d1dade8ce..d7675e051 100644 --- a/main/lib/db/gb.db/.src/SQLRequest.class +++ b/main/lib/db/gb.db/.src/SQLRequest.class @@ -122,33 +122,37 @@ Public Function _call() As String Dim sField As String Dim bDesc As Boolean - If Not $sTable Then Error.Raise("No table specified") + 'If Not $sTable Then Error.Raise("No table specified") - sReq = $sType + If $sType Then - If $aField Then - - sReq &= " " - - For I = 0 To $aField.Max - If I Then sReq &= "," - aScan = Scan($aField[I], "* AS *") - If aScan.Count = 2 And If InStr(aScan[1], " ") = 0 Then - sReq &= $aField[I] - Else If $aField[I] = "*" Then - sReq &= "*" - Else - sReq &= $hConn.Quote($aField[I]) - Endif - Next - - Else If $sType = "SELECT" Then - - sReq &= " *" + sReq = $sType + + If $aField Then + + sReq &= " " + + For I = 0 To $aField.Max + If I Then sReq &= "," + aScan = Scan($aField[I], "* AS *") + If aScan.Count = 2 And If InStr(aScan[1], " ") = 0 Then + sReq &= $aField[I] + Else If $aField[I] = "*" Then + sReq &= "*" + Else + sReq &= $hConn.Quote($aField[I]) + Endif + Next + + Else If $sType = "SELECT" Then + + sReq &= " *" + + Endif Endif - - sReq &= " FROM " & $hConn.Quote($sTable, True) + + If $sTable Then sReq &= " FROM " & $hConn.Quote($sTable, True) If $sWhere Then sReq &= " WHERE" & $sWhere @@ -171,6 +175,6 @@ Public Function _call() As String Endif - Return sReq + Return Trim(sReq) End