If there is a selection in the query then only that part is Executed or explained.
Replaced QTextEdit with QPLainTextEdit as it is more efficient and CAN do syntax highlighting.
This commit is contained in:
parent
c555182ddd
commit
5831f18008
5 changed files with 44 additions and 39 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#include "sqlhighlighter.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QFileDialog>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QTextStream>
|
||||
#include <QTextTable>
|
||||
#include <QTimer>
|
||||
|
|
@ -93,6 +94,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
font.setPointSize(10);
|
||||
ui->queryEdit->setFont(font);
|
||||
highlighter.reset(new SqlHighlighter(ui->queryEdit->document()));
|
||||
|
||||
// ui->queryEdit->setPlainText(test_query);
|
||||
// ui->connectionStringEdit->setText("user=postgres dbname=foutrapport password=admin");
|
||||
|
||||
|
|
@ -191,6 +193,19 @@ void MainWindow::startConnect()
|
|||
m_dbConnection.setupConnection(m_config);
|
||||
}
|
||||
|
||||
std::string MainWindow::getCommand() const
|
||||
{
|
||||
QString command;
|
||||
QTextCursor cursor = ui->queryEdit->textCursor();
|
||||
if (cursor.hasSelection()) {
|
||||
command = cursor.selection().toPlainText();
|
||||
}
|
||||
else {
|
||||
command = ui->queryEdit->toPlainText();
|
||||
}
|
||||
return command.toUtf8().data();
|
||||
}
|
||||
|
||||
void MainWindow::performQuery()
|
||||
{
|
||||
if (m_dbConnection.state() == ASyncDBConnection::State::Connected) {
|
||||
|
|
@ -200,9 +215,7 @@ void MainWindow::performQuery()
|
|||
resultModel.reset();
|
||||
ui->messagesEdit->clear();
|
||||
|
||||
|
||||
QString command = ui->queryEdit->toPlainText();
|
||||
std::string cmd = command.toUtf8().data();
|
||||
std::string cmd = getCommand();
|
||||
startTimer();
|
||||
m_dbConnection.send(cmd,
|
||||
[this](std::shared_ptr<Pgsql::Result> res)
|
||||
|
|
@ -274,9 +287,7 @@ void MainWindow::performExplain()
|
|||
addLog("Explain clicked");
|
||||
|
||||
startTimer();
|
||||
QString command = "EXPLAIN (ANALYZE, VERBOSE, BUFFERS, FORMAT JSON) ";
|
||||
command += ui->queryEdit->toPlainText();
|
||||
std::string cmd = command.toUtf8().data();
|
||||
std::string cmd = "EXPLAIN (ANALYZE, VERBOSE, BUFFERS, FORMAT JSON) " + getCommand();
|
||||
m_dbConnection.send(cmd,
|
||||
[this](std::shared_ptr<Pgsql::Result> res)
|
||||
{
|
||||
|
|
@ -410,7 +421,7 @@ void MainWindow::on_actionLoad_SQL_triggered()
|
|||
ui->queryEdit->clear();
|
||||
while (!stream.atEnd()){
|
||||
QString line = stream.readLine();
|
||||
ui->queryEdit->append(line);
|
||||
ui->queryEdit->appendPlainText(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue