Bug 147893 - Embedded firebird extends size of CHAR() data field beyond set boundaries and invokes error message
Summary: Embedded firebird extends size of CHAR() data field beyond set boundaries and...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
6.1.2.1 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL: https://github.com/FirebirdSQL/firebi...
Whiteboard:
Keywords:
: 120640 (view as bug list)
Depends on:
Blocks: Database-Firebird-Default
  Show dependency treegraph
 
Reported: 2022-03-10 09:56 UTC by johnny bugs
Modified: 2023-04-30 08:08 UTC (History)
4 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 johnny bugs 2022-03-10 09:56:30 UTC
Description:
When filling a field with a fixed character size data type with appropriate data, the field is right padded with spaces to 4 times its defined length.

Steps to Reproduce:
1. Create new embedded firebird database
2. Create new table with a CHAR() data field (weather primary key or not)
3. Insert data, save and close table
4. Reopen table

Actual Results:
All entered data is right padded with spaces to 4 times its set size

Expected Results:
Spaces shouldn't have been added


Reproducible: Always


User Profile Reset: Yes


OpenGL enabled: Yes

Additional Info:
Base gives an error on trying to fill records in a form using a list box linking to that column. Giving this error message:


firebird_sdbc error:
*Dynamic SQL Error
*SQL error code = -303
*arithmetic exception, numeric overflow, or string truncation
*string right truncation
*expected length 3, actual 12
caused by
'isc_dsql_execute'


Version: 7.2.5.2 (x64) / LibreOffice Community
Build ID: 499f9727c189e6ef3471021d6132d4c694f357e5
CPU threads: 4; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: en-IE (en_IE); UI: en-GB
Calc: threaded
Comment 1 Robert Großkopf 2022-03-10 11:07:29 UTC
Have tested this with LO 7.3.1.2 and LO 7.2.5.2 on OpenSUSE 15.3 64bit rpm Linux.

Spaces have been added because it is a CHAR()-field with defined length. But the length, which is currently added by spaces, will be the wrong length. Looks like a bug with UTF8.

Example: To a CHAR(10) field with 10 characters will be added 30 spaces.
Comment 2 Alex Thurgood 2022-04-13 10:12:00 UTC
*** Bug 120640 has been marked as a duplicate of this bug. ***
Comment 3 Alex Thurgood 2022-04-13 10:19:07 UTC
This is wontfix in the firebird bug tracker. The devs there don't consider it to be a bug - the function is working as designed as it is related to the character encoding, so padding occurs according to the number of bytes in which any given character is written.
Comment 4 Andreas Heinisch 2022-04-13 14:39:29 UTC
I thought it would be enough to set the UTF8 character set to the connection string. Apparently, this is already the case in Connection::construct [1].

I tried to just divide the sqllen by 4 (UTF8 ) in firebird::mallocSQLVAR [2] but it does not work because system queries sometimes return not a multiple of 4.

Maybe the tables and columns were created a different character set.

[1]https://opengrok.libreoffice.org/xref/core/connectivity/source/drivers/firebird/Connection.cxx?r=840b4eb2#222
[2]https://opengrok.libreoffice.org/xref/core/connectivity/source/drivers/firebird/Util.cxx?r=3a88b513#296
Comment 5 Robert Großkopf 2022-04-13 17:30:11 UTC
CHAR_LENGTH() will give the expected value for type CHAR. It will be the same value as defined in the table. But the field will be filled with spaces like it would have if using "normal ASCII". So a field defined for length 3 has 3 defined characters and 9 spaces. There will appear an error if I try to input 4 characters in such a field:

firebird_sdbc error:
*Dynamic SQL Error
*SQL error code = -303
*arithmetic exception, numeric overflow, or string truncation
*string right truncation
*expected length 3, actual 12

So it counts the right length together with the spaces. But if I delete the just added (4.) character it will save the content.