After an insert, update, delete the number of rows affected is reported.

This also makes it clearer the command was executed succesfully.

Times are now printed with no more then two decimals. This prevents confusion
between thousand and decimal seperators.
This commit is contained in:
Eelke Klein 2017-01-16 18:56:07 +01:00
parent 5831f18008
commit fa9787adfd
5 changed files with 68 additions and 36 deletions

View file

@ -122,6 +122,26 @@ ErrorDetails Result::diagDetails()
return ErrorDetails::createErrorDetailsFromPGresult(result); 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 int Result::getRows() const
{ {

View file

@ -113,7 +113,7 @@ namespace Pgsql {
int tuplesAffected() const;
int getRows() const; int getRows() const;
int getCols() const; int getCols() const;

View file

@ -25,7 +25,7 @@ namespace {
{ {
QString unit; QString unit;
float val; float val;
int deci = 3; int deci = 2;
if (ms < 1.0f) { if (ms < 1.0f) {
val = ms * 1000.f; val = ms * 1000.f;
//result = QString::asprintf("%0.3f", ms * 1000.0f); //result = QString::asprintf("%0.3f", ms * 1000.0f);
@ -53,14 +53,15 @@ namespace {
unit = "ms"; unit = "ms";
} }
if (val >= 1000.f) { // if (val >= 1000.f) {
// deci = 0;
// }
// else
if (val >= 100.f) {
deci = 0; deci = 0;
} }
else if (val >= 100.f) {
deci = 1;
}
else if (val >= 10.f) { else if (val >= 10.f) {
deci = 2; deci = 1;
} }
QString result = QString::asprintf("%0.*f", deci, val); QString result = QString::asprintf("%0.*f", deci, val);
return result + unit; return result + unit;
@ -237,13 +238,20 @@ void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
ui->tabWidget->setCurrentWidget(ui->dataTab); ui->tabWidget->setCurrentWidget(ui->dataTab);
statusBar()->showMessage(tr("Query ready.")); statusBar()->showMessage(tr("Query ready."));
} }
else {
if (st == PGRES_COMMAND_OK) {
statusBar()->showMessage(tr("Command OK."));
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 { else {
if (st == PGRES_EMPTY_QUERY) { if (st == PGRES_EMPTY_QUERY) {
statusBar()->showMessage(tr("Empty query.")); statusBar()->showMessage(tr("Empty query."));
} }
else if (st == PGRES_COMMAND_OK) {
statusBar()->showMessage(tr("Command OK."));
}
else if (st == PGRES_COPY_OUT) { else if (st == PGRES_COPY_OUT) {
statusBar()->showMessage(tr("COPY OUT.")); statusBar()->showMessage(tr("COPY OUT."));
} }
@ -272,6 +280,7 @@ void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
receiveNotice(dbres->diagDetails()); receiveNotice(dbres->diagDetails());
} }
} }
}
else { else {
addLog("query_ready with NO result"); addLog("query_ready with NO result");
statusBar()->showMessage(tr("Query cancelled.")); statusBar()->showMessage(tr("Query cancelled."));
@ -382,6 +391,7 @@ void MainWindow::updateTimer()
{ {
auto nu = std::chrono::steady_clock::now(); auto nu = std::chrono::steady_clock::now();
std::chrono::duration<float, std::milli> diff = nu - m_startTime; std::chrono::duration<float, std::milli> diff = nu - m_startTime;
elapsedTime = diff;
m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count())); m_timeElapsedLabel->setText(msfloatToHumanReadableString(diff.count()));

View file

@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include <future> #include <future>
#include "PgsqlConn.h" #include "PgsqlConn.h"
#include <chrono>
#include <deque> #include <deque>
#include <mutex> #include <mutex>
@ -50,6 +51,7 @@ private:
void startTimer(); void startTimer();
void endTimer(); void endTimer();
std::chrono::duration<float, std::milli> elapsedTime;
Ui::MainWindow *ui; Ui::MainWindow *ui;

View file

@ -22,7 +22,7 @@ SqlHighlighter::SqlHighlighter(QTextDocument *parent)
: QSyntaxHighlighter(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 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)-"; // static auto err = R"-(left|right|inner|outer)-";