Bug 130376 - PostgreSQL JDBC and Direct Connection: Autoincrement doesn't return values in Queries with Alias
Summary: PostgreSQL JDBC and Direct Connection: Autoincrement doesn't return values in...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: dataLoss
Depends on:
Blocks: Database-Connectivity
  Show dependency treegraph
 
Reported: 2020-02-03 08:16 UTC by Robert Großkopf
Modified: 2024-11-11 07:48 UTC (History)
1 user (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 Robert Großkopf 2020-02-03 08:16:57 UTC
Don't know if this is a bug of LO or of the JDBC-Connector ...

You will need a connection to a PostgreSQL-database through JDBC.
Create a table like

CREATE TABLE "public"."Test" (
    "ID-Test" serial PRIMARY KEY,
    "Text" varchar(100) NULL
); 

Input some data into the table. Will work right, the primary key will be incremented.

Create a query 
SELECT "ID-Test", "Text" FROM "public"."Test" AS "a"

Start the query and input a value to the field "Text".
"ID-Test" will return '0'.
'0' will be returned for all new input.
Reload the data and the right values will appear.

Log-file of PostgreSQL will show this:
ERROR:  relation "a" does not exist at character 30
       STATEMENT:  SELECT MAX( "ID-Test" ) FROM "a"

The "normal" way to get the incremented value is like this, which will work in Tools - SQL:
INSERT INTO "public"."Test" AS "a" ("Text") VALUES ('Test') RETURNING "ID-Test";

This bug appears in all LO-Versions I have tested here - from LO 6.1.5 up to LO 6.4.0 on OpenSUSE 15.1 64bit rpm Linux.
Comment 1 Michael 2020-02-03 14:48:18 UTC
Found the same here, using
LO-BASE: Version: 6.1.5.2, Build-ID: 90f8dcf33c87b3705e78202e3df5142b201bd805, 
CPU-Threads: 4; BS: Linux 5.3; UI-Render: Standard; VCL: kde4; 
Gebietsschema: de-DE (de_DE.UTF-8); Calc: group threaded
PostgreSQL: PostgreSQL 10.10 (Ubuntu 10.10-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0, 64-bit

Additional information:
1) All variants for SQL-queries, having an Alias-Name in the FROM-clause cause that entry in the PostgreSQL-Log-file and  - as reported -  the ID for new entries is shown as 0; entering more than one record at a time, you'll see multiple ID-values = 0  below each other. Having this fault, I also found issues in BASE-Forms or Queries, where sometimes one ore more data fields get lost on saving.

2) The same SQL-query without Alias-Name in the FROM-clause works fine without entry in the PostgreSQL-Log-file, the ID is shown correct no data fields get lost anymore.

3) Using the same SQL-query WITH Alias-Name in the FROM-clause in DBeaver works fine without entry in the PostgreSQL-Log-file or any other issue.
Comment 2 Robert Großkopf 2020-02-06 19:39:53 UTC
Tested it a little bit more.
Executed the query of the bug-report.
Entered a new value in a new row in the field Text.
Saved the value by leaving the row.
ID-Test shows 0.
Changed the new value of Text in this field.
Saved this by leaving the row.
The old value will be shown again, the changed value has been lost.

Seems Base wants to make an update for a row with the primary-key 0, which doesn't exist.

This buggy behavior could lead to data loss!
Comment 3 Robert Großkopf 2020-02-09 08:12:06 UTC
This bug isn't only a bug of JDBC.
It will be the same for the direct connection.

If I connect to PostgreSQL through ODBC it won't appear if I won't set
Edit > Database > Advanced settings > Special settings
"Respect the result set type from the database driver" to true.

I have changed the summary to reflect this
Comment 4 QA Administrators 2022-02-09 03:41:12 UTC Comment hidden (obsolete)
Comment 5 Robert Großkopf 2022-02-09 06:44:06 UTC
Bug is still the same with LO 7.3.0.3

SELECT "ID-Test", "Text" FROM "public"."Test" AS "a"
will return '0' in "ID-Test" for every new row.

SELECT "ID-Test", "Text" FROM "public"."Test" AS "Test"
will work well. Could be it is because
SELECT "ID-Test", "Text" FROM "Test"
will work also.

Setting an Alias for the table will destroy the returning for input new values.

This will only appear in query GUI. Tools → SQL will work right.
Comment 6 QA Administrators 2024-11-11 03:13:00 UTC Comment hidden (obsolete)
Comment 7 Robert Großkopf 2024-11-11 07:48:06 UTC
Version: 24.8.3.1 (X86_64) / LibreOffice Community
Build ID: 65412f067af443213e726c93f137ccc85c9a1e06
CPU threads: 6; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded
Comment 8 Robert Großkopf 2024-11-11 07:48:30 UTC
Bug is still the same:
Version: 24.8.3.1 (X86_64) / LibreOffice Community
Build ID: 65412f067af443213e726c93f137ccc85c9a1e06
CPU threads: 6; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded