mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Настройки базы данных теперь в xml
This commit is contained in:
@@ -21,14 +21,16 @@ bool DataBaseLMS::createConnection()
|
||||
{
|
||||
mtxAccess.lock();
|
||||
|
||||
db = new QSqlDatabase(QSqlDatabase::addDatabase(dbType, connectionName));
|
||||
db->setDatabaseName(dbName);
|
||||
db->setUserName(dbUserName);
|
||||
db->setPassword(dbPassword);
|
||||
db->setPort(5432);
|
||||
//db->setHostName("192.168.100.87");
|
||||
//db->setHostName("192.168.100.248");
|
||||
db->setHostName("192.168.100.239");
|
||||
dbSettings = getDataBaseSettings();
|
||||
|
||||
dbSettings.connectionName = "Connection_" + dbSettings.dbName;
|
||||
|
||||
db = new QSqlDatabase(QSqlDatabase::addDatabase(dbSettings.dbType, dbSettings.connectionName));
|
||||
db->setDatabaseName(dbSettings.dbName);
|
||||
db->setUserName(dbSettings.dbUserName);
|
||||
db->setPassword(dbSettings.dbPassword);
|
||||
db->setHostName(dbSettings.dbHostName);
|
||||
db->setPort(dbSettings.dbPort);
|
||||
|
||||
bool res = db->open();
|
||||
|
||||
@@ -91,6 +93,63 @@ bool DataBaseLMS::isConnected()
|
||||
return false;
|
||||
}
|
||||
|
||||
DataBaseSettings DataBaseLMS::getDataBaseSettings()
|
||||
{
|
||||
DataBaseSettings settings;
|
||||
QFile file("config/settings.xml");
|
||||
if(!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QMessageBox::critical(nullptr, "Attention!", "The file could not be opened: config/settings.xml");
|
||||
return settings;
|
||||
}
|
||||
QXmlStreamReader xmlReader(&file);
|
||||
|
||||
while (!xmlReader.atEnd()){
|
||||
|
||||
if(xmlReader.isStartElement()){
|
||||
|
||||
if(xmlReader.name() == "DataBaseSettings")
|
||||
{
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes()){
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Type"){
|
||||
settings.dbType = value;
|
||||
}
|
||||
|
||||
if(name == "Name"){
|
||||
settings.dbName = value;
|
||||
}
|
||||
|
||||
if(name == "UserName"){
|
||||
settings.dbUserName = value;
|
||||
}
|
||||
|
||||
if(name == "Password"){
|
||||
settings.dbPassword = value;
|
||||
}
|
||||
|
||||
if(name == "HostName"){
|
||||
settings.dbHostName = value;
|
||||
}
|
||||
|
||||
if(name == "Port"){
|
||||
settings.dbPort = value.toInt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
file.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
bool DataBaseLMS::transactionBegin()
|
||||
{
|
||||
/*
|
||||
@@ -1138,7 +1197,7 @@ bool DataBaseLMS::queryExec(QString queryStr, QSqlQuery *query)
|
||||
|
||||
void DataBaseLMS::messageWarningErrorQuery(QString queryStr, QSqlQuery* query)
|
||||
{
|
||||
QMessageBox::warning(nullptr, dbName,
|
||||
QMessageBox::warning(nullptr, dbSettings.dbName,
|
||||
"Error query:\n" + query->lastError().text() + "\n" +
|
||||
"String of query:\n" + queryStr + "\n" +
|
||||
"Executed query:\n" + query->executedQuery());
|
||||
|
||||
Reference in New Issue
Block a user