Fix SQL syntax error when using MariaDB 12.1
Hi all,
this is about and fixes Bug #512859. Please review this. For an end-user, this is severe breakage.
On a fresh Artix Linux installation, I encountered a problem whilst setting up KMail: Akonadi could not start. The problem was a syntax error:
$ akonadictl start
org.kde.pim.akonadictl: Starting Akonadi Server...
org.kde.pim.akonadictl: done.
Connecting to deprecated signal QDBusConnectionInterface::serviceOwnerChanged(QString,QString,QString)
qt.qpa.services: Failed to register with host portal QDBusError("org.freedesktop.portal.Error.Failed", "Could not register app ID: App info not found for 'org.kde.akonadi_control'")
org.kde.pim.akonadiserver: Starting up the Akonadi Server...
/usr/bin/mysqlcheck: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-check' instead
akonadi.collectionattributetable OK
akonadi.collectionmimetyperelation OK
akonadi.collectionpimitemrelation OK
akonadi.collectiontable OK
akonadi.flagtable OK
akonadi.mimetypetable OK
akonadi.parttable OK
akonadi.parttypetable OK
akonadi.pimitemflagrelation OK
akonadi.pimitemtable OK
akonadi.pimitemtagrelation OK
akonadi.resourcetable OK
akonadi.schemaversiontable OK
akonadi.tagattributetable OK
akonadi.tagremoteidresourcerelationtable OK
akonadi.tagtable OK
akonadi.tagtypetable OK
/usr/bin/mysql_upgrade: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-upgrade' instead
This installation of MariaDB is already upgraded to 12.1.2-MariaDB.
There is no need to run mariadb-upgrade again.
You can use --force if you still want to run mariadb-upgrade
org.kde.pim.akonadiserver: Running DB initializer
org.kde.pim.akonadiserver: DB initializer done
org.kde.pim.akonadiserver: Updating index failed:
Sql error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '2' at line 1 QMYSQL: Die Abfrage konnte nicht ausgeführt werden
Query: ALTER TABLE PimItemTable DROP FOREIGN KEY 2
org.kde.pim.akonadiserver: ""
org.kde.pim.akonadiserver: Unable to initialize database.
org.kde.pim.akonadiserver: Shutting down AkonadiServer...
org.kde.pim.akonadicontrol: Application '/usr/bin/akonadiserver' exited normally...
As far as I can grasp it, this change causes this: https://jira.mariadb.org/browse/MDEV-28933
Apparently, Arch Linux is also affected. At least, some people advise to configure Akonadi to use SQLite instead of MySQL/MariaDB to work around this.
Fixing this seems to be quite easy, the foreign key identifier just has to be quoted using backticks. A local build including said patch starts without a problem on my Artix machine. Interestingly, I run three other Artix machines, all on MariaDB 12.1 – without a problem. Maybe, this only happens if a database is newly set up. I'm neither a MariaDB nor an Akonadi pro though, so please have a look at this ;-)
Thanks in advance for fixing this. Maybe, distributors encountering this problem can port this back to their current version when this becomes an upstream patch.
Cheers, Tobias