Bug 162833 - Firebird sqlquery with sum created in 24.2 can not changed or saved with Editor 24.8
Summary: Firebird sqlquery with sum created in 24.2 can not changed or saved with Edit...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
24.8.0.3 release
Hardware: All All
: medium normal
Assignee: Julien Nabet
URL:
Whiteboard: target:25.2.0 target:24.8.2 target:24...
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-07 05:32 UTC by Ulf
Modified: 2024-09-09 21:25 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
errordetails (30.07 KB, image/jpeg)
2024-09-07 05:32 UTC, Ulf
Details
Database to show the error (4.01 KB, application/vnd.sun.xml.base)
2024-09-07 05:33 UTC, Ulf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ulf 2024-09-07 05:32:02 UTC
Created attachment 196294 [details]
errordetails

Edit Test_01
Run query

Query works

Insert any field like idTyp by double click
set function to “group by” to the new column
run query

Error in Libreoffice 24.8

delete column idTyp

Impossible to run or save the query again

There is no error in 24.2.4.2

Version: 24.8.0.3 (X86_64) / LibreOffice Community
Build ID: 0bdf1299c94fe897b119f97f3c613e9dca6be583
CPU threads: 24; OS: Windows 11 X86_64 (10.0 build 22631); UI render: Skia/Raster; VCL: win
Locale: de-DE (de_DE); UI: de-DE
Calc: CL threaded
Comment 1 Ulf 2024-09-07 05:33:42 UTC
Created attachment 196295 [details]
Database to show the error
Comment 2 Robert Großkopf 2024-09-07 06:31:44 UTC
Different behavior here:

Opening the query in LO 24.2.5.2 for editing in GUI.
Executing query → no problem
Adding field to query → no problem

Opening in LO 24.8.0.3 for editing in GUI.
Executing query → Crash of LO

Opening in LO 24.8.1.1 for editing in GUI.
Executing query → "Syntax error in SQL statement" and in details the old unusable "syntax error, unexpected $end, expecting BETWEEN or IN or SQL_TOKEN_LIKE"

If opening the query for editing in SQL mode query could be executed.

You won't need to add any field to produce the buggy behavior of GUI.

Version: 24.8.1.1 (X86_64) / LibreOffice Community
Build ID: ef51c4a0cd35185debf25ad9d0db6a1c14bed5a0
CPU threads: 6; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: en-US
Calc: threaded
Comment 3 Julien Nabet 2024-09-07 09:31:33 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce the error message.

After some gdb trace, I noticed that when opening the query in edition, I got:
#0  dbaui::OQueryController::setStatement_fireEvent
    (this=0x5583a3cb8d90, _rNewStatement="SELECT \"fiPayTermin\", SUM( CASE WHEN \"dtPayTyp\" = 1 THEN \"dtPayBetrag\" * - 1 ELSE \"dtPayBetrag\" END ) \"qcpSollHabenErsatz\" FROM \"tblmPay\" GROUP BY \"tblmPay\".\"fiPayTermin\"", _bFireStatementChange=true) at dbaccess/source/ui/querydesign/querycontroller.cxx:1724
#1  0x00007fe3f1eb882f in dbaui::OQueryController::impl_reset (this=0x5583a3cb8d90, i_bForceCurrentControllerSettings=false) at dbaccess/source/ui/querydesign/querycontroller.cxx:1609
#2  0x00007fe3f1eb7de4 in dbaui::OQueryController::impl_initialize (this=0x5583a3cb8d90, rArguments=...) at dbaccess/source/ui/querydesign/querycontroller.cxx:809
#3  0x00007fe3f1bb4fe2 in dbaui::OGenericUnoController::initialize (this=0x5583a3cb8d90, aArguments=uno::Sequence of length 13 = {...}) at dbaccess/source/ui/browser/genericcontroller.cxx:217
#4  0x00007fe3f1b2a76d in (anonymous namespace)::DBContentLoader::load
    (this=0x5583a1707c50, rFrame=uno::Reference to ((anonymous namespace)::XFrameImpl *) 0x5583a3d45af0, rURL=".component:DB/QueryDesign", rArgs=uno::Sequence of length 12 = {...}, rListener=uno::Reference to (framework::(anonymous namespace)::LoadEnvListener *) 0x5583a3aad4a8) at dbaccess/source/ui/browser/dbloader.cxx:226
