Bug 155204 - BASIC SF GetRows treats an empty result as an error
Summary: BASIC SF GetRows treats an empty result as an error
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.5.1.2 release
Hardware: x86-64 (AMD64) All
: medium major
Assignee: Jean-Pierre Ledure
URL:
Whiteboard: target:7.6.0 target:7.5.4
Keywords:
: 156238 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-05-09 00:44 UTC by Michael
Modified: 2023-07-19 14:45 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Sample document (4.75 KB, application/vnd.sun.xml.base)
2023-05-09 00:44 UTC, Michael
Details
screenshot (19.58 KB, image/png)
2023-05-09 00:45 UTC, Michael
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael 2023-05-09 00:44:22 UTC
Created attachment 187156 [details]
Sample document

Steps to reproduce
1 have base document with
1.1 with a table
1.1.1 with content
	KategorieID | KategorieName
	1           | red
2. have macro
 Sub Main
	GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
	DIM oDoc AS OBJECT : oDoc = CreateScriptService("SFDocuments.Document",ThisDatabaseDocument)
	DIM oDB AS OBJECT : oDB = oDoc.GetDatabase()
	Dim queryResults as Variant
	queryResults = oDB.GetRows("SELECT * FROM [Kategorien] WHERE [KategorieName] = 'red'")		' works as expected
	queryResults = oDB.GetRows("SELECT * FROM [Kategorien] WHERE [KategorieName] = 'green'")	' crash
 End Sub
3. Run macro

Expected behavior 
GetRows returns array of records found. An empty array, if no records found

Actual behavior
GetRows creates a popup window complaining about a crash, if no records found / empty result set
Comment 1 Michael 2023-05-09 00:45:47 UTC
Created attachment 187157 [details]
screenshot
Comment 2 Buovjaga 2023-05-15 13:51:17 UTC
Reproduced with document.

Jean-Pierre: you are probably interested in this.

Arch Linux 64-bit, X11
Version: 7.6.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: d2756dbd9b11bdfbf1d576381b8f9846a6fb7070
CPU threads: 8; OS: Linux 6.3; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: threaded
Built on 15 May 2023
Comment 3 Jean-Pierre Ledure 2023-05-16 14:49:25 UTC
The complete expected bheviour is: when there is no data returned by the query, - - either GetRows()returns an empty array, when Header := False
- or GetRows() returns an array with a single row containing the column names only

Indeed, in the example given, 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() executions on the resultset.

A patch will be provided to correct the error.

Thanks for having reported the issue.
Comment 4 Commit Notification 2023-05-17 06:54:32 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d07cc6706ef3b382fa16a104c97b69bc2d2365e5

ScriptForge - database.GetRows() tdf#155204 error when no data

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2023-05-17 10:47:58 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-7-5":

https://git.libreoffice.org/core/commit/2840a8e139f9e6766fe291512f6a42b3d72371f6

ScriptForge - database.GetRows() tdf#155204 error when no data

It will be available in 7.5.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Jean-Pierre Ledure 2023-07-19 14:45:51 UTC
*** Bug 156238 has been marked as a duplicate of this bug. ***