try to fix mariadb encoding problem
This commit is contained in:
parent
8f2715bd33
commit
70b518e839
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,11 +42,13 @@ class MariaDbDriver : public DatabaseDriver {
|
|||||||
QString interpretErrorCode(MariaDbError error_code) const;
|
QString interpretErrorCode(MariaDbError error_code) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool updateDatabaseSchema(QSqlQuery &query,
|
bool updateDatabaseSchema(QSqlQuery& query,
|
||||||
const QString& source_db_schema_version,
|
const QString& source_db_schema_version,
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user