-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheadmin.cpp
More file actions
152 lines (121 loc) · 5.07 KB
/
Copy patheadmin.cpp
File metadata and controls
152 lines (121 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "eadmin.h"
#include "ui_eadmin.h"
#include <QMessageBox>
#include <QFileDialog>
EAdmin::EAdmin(EUser& user, QWidget *parent) :
QTabWidget(parent),
EUser(user),
ui(new Ui::EAdmin)
{
ui->setupUi(this);
qDebug("EAdmin constructor");
// connect(EDBconnection::getInstance(), SIGNAL(returnLastError(QString)), ui->result_te, SLOT(insertHtml(QString)));
connect(EDBconnection::getInstance(), SIGNAL(returnLastError(QString)), this, SLOT(showError(QString)));
// ui->result_te->insertHtml("<style type=”text/css”>p { line-height: 100px;}</style>");
process = new QProcess;
}
EAdmin::~EAdmin()
{
delete ui;
}
void EAdmin::on_execute_btn_clicked()
{
if (ui->query_tx->document()->isEmpty()) return;
QString query = ui->query_tx->toPlainText().trimmed();
// show query
qDebug()<<"query :"<<query;
ui->result_te->insertHtml("<p style=\"color: blue;\">"+query+" : </p>");
QString query_type = query.section(" ", 0, 0);
if (QString::compare(query_type, QString("SELECT"), Qt::CaseInsensitive) == 0) {
qDebug()<<"query_type :"<<query_type;
QList<QStringList> List = EDBconnection::getInstance()->get(query);
// :TODO добавить вывод названия колонок
if (!List.isEmpty()) {
if (List.length() == 1 && List[0].length() == 1) {
ui->result_te->insertHtml("<p>"+List[0].at(0)+"</p>");
} else {
QString html_table = "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\">";
for (int i = 0; i < List.length(); ++i) {
QString row;
for (int j = 0; j < List[0].length(); ++j) {
row += "<td>" + List[i].at(j) + "</td>";
}
html_table += "<tr>"+row+"</tr>";
}
html_table += "</table><br/><br/><br/>";
ui->result_te->insertHtml(html_table);
}
}
} else if (QString::compare(query_type, QString("INSERT"), Qt::CaseInsensitive) == 0
|| QString::compare(query_type, QString("REPLACE"), Qt::CaseInsensitive) == 0) {
// show last insert id
if (int last_id = EDBconnection::getInstance()->insert(query) != -1)
ui->result_te->insertHtml(QString("<p style=\"color: green;\">Last insert ID = %1 </p><br/><br/>").arg(last_id));
} else if (QString::compare(query_type, QString("UPDATE"), Qt::CaseInsensitive) == 0) {
} else {
// other queries {DELETE, i.e.}
QString query = ui->query_tx->toPlainText().trimmed();
bool error = EDBconnection::getInstance()->query(query);
if (error) ui->result_te->insertHtml("<p style=\"color: red;\">Error : EDBconnection::query(QString) return false;</p><br/><br/>");
}
}
void EAdmin::on_backup_btn_clicked()
{
// execute "mysqldump exlibris --user=root --password=********* > ./sql_log2.sql"
// QString param;
// param += " mysqldump ";
// param += db->get_dbName();
// param += " --host=" + db->get_dbHost();
// param += " --user=" + db->get_dbUser();
// param += " --password=" + db->get_dbPass();
// param += " --add-drop-table";
// param += " --complete-insert";
// param += " --triggers ";
QString fileName = QFileDialog::getSaveFileName(this, QObject::trUtf8("Save Backup"), "", QObject::trUtf8("Save Backup (*.sql)"));
qDebug()<<"filename :"<<fileName;
if (fileName.isEmpty()) return;
EDBconnection *db = EDBconnection::getInstance();
QStringList param;
param << db->get_dbName();
param << db->get_dbHost();
param << db->get_dbUser();
param << db->get_dbPass();
param << fileName;
qDebug()<<param;
process->execute("./dump_db", param);
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// show ERROR message
QMessageBox::warning(0, "Worning", "Ошибка.\nНельзя открыть файл.");
return;
}
QByteArray db_data = file.readAll();
ui->info_te->append(db_data);
}
void EAdmin::on_restore_btn_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, trUtf8("Restore from Backup"), "", trUtf8("Load Backup (*.sql)"));
qDebug()<<"filename :"<<fileName;
if (fileName.isEmpty()) return;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
// show ERROR message
QMessageBox::warning(0, "Worning", trUtf8("Ошибка.\nНельзя открыть файл."));
return;
}
QByteArray db_data = file.readAll();
ui->info_te->setPlainText(db_data);
EDBconnection *db = EDBconnection::getInstance();
QStringList param;
param << db->get_dbName();
param << db->get_dbHost();
param << db->get_dbUser();
param << db->get_dbPass();
param << fileName;
qDebug()<<param;
process->execute("./restore_db", param);
}
void EAdmin::showError(QString error)
{
ui->result_te->insertHtml("<p style=\"color: red; line-height: 10px;\">"+error+"</p><br/><br/>");
}