Skip to content

Commit b39481f

Browse files
author
Jim Hamill
committed
Lots of changes
1 parent 51b4554 commit b39481f

18 files changed

+573
-89
lines changed

Database.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

Database.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

DatabaseConnectionWidget.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool DatabaseConnectionWidget::createSshTunnel(QString hostname, int remotePort,
6363
m_sshTunnel.start("ssh", arguments);
6464

6565
// Wait until finished
66-
if (!m_sshTunnel.waitForFinished(20000)) {
66+
if (!m_sshTunnel.waitForFinished(30000)) {
6767
return false;
6868
}
6969

@@ -137,16 +137,28 @@ bool DatabaseConnectionWidget::importDatabase()
137137
}
138138

139139
// File data
140-
QByteArray fileData = file.readAll();
140+
//QByteArray fileData = file.readAll();
141+
QByteArray decompressed;
141142

142143
// Decompress if it is a gzip file
143144
QFileInfo fileInfo(fileName);
144145
if (fileInfo.suffix() == "gz") {
145-
fileData = QCompressor::gzDecompress(fileData);//if (!QCompressor::gzipDecompress(file.readAll(), fileData)) {
146+
/*if (!QCompressor::gzipDecompress(fileData, decompressed)) {
147+
return false;
148+
}*/
149+
150+
//decompressed = QCompressor::gzDecompress(fileData);
151+
152+
//qDebug() << decompressed;
153+
154+
// Let the user know that this is broken
155+
QMessageBox::warning(this, "Operation Failed", "Compressed databases are not supported at this time.");
156+
157+
return false;
146158
}
147159

148160
// Read string from file and feed into splitter
149-
SQLSplitter splitter(fileData);
161+
SQLSplitter splitter(&file);
150162

151163
// Create Progress Dialog
152164
QProgressDialog progress("Importing database...", "Abort", 0, splitter.getLength());
@@ -172,6 +184,9 @@ bool DatabaseConnectionWidget::importDatabase()
172184

173185
// Increment progress bar value
174186
progress.setValue(splitter.getPosition());
187+
188+
// Update our event loop so that progress dialog updates
189+
QCoreApplication::processEvents();
175190
}
176191

177192
// Let the user know the code has been run

Extension/MySQLExtension.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ int MySQLExtension::createTable(QString table)
180180
// Run the drop query
181181
QSqlQuery query = m_database->exec("CREATE TABLE " + table + "(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id))");
182182

183+
// Check if there was an error and display it if there was
184+
if (query.lastError().type() != QSqlError::NoError) {
185+
QMessageBox::critical(qApp->activeWindow(), "Operation failed", query.lastError().text());
186+
}
187+
183188
return true;
184189
}
185190

@@ -188,6 +193,11 @@ int MySQLExtension::removeTable(QString table)
188193
// Run the drop query
189194
QSqlQuery query = m_database->exec("SET foreign_key_checks = 0; DROP TABLE " + table + "; SET foreign_key_checks = 1;");
190195

196+
// Check if there was an error and display it if there was
197+
if (query.lastError().type() != QSqlError::NoError) {
198+
QMessageBox::critical(qApp->activeWindow(), "Operation failed", query.lastError().text());
199+
}
200+
191201
return true;
192202
}
193203

@@ -196,6 +206,11 @@ int MySQLExtension::renameTable(QString from, QString to)
196206
// Run the rename query
197207
QSqlQuery query = m_database->exec("RENAME TABLE " + from + " TO " + to);
198208

209+
// Check if there was an error and display it if there was
210+
if (query.lastError().type() != QSqlError::NoError) {
211+
QMessageBox::critical(qApp->activeWindow(), "Operation failed", query.lastError().text());
212+
}
213+
199214
return true;
200215
}
201216