#5  0x00007fe424c1da70 in framework::LoadEnv::impl_loadContent (this=0x7fff543b7218) at framework/source/loadenv/loadenv.cxx:1163
#6  0x00007fe424c1aa84 in framework::LoadEnv::start (this=0x7fff543b7218) at framework/source/loadenv/loadenv.cxx:412

so _rNewStatement="SELECT \"fiPayTermin\", SUM( CASE WHEN \"dtPayTyp\" = 1 THEN \"dtPayBetrag\" * - 1 ELSE \"dtPayBetrag\" END ) \"qcpSollHabenErsatz\" FROM \"tblmPay\" GROUP BY \"tblmPay\".\"fiPayTermin\""

but when executing, i got:
#0  dbaui::OQueryController::setStatement_fireEvent
    (this=0x5583a49acae0, _rNewStatement="SELECT \"fiPayTermin\", Sum(Sum( WHEN \"dtPayTyp\" = 1 THEN \"dtPayBetrag\" * - 1 ELSE \"dtPayBetrag\" END) AS \"qcpSollHabenErsatz\" FROM \"tblmPay\" GROUP BY \"tblmPay\".\"fiPayTermin\" ", _bFireStatementChange=false) at dbaccess/source/ui/querydesign/querycontroller.cxx:1724
#1  0x00007fe3f1ebaca4 in dbaui::OQueryController::translateStatement (this=0x5583a49acae0, _bFireStatementChange=false) at dbaccess/source/ui/querydesign/querycontroller.cxx:1520
#2  0x00007fe3f1eb53ab in dbaui::OQueryController::executeQuery (this=0x5583a49acae0) at dbaccess/source/ui/querydesign/querycontroller.cxx:1081
#3  0x00007fe3f1eb2bb7 in dbaui::OQueryController::Execute (this=0x5583a49acae0, _nId=10721, aArgs=uno::Sequence of length 1 = {...}) at dbaccess/source/ui/querydesign/querycontroller.cxx:582

SELECT \"fiPayTermin\", Sum(Sum( WHEN \"dtPayTyp\" = 1 THEN \"dtPayBetrag\" * - 1 ELSE \"dtPayBetrag\" END) AS \"qcpSollHabenErsatz\" FROM \"tblmPay\" GROUP BY \"tblmPay\".\"fiPayTermin\" "

Notice the "SUM ( CASE" is transformed in "Sum(Sum"
Comment 4 Julien Nabet 2024-09-07 10:10:13 UTC
I gave a try with https://gerrit.libreoffice.org/c/core/+/172989
Comment 5 Julien Nabet 2024-09-07 10:34:34 UTC
Just for info, this bug isn't specific to Firebird, it's related to queries in general which include an aggregate function (SUM, COUNT, etc.)
So there may be already existing bugs with the same root cause.
Comment 6 Commit Notification 2024-09-07 19:48:47 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

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

tdf#162833: don't use an OUStringBuffer directly in a concat to assign itself

It will be available in 25.2.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 7 Julien Nabet 2024-09-07 19:55:40 UTC
cherry-pick for 24.8: https://gerrit.libreoffice.org/c/core/+/173007
cherry-pick for 24.8.1: https://gerrit.libreoffice.org/c/core/+/173008
Comment 8 Ulf 2024-09-07 20:23:23 UTC
Well that was very fast. Thank you
Comment 9 Commit Notification 2024-09-07 21:13:00 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/05de49bad2c8d097dc6bf18f1d16093b90fb5768

tdf#162833: don't use an OUStringBuffer directly in a concat to assign itself

It will be available in 24.8.2.

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 10 Commit Notification 2024-09-08 08:31:15 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-24-8-1":

https://git.libreoffice.org/core/commit/3a32f7ad5ada5b3ea83d7160127f09302e3cb16d

tdf#162833: don't use an OUStringBuffer directly in a concat to assign itself

It will be available in 24.8.1.

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 11 Ulf 2024-09-09 21:21:26 UTC
Works for me now with:
Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: c8eb95e8407ef24436e0e8e218dce535df6bb2e5
CPU threads: 16; OS: Windows 11 X86_64 (10.0 build 22631); UI render: Skia/Vulkan; VCL: win
Locale: de-DE (de_DE); UI: de-DE
Calc: threaded
Comment 12 Julien Nabet 2024-09-09 21:25:59 UTC
Thank you for the check Ulf! :-)