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:
parent
5831f18008
commit
fa9787adfd
5 changed files with 68 additions and 36 deletions
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Pgsql {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int tuplesAffected() const;
|
||||||
int getRows() const;
|
int getRows() const;
|
||||||
int getCols() const;
|
int getCols() const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -238,38 +239,46 @@ void MainWindow::query_ready(std::shared_ptr<Pgsql::Result> dbres)
|
||||||
statusBar()->showMessage(tr("Query ready."));
|
statusBar()->showMessage(tr("Query ready."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (st == PGRES_EMPTY_QUERY) {
|
if (st == PGRES_COMMAND_OK) {
|
||||||
statusBar()->showMessage(tr("Empty query."));
|
|
||||||
}
|
|
||||||
else if (st == PGRES_COMMAND_OK) {
|
|
||||||
statusBar()->showMessage(tr("Command OK."));
|
statusBar()->showMessage(tr("Command OK."));
|
||||||
}
|
QString msg = tr("Query returned succesfully: %1 rows affected, %2 execution time.")
|
||||||
else if (st == PGRES_COPY_OUT) {
|
.arg(QString::number(dbres->tuplesAffected()))
|
||||||
statusBar()->showMessage(tr("COPY OUT."));
|
.arg(msfloatToHumanReadableString(elapsedTime.count()));
|
||||||
}
|
ui->messagesEdit->append(msg);
|
||||||
else if (st == PGRES_COPY_IN) {
|
|
||||||
statusBar()->showMessage(tr("COPY IN."));
|
ui->tabWidget->setCurrentWidget(ui->messageTab);
|
||||||
}
|
|
||||||
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 {
|
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 {
|
else {
|
||||||
|
|
@ -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()));
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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)-";
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue