Bug 156238 - Python SFDatabases.Database.GetRows() crashes when no data is available
Summary: Python SFDatabases.Database.GetRows() crashes when no data is available
Status: RESOLVED DUPLICATE of bug 155204
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
7.3.7.2 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2023-07-11 15:12 UTC by Szymon Nikliborc
Modified: 2023-07-19 14:45 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Calc file (7.74 KB, application/octet-stream)
2023-07-11 15:14 UTC, Szymon Nikliborc
Details
Error window (43.41 KB, image/png)
2023-07-11 15:15 UTC, Szymon Nikliborc
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Szymon Nikliborc 2023-07-11 15:12:31 UTC
Description:
I write python macro embed in Calc which: create database, insert data and select data.
An Libreoffice error window is displayed when there is no data in the database (SELECT statement). Trying to catch an exception doesn't help.

Steps to Reproduce:
1. Install APSO
2. Open the attached file
3. Run "organise python script", select embedded modul "test", run "Python shell"
4. In shell type test1() + enter

Actual Results:
>>> test1()
/home/sznik/python_projekty/LibreOffice/test.odb
Connection to Base successful
query ='CREATE TABLE "tickers" ("id" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY, "ticker" VARCHAR(50) NOT NULL, "currency" VARCHAR(10) NOT NULL)'
Query executed successfully
query ='INSERT INTO "tickers" ("ticker", "currency") VALUES (\'a\', \'aa\')'
Query executed successfully
query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'a\' '
Query executed successfully
execute_read_query(connection, query) =((0,),)

query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'b\' '
Traceback (most recent call last):
  File "/usr/lib/python3.10/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
  File "/home/sznik/.config/libreoffice/4/user/Scripts/python/test.py", line 61, in test1
    print(f'{execute_read_query(connection, query) =}\n')
  File "/home/sznik/.config/libreoffice/4/user/Scripts/python/test.py", line 33, in execute_read_query
    result = connection.GetRows(query, directsql=True)
  File "/usr/lib/libreoffice/program/scriptforge.py", line 1603, in GetRows
    return self.ExecMethod(self.vbMethod + self.flgArrayRet, 'GetRows', sqlcommand, directsql, header, maxrows)
  File "/usr/lib/libreoffice/program/scriptforge.py", line 546, in ExecMethod
    return self.EXEC(self.objectreference, flags, methodname, *args)
  File "/usr/lib/libreoffice/program/scriptforge.py", line 306, in InvokeBasicService
    raise RuntimeError("The execution of the method '" + method + "' failed. Execution stops.")
RuntimeError: The execution of the method 'GetRows' failed. Execution stops.
>>> 

Expected Results:
>>> test1()
/home/sznik/python_projekty/LibreOffice/test.odb
Connection to Base successful
query ='CREATE TABLE "tickers" ("id" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY, "ticker" VARCHAR(50) NOT NULL, "currency" VARCHAR(10) NOT NULL)'
Query executed successfully
query ='INSERT INTO "tickers" ("ticker", "currency") VALUES (\'a\', \'aa\')'
Query executed successfully
query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'a\' '
Query executed successfully
execute_read_query(connection, query) =((0,),)

query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'b\' '
Query executed successfully
execute_read_query(connection, query) =()
>>> 


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: pl-PL (pl_PL.UTF-8); UI: pl-PL
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.3
Calc: threaded
Comment 1 Szymon Nikliborc 2023-07-11 15:14:30 UTC
Created attachment 188318 [details]
Calc file
Comment 2 Szymon Nikliborc 2023-07-11 15:15:13 UTC
Created attachment 188319 [details]
Error window
Comment 3 Rafael Lima 2023-07-18 21:59:52 UTC
Hi, I have just run your script and it worked. Here's what I got as result:

------------< Python Shell >------------
>>> test1()
/home/rafael/Downloads/test.odb
Connection to Base successful
query ='CREATE TABLE "tickers" ("id" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY, "ticker" VARCHAR(50) NOT NULL, "currency" VARCHAR(10) NOT NULL)'
Query executed successfully
query ='INSERT INTO "tickers" ("ticker", "currency") VALUES (\'a\', \'aa\')'
Query executed successfully
query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'a\' '
Query executed successfully
execute_read_query(connection, query) =((0,),)

query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'b\' '
Query executed successfully
execute_read_query(connection, query) =()
------------

I simply opened the file, entered APSO Python sheel and ran "test1()".

Note that if you run the script for a second time, it will crash because the ODB file will have been created.

@JPL any input in this issue?
Comment 4 Szymon Nikliborc 2023-07-19 12:07:59 UTC
(In reply to Rafael Lima from comment #3)
> Hi, I have just run your script and it worked. Here's what I got as result:
> 
> ------------< Python Shell >------------
> >>> test1()
> /home/rafael/Downloads/test.odb
> Connection to Base successful
> query ='CREATE TABLE "tickers" ("id" INTEGER GENERATED BY DEFAULT AS
> IDENTITY(START WITH 0) NOT NULL PRIMARY KEY, "ticker" VARCHAR(50) NOT NULL,
> "currency" VARCHAR(10) NOT NULL)'
> Query executed successfully
> query ='INSERT INTO "tickers" ("ticker", "currency") VALUES (\'a\', \'aa\')'
> Query executed successfully
> query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'a\' '
> Query executed successfully
> execute_read_query(connection, query) =((0,),)
> 
> query ='SELECT "id" FROM "tickers" WHERE "ticker" = \'b\' '
> Query executed successfully
> execute_read_query(connection, query) =()
> ------------
> 
> I simply opened the file, entered APSO Python sheel and ran "test1()".
> 
> Note that if you run the script for a second time, it will crash because the
> ODB file will have been created.
> 
> @JPL any input in this issue?

Problem is with Linux. Windows is ok.
Comment 5 Rafael Lima 2023-07-19 12:48:54 UTC
(In reply to Szymon Nikliborc from comment #4)
> Problem is with Linux. Windows is ok.

I tested in Kubuntu 23.04 and it worked... maybe you could try again on another Linux install and see if the issue persists.

My system info:
Version: 7.5.4.2 (X86_64) / LibreOffice Community
Build ID: 50(Build:2)
CPU threads: 16; OS: Linux 6.2; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: en-US
Ubuntu package version: 4:7.5.4-0ubuntu0.23.04.1
Calc: threaded
Comment 6 Jean-Pierre Ledure 2023-07-19 14:45:51 UTC
My conclusion is that the bug is a duplicate of bug#155204.

The script aborts on line 61, which attempts to execute next query:
   SELECT "id" FROM "tickers" WHERE "ticker" = 'b'

Now, this query does not return any record.
Exactly the situation described in above-mentioned bug.

The bug is corrected since LO 7.5.4.

Thanks for having reported this bug.

*** This bug has been marked as a duplicate of bug 155204 ***