Added explain functionality.

Uses json format with jsoncpp as a parser. Then show it in a QTreeView.
Shows inclusive/exclusive times like explain.despesz does. Also a similar
coloring scheme as applied.
This commit is contained in:
Eelke Klein 2016-12-29 13:48:35 +01:00
parent 0d30dc9080
commit 8af6bc4ac5
14 changed files with 9089 additions and 33 deletions

View file

@ -10,6 +10,7 @@
namespace Pgsql {
class Connection;
/*
This library has multiple layers.
@ -31,6 +32,29 @@ namespace Pgsql {
};
class ErrorDetails {
public:
static ErrorDetails createErrorDetailsFromPGresult(const PGresult *res);
std::string state; ///< PG_DIAG_SQLSTATE Error code as listed in https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
std::string severity;
std::string messagePrimary;
std::string messageDetail;
std::string messageHint;
int statementPosition; ///< First character is one, measured in characters not bytes!
int internalPosition;
std::string internalQuery;
std::string context;
std::string schemaName;
std::string tableName;
std::string columnName;
std::string datatypeName;
std::string constraintName;
std::string sourceFile;
std::string sourceLine;
std::string sourceFunction;
};
/** Non-copyable but movable wrapper for a postgresql result. */
class Result {
public:
@ -76,8 +100,19 @@ namespace Pgsql {
operator bool() const;
ExecStatusType resultStatus();
std::string getResStatus();
/** Use this to retrieve an error code when this is an error result
*
* The possible code are listed in https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
*/
std::string diagSqlState();
/** Retrieves all the error fields. */
ErrorDetails diagDetails();
int getRows() const;
int getCols() const;
@ -91,6 +126,21 @@ namespace Pgsql {
PGresult *result = nullptr;
};
class Canceller {
public:
Canceller(PGcancel *c);
Canceller(const Canceller&) = delete;
Canceller& operator=(const Canceller&) = delete;
Canceller(Canceller&& rhs);
Canceller& operator=(Canceller&& rhs);
~Canceller();
void cancel();
private:
PGcancel *m_cancel;
};
class Connection {
public:
Connection();
@ -120,6 +170,7 @@ namespace Pgsql {
int socket();
void close();
Canceller getCancel();
std::string getErrorMessage() const;
@ -140,15 +191,14 @@ namespace Pgsql {
bool consumeInput();
bool isBusy();
void setNoticeReceiver(std::function<void(const PGresult *)> callback);
private:
PGconn *conn = nullptr;
std::function<void(const PGresult *)> notifyReceiver;
static void notifyReceiveFunc(void *arg, const PGresult *result);
};
class Canceller {
public:
void Cancel();
};