Bug 165928 - MySQL/MariaDB direct Connection: Impossible to save VARCHAR with more than 255 Characters
Summary: MySQL/MariaDB direct Connection: Impossible to save VARCHAR with more than 25...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Base (show other bugs)
Version:
(earliest affected)
25.2.1.2 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Julien Nabet
URL:
Whiteboard: target:25.8.0 target:25.2.3
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-27 10:34 UTC by Robert Großkopf
Modified: 2025-04-09 13:31 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 Robert Großkopf 2025-03-27 10:34:57 UTC
Open a Base file with direct connection to MariaDB.
Create a table.
Try to create a varchar field with more than 255.
Couldn't be created.
Base would show ENUM instead of VARCHAR, if VARCHAR(1000) (or more) has been created with PHPMyAdmin.

Note from https://mariadb.com/kb/en/varchar/:
A variable-length string. M represents the maximum column length in characters. The range of M is 0 to 65,532. The effective maximum length of a VARCHAR is subject to the maximum row size and the character set used. For example, utf8 characters can require up to three bytes per character, so a VARCHAR column that uses the utf8 character set can be declared to be a maximum of 21,844 characters.
Comment 1 Robert Großkopf 2025-03-27 13:43:50 UTC
Have had a look where the limit come from:
In MySQL 4 there had been a limit of 255 characters. Since MySQL 5.0 (and since the start of MariaDB with 5.1) the limit has been updated to 65535 characters. This happen in October 2005. 

We should update the limit for better handling.
Comment 2 Julien Nabet 2025-03-27 14:01:13 UTC
I've submitted a patch here:
https://gerrit.libreoffice.org/c/core/+/183400

(I put 65535)
Comment 3 Julien Nabet 2025-03-27 16:36:15 UTC
On Debian testing, I gave a try on phpmyadmin (Version: 4:5.2.2-really5.2.2+20250121+dfsg-1) with on MariaDB 11.8.1
and when trying to create a VARCHAR of 65535 characters, phpmyadmin displays an error proposing to use a BLOB since max length is 16383 (ie 65535 / 4 which must correspond to the max bytes which can be used by utf-8).

Has someone got Mysql (and not Mariadb) to compare?
Comment 4 Julien Nabet 2025-03-27 19:04:47 UTC
Just rethinking, I wonder if "precision" field means the number of bytes here and so 65535 would be ok or if it means the number of characters and in this case, it depends on the encoding.
Doing tests again with phpmyadmin, and when choosing one type of ucs2, it indicates this time max at 32766

Reading https://docs.oracle.com/javase/8/docs/api/java/sql/DatabaseMetaData.html:
"
The PRECISION column represents the specified column size for the given column. For numeric data, this is the maximum precision. For character data, this is the length in characters..."
So either we should find a way to retrieve the default encoding of the database
if it's possible (on my desktop on Mariadb, it seems to be utf8mb4_general_ci, so 4 bytes per character) or to try to be safe and use 16383.
Comment 5 Robert Großkopf 2025-03-27 20:47:55 UTC
(In reply to Julien Nabet from comment #4)

You could set it to 21844, as described on the homepage of MariaDB. Have a look at the bug description.

Its the same as discussed for Firebird. There could be set 32000, but we devided it by 4 to 8000 for utf-8
On description of MariaDB there is posted 3 bytes for a utf8 - so devided by 3 bytes…
If we say 4 bytes as maximum for a character it might also be 16383.

But all this solutions are much better than 255! Note there are fields for more text content. My problem appears because I have copied tables from internal Firebird to MariaDB and that won't work directly at this moment.
Comment 6 Julien Nabet 2025-03-27 21:21:27 UTC
(In reply to Robert Großkopf from comment #5)
> (In reply to Julien Nabet from comment #4)
...
> If we say 4 bytes as maximum for a character it might also be 16383.
> 
> But all this solutions are much better than 255! Note there are fields for
> more text content. My problem appears because I have copied tables from
> internal Firebird to MariaDB and that won't work directly at this moment.
Ok I put back 16383 to keep it safe and put some comments and a TODO in the code.
Comment 7 Commit Notification 2025-03-28 08:59:53 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4b7ddc149990f21a98deb8ba0cc6a97e62b201d7

tdf#165928: MySQL/MariaDB direct connection: VARCHAR can be > 255 characters

It will be available in 25.8.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 8 Julien Nabet 2025-03-28 09:46:35 UTC
Xisco cherry-picked the patch for 25.2 here:
https://gerrit.libreoffice.org/c/core/+/183439
=> let's put this one to FIXED.
Again, as put in the comment of the patch, ideally we should detect encoding to adjust the precision.
Comment 9 Commit Notification 2025-04-09 13:31:59 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/1ef0b26c70e2f5320829066350e8102e4d4f2a0e

tdf#165928: MySQL/MariaDB direct connection: VARCHAR can be > 255 characters

It will be available in 25.2.3.

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.