Work around tms bugs with MariaDB

See https://doliforge.org/tracker/?func=detail&aid=1643&atid=246&group_id=144 and https://doliforge.org/tracker/?func=detail&aid=1644&atid=246&group_id=144.

I don't have a good understanding of what's happening here. Feel free to push a better fix if you do.