@@ -265,6 +280,11 @@ int MySQLExtension::addColumn(QString table, QString name, QString type, int len
265280
// Run the add column query
266281
QSqlQuery query = m_database->exec(queryString);
267282

283+
// Check if there was an error and display it if there was
284+
if (query.lastError().type() != QSqlError::NoError) {
285+
QMessageBox::critical(qApp->activeWindow(), "Operation failed", query.lastError().text());
286+
}
287+
268288
return true;
269289
}
270290

@@ -273,6 +293,11 @@ int MySQLExtension::removeColumn(QString table, QString column)
273293
// Run the rename query
274294
QSqlQuery query = m_database->exec("ALTER TABLE " + table + " DROP COLUMN " + column);
275295

296+
// Check if there was an error and display it if there was
297+
if (query.lastError().type() != QSqlError::NoError) {
298+
QMessageBox::critical(qApp->activeWindow(), "Operation failed", query.lastError().text());
299+
}
300+
276301
return true;
277302
}
278303

@@ -301,10 +326,10 @@ int MySQLExtension::alterColumn(QString table, QString oldName, QString newName,
301326
// Run the add column query
302327
QSqlQuery query = m_database->exec(queryString);
303328

304-
return true;
305-
}
329+
// Check if there was an error and display it if there was
330+
if (query.lastError().type() != QSqlError::NoError) {
331+
QMessageBox::critical(qApp->activeWindow(), "Operation failed", query.lastError().text());
332+
}
306333

307-
SchemaWidget* MySQLExtension::createSchemaWidget(QWidget *parent)
308-
{
309-
return new MySQLSchemaWidget(parent, m_database);
334+
return true;
310335
}

OpenConnectionDialog.cpp

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <QSqlDatabase>
55
#include <QFileDialog>
66
#include <QSettings>
7+
#include <QStandardPaths>
78
#include <QDebug>
89

910
OpenConnectionDialog::OpenConnectionDialog(QWidget *parent) :
@@ -120,6 +121,12 @@ void OpenConnectionDialog::on_driverCombo_currentIndexChanged(const QString &arg
120121
ui->portSpinBox->setEnabled(true);
121122
ui->portSpinBox->setValue(3306);
122123
ui->sshTunnelCheckBox->setEnabled(true);
124+
125+
// Check to see if ssh is on this computer
126+
if (QStandardPaths::findExecutable("ssh").isEmpty()) {
127+
ui->sshTunnelCheckBox->setEnabled(false);
128+
ui->sshTunnelCheckBox->setToolTip("SSH could not be found on this machine.");
129+
}
123130
}
124131
}
125132

@@ -315,28 +322,3 @@ void OpenConnectionDialog::on_sshTunnelCheckBox_toggled(bool checked)
315322
ui->hostnameEdit->setText("127.0.0.1");
316323
}
317324
}
318-
319-
void OpenConnectionDialog::initDatabase()
320-
{
321-
QString connectionsQuery =
322-
"CREATE TABLE connections(id INT PRIMARY KEY NOT NULL,"
323-
" driver TEXT NOT NULL,"
324-
" name TEXT NOT NULL,"
325-
" database TEXT NOT NULL,"
326-
" username TEXT,"
327-
" password TEXT,"
328-
" hostname TEXT,"
329-
" port INTEGER,"
330-
" sshTunnel INTEGER,"
331-
" sshHostname TEXT,"
332-
" sshPort INTEGER"
333-
" );";
334-
335-
QString savedQuery =
336-
"CREATE TABLE saved(id INTEGER PRIMARY KEY NOT NULL,"
337-
" name TEXT NOT NULL,"
338-
" command TEXT NOT NULL,"
339-
" connection_id INTEGER NOT NULL"
340-
" FOREIGN KEY(connection_id) REFERENCES connections(id)"
341-
" );";
342-
}

OpenConnectionDialog.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ private slots:
6868
private:
6969
void reloadConnections();
7070

71-
void initDatabase();
72-
7371
private:
7472
Ui::OpenConnectionDialog *ui;
7573

0 commit comments

Comments
 (0)