Bug 130672 - base sql query parameter with negative value fails
Summary: base sql query parameter with negative value fails
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
6.3.4.2 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-14 18:41 UTC by Wayne Davis
Modified: 2024-09-07 14:24 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Wayne Davis 2020-02-14 18:41:02 UTC
Description:
Simple example:
SELECT * FROM "MediaInfo" WHERE "aid" = :P1
The "aid" column is integer and has some negative integers in it. When I run the query and enter a positive integer it works but finds no records if I enter a negative. It does work when I replace :P1 with either '-1030' or just -1030.
Sliderule gave two workarounds:
SELECT * FROM "MediaInfo" WHERE "aid" = :P1*1
or SELECT * FROM "MediaInfo" WHERE "aid" IN ( :P1 )
He says it's an issue with Base OpenOffice / LibreOffice database parser.

Steps to Reproduce:
1. Create table1 with "ID", "AID" columns, both integer.  Create data rows, with negative numbers for "aid", ex:
ID   AID
123 -1030
124  235
666 -9999
2. Create query SELECT * FROM "table1" WHERE "aid" = :P1
3. Run query, enter -1030 for prompt.


Actual Results:
No records found.

Expected Results:
123, -1030


Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 6.3.4.2 (x64)
Build ID: 60da17e045e08f1793c57c00ba83cdfce946d0aa
CPU threads: 4; OS: Windows 10.0; UI render: default; VCL: win; 
Locale: en-US (en_US); UI-Language: en-US
Calc: threaded
Comment 1 Robert Großkopf 2020-02-15 15:59:37 UTC
Could confirm the buggy behavior with the internal database HSQLDB. Seems the parameter isn't set as Integer.

SELECT * FROM "table1" WHERE "aid" = CAST(:P1 AS INTEGER)
will work. Multiplication with '1' will do the same.
SELECT "aid", :P1 AS "T" FROM "table1" WHERE "aid" = :P1
will work also.

With internal Firebird the bug appears also, but there is no known workaround.

Tested with LO 6.4.0.3 on OpenSUSE 15.1 64bit rpm Linux
Comment 2 Robert Großkopf 2020-02-16 08:16:25 UTC
(In reply to Robert Großkopf from comment #1)
> 
> With internal Firebird the bug appears also, but there is no known
> workaround.

Workaround with Firebird:

SELECT * FROM "table1" WHERE CAST("aid" AS VARCHAR(10)) = :P1
Comment 3 QA Administrators 2022-02-16 03:35:30 UTC Comment hidden (obsolete)
Comment 4 Robert Großkopf 2022-02-16 06:56:23 UTC
Bug still exists in LO 7.3.1.1 on OpenSUSE 64bit rpm Linux.

Seems the parser sets negative values to "VARCHAR". Its a typical bug of the dialog for the parameter. In older versions before LO 4.4 it also set empty strings instead of NULL. See bug 86852
Comment 5 QA Administrators 2024-02-17 03:13:07 UTC Comment hidden (obsolete)
Comment 6 Robert Großkopf 2024-02-17 10:21:41 UTC
Bug still exists in LO 24.2.0.3 on OpenSUSE 64bit rpm Linux.
Comment 7 Julien Nabet 2024-09-07 14:24:23 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce this.

Lionel:
I could make it work with 2 changes:
1) 
diff --git a/connectivity/source/commontools/predicateinput.cxx b/connectivity/source/commontools/predicateinput.cxx
index c4360f981222..9eefddba525f 100644
--- a/connectivity/source/commontools/predicateinput.cxx
+++ b/connectivity/source/commontools/predicateinput.cxx
@@ -250,6 +250,7 @@ namespace dbtools
                     sTransformedText, m_xConnection, m_xFormatter, _rxField, OUString(),
                     rParseContext.getPreferredLocale(), OUString(nDecSeparator), &rParseContext
                 );
+                sTransformedText = sTransformedText.replaceAll(" ", "");
                 _rPredicateValue = sTransformedText;
 
                 bSuccess = true;

I noticed that, after having typed "-2" for example, if I switch to another appli and go back to LO, "-2" is automatically changed into "- 2" (with a space)

normalizePredicateString is called from OParameterDialog::CheckValueForError()
(see https://opengrok.libreoffice.org/xref/core/dbaccess/source/ui/dlg/paramdialog.cxx?r=d52a4dba#157)

I tried this to avoid modifying sqlnode.cxx (a bit afraid about regressions)

2) 
diff --git a/dbaccess/source/ui/dlg/paramdialog.cxx b/dbaccess/source/ui/dlg/paramdialog.cxx
index ad1c23baa9f4..934ea809d09d 100644
--- a/dbaccess/source/ui/dlg/paramdialog.cxx
+++ b/dbaccess/source/ui/dlg/paramdialog.cxx
@@ -215,10 +215,11 @@ namespace dbaui
                     {
                         Reference< XPropertySet >  xParamAsSet;
                         m_xParams->getByIndex(i) >>= xParamAsSet;
-
+/*
                         OUString sValue;
                         pValues->Value >>= sValue;
                         pValues->Value = m_aPredicateInput.getPredicateValue( sValue, xParamAsSet );
+*/
                     }
                 }
                 catch(Exception&)

This one replaces too "-2" by "- 2".
I must recognize I don't understand what's the use of the block I commented knowing that CheckValueForError from 1) already made the check.

Any thoughts here?