wizards/source/sfdatabases/SF_Database.xba |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

New commits:
commit d07cc6706ef3b382fa16a104c97b69bc2d2365e5
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Tue May 16 17:00:20 2023 +0200
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Wed May 17 08:53:58 2023 +0200

    ScriptForge - database.GetRows() tdf#155204 error when no data
    
    The complete expected bheviour is:
    when there is no data returned by the query,
    - either GetRows() returns an empty array, (Header := False)
    - or GetRows() returns an array with a single
    row containing the column names only (Header := True)
    
    In the example given in the bug report,
    GetRows() gives an unexpected error.
    
    Actually the "end-of-file" status is tested
    with the isAfterLast() indicator.
    It seems better to rely on the Boolean value
    returned by the first() and next() methods applied
    on the resultset.
    
    Change-Id: Ibe97dbbcb03d45ebb9184fab2733abe4e04963a6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151844
    Tested-by: Jean-Pierre Ledure <j...@ledure.be>
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>
    Tested-by: Jenkins

diff --git a/wizards/source/sfdatabases/SF_Database.xba 
b/wizards/source/sfdatabases/SF_Database.xba
index de891935be69..f93cf55d74c0 100644
--- a/wizards/source/sfdatabases/SF_Database.xba
+++ b/wizards/source/sfdatabases/SF_Database.xba
@@ -312,7 +312,8 @@ Dim sSql As String                          &apos;  SQL 
statement
 Dim bDirect                                            &apos;  Alias of 
DirectSQL
 Dim lCols As Long                              &apos;  Number of columns
 Dim lRows As Long                              &apos;  Number of rows
-Dim oColumns As Object
+Dim oColumns As Object                 &apos;  Collection of 
com.sun.star.sdb.ODataColumn
+Dim bRead As Boolean                   &apos;  When True, next record has been 
read successfully
 Dim i As Long
 Const cstThisSub = &quot;SFDatabases.Database.GetRows&quot;
 Const cstSubArgs = &quot;SQLCommand, [DirectSQL=False], [Header=False], 
[MaxRows=0]&quot;
@@ -367,8 +368,8 @@ Try:
                End If
 
        &apos;  Load data
-               .first()
-               Do While Not .isAfterLast() And (MaxRows = 0 Or lRows &lt; 
MaxRows - 1)
+               bRead = .first()
+               Do While bRead And (MaxRows = 0 Or lRows &lt; MaxRows - 1)
                        lRows = lRows + 1
                        If lRows = 0 Then
                                ReDim vResult(0 To lRows, 0 To lCols)
@@ -378,7 +379,7 @@ Try:
                        For i = 0 To lCols
                                vResult(lRows, i) = _GetColumnValue(oResult, i 
+ 1)
                        Next i
-                       .next()
+                       bRead = .next()
                Loop
        End With
        

Reply via email to