Bug 158452 - FIREBIRD: Impossible to change field to "entry required" in GUI after table has been saved
Summary: FIREBIRD: Impossible to change field to "entry required" in GUI after table h...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
7.4.7.2 release
Hardware: All All
: medium normal
Assignee: Julien Nabet
URL:
Whiteboard: target:24.2.0 target:7.6.5
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-30 10:09 UTC by Robert Großkopf
Modified: 2023-12-02 11:34 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Open table "Tabelle1" for editing. Try to set "Name" to required → yes. (3.43 KB, application/vnd.oasis.opendocument.database)
2023-11-30 10:09 UTC, Robert Großkopf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Großkopf 2023-11-30 10:09:29 UTC
Created attachment 191132 [details]
Open table "Tabelle1" for editing. Try to set "Name" to required → yes.

Open the attached database.
Open "Tabelle1" for editing, not for input data.
Change field "Name" in field Properties to → Entry required → 'yes'
Try to save the table.

An error appears:
The column "Name" could not be changed. Should the column instead be deleted and the new format appended?

Now go to Tools → SQL.
ALTER TABLE "Tabelle1" ALTER COLUMN "Name" SET NOT NULL;
Status will show the useless message
1: at /home/buildslave/source/libo-core/connectivity/source/drivers/firebird/StatementCommonBase.cxx:458
but the command will be submitted.

Go to View → Refresh Tables
and open "Tabelle1".
Field "Name" has set Entry required → 'yes'

It should be possible to set Entry required after a table has been edited and saved. HSQLDB offers this possibility. The error, which appears in Firebird, only shows: Changing isn't allowed by GUI.
Setting NOT NULL is the same code as required for HSQLDB.
Setting back to NULL requires
ALTER TABLE "Tabelle1" ALTER COLUMN "Name" DROP NOT NULL;
Comment 1 Julien Nabet 2023-12-01 15:07:24 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce this.

I noticed this on console:
warn:connectivity.firebird:558350:558350:connectivity/source/drivers/firebird/Util.cxx:58: firebird_sdbc error:
*UPDATE operation is not allowed for system table RDB$RELATION_FIELDS
caused by
'UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 WHERE RDB$FIELD_NAME = 'Name' AND RDB$RELATION_NAME = 'Tabelle1''


Searching in the code, I see:
    159             // Dirty hack: can't change null directly in sql, we have to fiddle
    160             // the system tables manually.
    161             if (nNullable == ColumnValue::NULLABLE)
    162             {
    163                 sSql = "UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = NULL "
    164                        "WHERE RDB$FIELD_NAME = '" + rColName + "' "
    165                        "AND RDB$RELATION_NAME = '" + getName() + "'";
    166             }
    167             else if (nNullable == ColumnValue::NO_NULLS)
    168             {
    169                 // And if we are making NOT NULL then we have to make sure we have
    170                 // no nulls left in the column.
    171                 OUString sFillNulls("UPDATE \"" + getName() + "\" SET \""
    172                                     + rColName + "\" = 0 "
    173                                     "WHERE \"" + rColName + "\" IS NULL");
    174                 getConnection()->createStatement()->execute(sFillNulls);
    175 
    176                 sSql = "UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1 "
    177                        "WHERE RDB$FIELD_NAME = '" + rColName + "' "
    178                        "AND RDB$RELATION_NAME = '" + getName() + "'";
    179             }
    180             getConnection()->createStatement()->execute(sSql);
(See https://opengrok.libreoffice.org/xref/core/connectivity/source/drivers/firebird/Table.cxx?r=299441fb#159)
This part comes from e6c4e419d6bc3572b183ca8ed3f2b75417899fff
Implement changing nullable. (firebird-sdbc)
(in 2013)

Reading https://stackoverflow.com/questions/74477356/how-to-remove-null-constraint-for-a-column-in-firebird-2-5, it seems due to the fact that with Firebird < 3, it wasn't possible to use alter table to make a column nullable or not.


Since the hack doesn't seem to work anyway, let's forget FB < 3 and use alter table syntax ; I'll give it a try.
Comment 2 Julien Nabet 2023-12-01 15:27:56 UTC
https://gerrit.libreoffice.org/c/core/+/160220
Comment 3 Commit Notification 2023-12-01 16:24:09 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/735b6b3861ed898dafa5c9d08400c37d1996283e

tdf#158452: FB: impossible to change field to "entry required" in GUI

It will be available in 24.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 4 Commit Notification 2023-12-02 11:34:49 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-7-6":

https://git.libreoffice.org/core/commit/6d782b57e0d8965dda279c2e73e2e91844f6f341

tdf#158452: FB: impossible to change field to "entry required" in GUI

It will be available in 7.6.5.

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.