try to fix mariadb encoding problem

This commit is contained in:
Martin Rotter 2022-01-18 11:28:38 +01:00
parent 8f2715bd33
commit 70b518e839
2 changed files with 14 additions and 1 deletions

View File

@ -162,6 +162,7 @@ QSqlDatabase MariaDbDriver::initializeDatabase(const QString& connection_name) {
QSqlQuery query_db(database); QSqlQuery query_db(database);
query_db.setForwardOnly(true); query_db.setForwardOnly(true);
setPragmas(query_db);
if (!query_db.exec(QSL("USE %1").arg(database_name)) || if (!query_db.exec(QSL("USE %1").arg(database_name)) ||
!query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"))) { !query_db.exec(QSL("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'"))) {
@ -214,6 +215,11 @@ QSqlDatabase MariaDbDriver::initializeDatabase(const QString& connection_name) {
return database; return database;
} }
void MariaDbDriver::setPragmas(QSqlQuery& query) {
query.exec(QSL("SET NAMES 'utf8mb4';"));
query.exec(QSL("SET CHARACTER SET utf8mb4;"));
}
bool MariaDbDriver::updateDatabaseSchema(QSqlQuery& query, bool MariaDbDriver::updateDatabaseSchema(QSqlQuery& query,
const QString& source_db_schema_version, const QString& source_db_schema_version,
const QString& database_name) { const QString& database_name) {
@ -295,6 +301,11 @@ QSqlDatabase MariaDbDriver::connection(const QString& connection_name, DatabaseD
<< "seems to be established."; << "seems to be established.";
} }
QSqlQuery query_db(database);
query_db.setForwardOnly(true);
setPragmas(query_db);
return database; return database;
} }
} }

View File

@ -47,6 +47,8 @@ class MariaDbDriver : public DatabaseDriver {
const QString& database_name); const QString& database_name);
QSqlDatabase initializeDatabase(const QString& connection_name); QSqlDatabase initializeDatabase(const QString& connection_name);
void setPragmas(QSqlQuery& query);
private: private:
bool m_databaseInitialized; bool m_databaseInitialized;
}; };