Skip to content

Permit connection to MariaDB 10.10 #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Permit connection to MariaDB 10.10 #51

wants to merge 1 commit into from

Conversation

rusher
Copy link

@rusher rusher commented Apr 21, 2023

Driver cannot even connect to MariaDB 10.10+, connection fails with error :

[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +57
MySql.Data.MySqlClient.Driver.LoadCharacterSets(MySqlConnection connection) +557
MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) +200
MySql.Data.MySqlClient.MySqlConnection.Open() +1341

the reason is MariaDB 10.10 supports Unicode 14 with Collations that can have null id/null characters:

show collation where COLLATION like 'uca14%';
+--------------------------------+---------+------+---------+----------+---------+
| Collation                      | Charset | Id   | Default | Compiled | Sortlen |
+--------------------------------+---------+------+---------+----------+---------+
| uca1400_ai_ci                  | NULL    | NULL | NULL    | Yes      |       8 |
| uca1400_ai_cs                  | NULL    | NULL | NULL    | Yes      |       8 |
| uca1400_as_ci                  | NULL    | NULL | NULL    | Yes      |       8 |
| uca1400_as_cs                  | NULL    | NULL | NULL    | Yes      |       8 |
...

Since 10.10, some collation have null id in I_S.COLLATIONS/SHOW COLLATIONS.
ID's only appear in I_S.COLLATION_CHARACTER_SET_APPLICABILITY, associate to charset.
example:

 SELECT * FROM INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY WHERE COLLATION_NAME LIKE 'uca1400_ai_ci';
 +----------------+--------------------+-----------------------+------+------------+
 | COLLATION_NAME | CHARACTER_SET_NAME | FULL_COLLATION_NAME   | ID   | IS_DEFAULT |
 +----------------+--------------------+-----------------------+------+------------+
 | uca1400_ai_ci  | utf8mb3            | utf8mb3_uca1400_ai_ci | 2048 |            |
 | uca1400_ai_ci  | ucs2               | ucs2_uca1400_ai_ci    | 2560 |            |
 | uca1400_ai_ci  | utf8mb4            | utf8mb4_uca1400_ai_ci | 2304 |            |
 | uca1400_ai_ci  | utf16              | utf16_uca1400_ai_ci   | 2816 |            |
 | uca1400_ai_ci  | utf32              | utf32_uca1400_ai_ci   | 3072 |            |
 +----------------+--------------------+-----------------------+------+------------+

This simple fix correct this connection problem

Driver cannot even connect to MariaDB 10.10+, connection fails with error :

```
[InvalidCastException: Object cannot be cast from DBNull to other types.]
System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +57
MySql.Data.MySqlClient.Driver.LoadCharacterSets(MySqlConnection connection) +557
MySql.Data.MySqlClient.Driver.Configure(MySqlConnection connection) +200
MySql.Data.MySqlClient.MySqlConnection.Open() +1341
```

the reason is MariaDB 10.10 supports Unicode 14 with Collations that can have null id/null characters:

```sql
show collation where COLLATION like 'uca14%';
+--------------------------------+---------+------+---------+----------+---------+
| Collation                      | Charset | Id   | Default | Compiled | Sortlen |
+--------------------------------+---------+------+---------+----------+---------+
| uca1400_ai_ci                  | NULL    | NULL | NULL    | Yes      |       8 |
| uca1400_ai_cs                  | NULL    | NULL | NULL    | Yes      |       8 |
| uca1400_as_ci                  | NULL    | NULL | NULL    | Yes      |       8 |
| uca1400_as_cs                  | NULL    | NULL | NULL    | Yes      |       8 |
...
```

collation ids depends on charset (see in I_S.COLLATION_CHARACTER_SET_APPLICABILITY)
 ``sql
 SELECT * FROM INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY WHERE COLLATION_NAME LIKE 'uca1400_ai_ci';
 +----------------+--------------------+-----------------------+------+------------+
 | COLLATION_NAME | CHARACTER_SET_NAME | FULL_COLLATION_NAME   | ID   | IS_DEFAULT |
 +----------------+--------------------+-----------------------+------+------------+
 | uca1400_ai_ci  | utf8mb3            | utf8mb3_uca1400_ai_ci | 2048 |            |
 | uca1400_ai_ci  | ucs2               | ucs2_uca1400_ai_ci    | 2560 |            |
 | uca1400_ai_ci  | utf8mb4            | utf8mb4_uca1400_ai_ci | 2304 |            |
 | uca1400_ai_ci  | utf16              | utf16_uca1400_ai_ci   | 2816 |            |
 | uca1400_ai_ci  | utf32              | utf32_uca1400_ai_ci   | 3072 |            |
 +----------------+--------------------+-----------------------+------+------------+
 ```

(Description is more complex than the fix)
@mysql-oca-bot
Copy link

Hi, thank you for submitting this pull request. In order to consider your code we need you to sign the Oracle Contribution Agreement (OCA). Please review the details and follow the instructions at https://oca.opensource.oracle.com/
Please make sure to include your MySQL bug system user (email) in the returned form.
Thanks

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@rusher
Copy link
Author

rusher commented May 2, 2023

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@unglaublicherdude
Copy link

This PR helped us making a hotifx-package into our local nuget repository. I would appreciate having the official fix at nuget.org.
@rusher thank's for the work!

@mysql-oca-bot
Copy link

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=110898 for updates.
Thanks

@alvaromarithompson
Copy link

Mysql Connector has become unusable on MariaDB 10.10.1+ without this fix, would appreciate it pushing through to the main release.

Thanks @rusher for the fix.

@perplexityjeff
Copy link

Are there any updates regarding this fix?

@JeanRessouche
Copy link

Up, this is a blocking issue

@alvaromarithompson
Copy link

I doubt anyone's reading this thread, comments are probably better posted on http://bugs.mysql.com/bug.php?id=110898

(I am also awaiting this to make its way to the next release, it's blocking our upgrade to Debian 12)

@bgrainger
Copy link

A potential workaround for anyone affected by this bug is to switch to the alternative ADO.NET library: https://github.com/mysql-net/MySqlConnector, https://mysqlconnector.net/tutorials/migrating-from-connector-net/

(Disclaimer: I am the lead author of MySqlConnector)

@alexbn71
Copy link

Does MySqlConnector support session parameters?

@bgrainger
Copy link

@alexbn71 You should ask questions about MySqlConnector at its repo: https://github.com/mysql-net/MySqlConnector/discussions

(And, yes it does.)

@sistemasIHS
Copy link

Alguien sabe si esto, ya entro en alguna version, he intentado cambiar a MySql Connector, pero me genera otro error el cual no he encontrado solucion.

@alvaromarithompson
Copy link

Still no fix for this issue.

@rusher
Copy link
Author

rusher commented Mar 20, 2024

MariaDB is compatible now, add a trick for MySQL.Data connector (see https://jira.mariadb.org/browse/MDEV-31608) but this need MariaDB 10.11.7+ version, not 10.10

@alvaromarithompson
Copy link

alvaromarithompson commented Mar 20, 2024

It's probably worth moving to MySqlConnector, as quoted in this thread here https://bugs.mysql.com/bug.php?id=109331 the .NET connector from the MySQL Dev team now focuses only on MySQL and not any developments in MariaDB:

MySQL and MariaDB are diverging products and compatibility is no longer guaranteed and is not a common objective of both projects. 
MariaDB is not a drop-in replacement of MySQL anymore.

Storage engines, protocol, etc.. all are going in different directions.

Therefore MySQL Connectors are developed with MySQL Server (Community, Enterprise) focus.

This problem will not be fixed by the official release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants