diff --git a/PgsqlConn.cpp b/PgsqlConn.cpp index 8a73292..e63dcaf 100644 --- a/PgsqlConn.cpp +++ b/PgsqlConn.cpp @@ -122,6 +122,26 @@ ErrorDetails Result::diagDetails() return ErrorDetails::createErrorDetailsFromPGresult(result); } +int Result::tuplesAffected() const +{ + int i; + char * res = PQcmdTuples(result); + if (res) { + try { + i = std::stoi(res); + } + catch (std::invalid_argument& ) { + i = -1; + } + catch (std::out_of_range& ) { + i = -1; + } + } + else { + i = -1; + } + return i; +} int Result::getRows() const { diff --git a/PgsqlConn.h b/PgsqlConn.h index c92797d..3a96a9d 100644 --- a/PgsqlConn.h +++ b/PgsqlConn.h @@ -113,7 +113,7 @@ namespace Pgsql { - + int tuplesAffected() const; int getRows() const; int getCols() const; diff --git a/mainwindow.cpp b/mainwindow.cpp index 8f011ed..74956a9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -25,7 +25,7 @@ namespace { { QString unit; float val; - int deci = 3; + int deci = 2; if (ms < 1.0f) { val = ms * 1000.f; //result = QString::asprintf("%0.3f", ms * 1000.0f); @@ -53,14 +53,15 @@ namespace { unit = "ms"; } - if (val >= 1000.f) { +// if (val >= 1000.f) { +// deci = 0; +// } +// else + if (val >= 100.f) { deci = 0; } - else if (val >= 100.f) { - deci = 1; - } else if (val >= 10.f) { - deci = 2; + deci = 1; } QString result = QString::asprintf("%0.*f", deci, val); return result + unit; @@ -238,38 +239,46 @@ void MainWindow::query_ready(std::shared_ptr dbres) statusBar()->showMessage(tr("Query ready.")); } else { - if (st == PGRES_EMPTY_QUERY) { - statusBar()->showMessage(tr("Empty query.")); - } - else if (st == PGRES_COMMAND_OK) { + if (st == PGRES_COMMAND_OK) { statusBar()->showMessage(tr("Command OK.")); - } - else if (st == PGRES_COPY_OUT) { - statusBar()->showMessage(tr("COPY OUT.")); - } - else if (st == PGRES_COPY_IN) { - statusBar()->showMessage(tr("COPY IN.")); - } - else if (st == PGRES_BAD_RESPONSE) { - statusBar()->showMessage(tr("BAD RESPONSE.")); - } - else if (st == PGRES_NONFATAL_ERROR) { - statusBar()->showMessage(tr("NON FATAL ERROR.")); - } - else if (st == PGRES_FATAL_ERROR) { - statusBar()->showMessage(tr("FATAL ERROR.")); - } - else if (st == PGRES_COPY_BOTH) { - statusBar()->showMessage(tr("COPY BOTH shouldn't happen is for replication.")); - } - else if (st == PGRES_SINGLE_TUPLE) { - statusBar()->showMessage(tr("SINGLE TUPLE result.")); + QString msg = tr("Query returned succesfully: %1 rows affected, %2 execution time.") + .arg(QString::number(dbres->tuplesAffected())) + .arg(msfloatToHumanReadableString(elapsedTime.count())); + ui->messagesEdit->append(msg); + + ui->tabWidget->setCurrentWidget(ui->messageTab); } else { - statusBar()->showMessage(tr("No tuples returned, possibly an error...")); + if (st == PGRES_EMPTY_QUERY) { + statusBar()->showMessage(tr("Empty query.")); + } + else if (st == PGRES_COPY_OUT) { + statusBar()->showMessage(tr("COPY OUT.")); + } + else if (st == PGRES_COPY_IN) { + statusBar()->showMessage(tr("COPY IN.")); + } + else if (st == PGRES_BAD_RESPONSE) { + statusBar()->showMessage(tr("BAD RESPONSE.")); + } + else if (st == PGRES_NONFATAL_ERROR) { + statusBar()->showMessage(tr("NON FATAL ERROR.")); + } + else if (st == PGRES_FATAL_ERROR) { + statusBar()->showMessage(tr("FATAL ERROR.")); + } + else if (st == PGRES_COPY_BOTH) { + statusBar()->showMessage(tr("COPY BOTH shouldn't happen is for replication.")); + } + else if (st == PGRES_SINGLE_TUPLE) { + statusBar()->showMessage(tr("SINGLE TUPLE result.")); + } + else { + statusBar()->showMessage(tr("No tuples returned, possibly an error...")); + } + ui->tabWidget->setCurrentWidget(ui->messageTab); + receiveNotice(dbres->diagDetails()); } - ui->tabWidget->setCurrentWidget(ui->messageTab); - receiveNotice(dbres->diagDetails()); } } else { @@ -382,6 +391,7 @@ void MainWindow::updateTimer() { auto nu = std::chrono::steady_clock::now(); std::chrono::duration diff = nu - m_startTime; + elapsedTime = diff; m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count())); diff --git a/mainwindow.h b/mainwindow.h index 7bde69c..2a834a1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -10,6 +10,7 @@ #include #include #include "PgsqlConn.h" +#include #include #include @@ -50,6 +51,7 @@ private: void startTimer(); void endTimer(); + std::chrono::duration elapsedTime; Ui::MainWindow *ui; diff --git a/sqlhighlighter.cpp b/sqlhighlighter.cpp index 1aca454..898bc2e 100644 --- a/sqlhighlighter.cpp +++ b/sqlhighlighter.cpp @@ -22,7 +22,7 @@ SqlHighlighter::SqlHighlighter(QTextDocument *parent) : QSyntaxHighlighter(parent) { // { - static auto keywords = R"-(as|alter|all|and|any|by|column|create|database|from|group|having|in|not|or|order|select|table|where|(?:(?:inner|(?:left|right|full)(\s+outer)?)\s+)?join)-"; + static auto keywords = R"-(as|alter|all|and|any|by|column|create|database|delete|from|group|having|in|not|or|order|select|set|table|update|where|(?:(?:inner|(?:left|right|full)(\s+outer)?)\s+)?join)-"; // static auto types = R"-(bigint|boolean|char|character varying|date|int[248]|integer|numeric|smallint|time|timestamp(?:tz)?|timestamp(?:\s+with\s+timezone)?|varchar)-"; // static auto err = R"-(left|right|inner|outer)-";