Skip to content

Commit 17cd21b

Browse files
committed
Database: fix open mysql database bug
1 parent 74acd42 commit 17cd21b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Src/Database/Database.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ bool CDatabase::OpenSQLiteDatabase(const CParameterDatabase *pPara,
139139
bool CDatabase::OpenMySqlDatabase(const CParameterDatabase *pPara,
140140
const QString &szConnectName)
141141
{
142+
bool success = false;
142143
if(!pPara) return false;
143144

144145
if(!szConnectName.isEmpty())
@@ -154,7 +155,7 @@ bool CDatabase::OpenMySqlDatabase(const CParameterDatabase *pPara,
154155
szDbName = "remote_control";
155156
#endif
156157
}
157-
m_database.setDatabaseName(szDbName);
158+
158159
auto &net = pPara->m_Net;
159160
m_database.setHostName(net.GetHost());
160161
m_database.setPort(net.GetPort());
@@ -173,7 +174,7 @@ bool CDatabase::OpenMySqlDatabase(const CParameterDatabase *pPara,
173174
}
174175

175176
QSqlQuery query(GetDatabase());
176-
bool success = query.exec("CREATE DATABASE IF NOT EXISTS " + szDbName);
177+
success = query.exec("CREATE DATABASE IF NOT EXISTS " + szDbName);
177178
if (!success) {
178179
qCritical(log) << "Failed to create" << szDbName << "database:"
179180
<< query.lastError().text()
@@ -189,8 +190,11 @@ bool CDatabase::OpenMySqlDatabase(const CParameterDatabase *pPara,
189190
return false;
190191
}
191192

193+
m_database.setDatabaseName(szDbName);
192194
qInfo(log) << "Open mysql database connect:"
193195
<< m_database.connectionName()
196+
<< "Host:" << net.GetHost() << "Port:" << net.GetPort()
197+
<< "User:" << user.GetUser()
194198
<< "database name:" << m_database.databaseName();
195199

196200
return OnInitializeDatabase();

0 commit comments

Comments
 (0)