Removed duplicates with old name adjusted includes to match new header name.
This commit is contained in:
parent
243f1c0a42
commit
869d867191
13 changed files with 11 additions and 434 deletions
|
|
@ -94,7 +94,7 @@ add_executable(pglab
|
||||||
pglab/PgDatabaseContainer.cpp
|
pglab/PgDatabaseContainer.cpp
|
||||||
pglab/PgDatabase.cpp
|
pglab/PgDatabase.cpp
|
||||||
pglab/PgNamespace.cpp
|
pglab/PgNamespace.cpp
|
||||||
pglab/PgsqlConn.cpp
|
pglab/Pgsql_Connection.cpp
|
||||||
pglab/Pgsql_Params.cpp
|
pglab/Pgsql_Params.cpp
|
||||||
pglab/Pgsql_Result.cpp
|
pglab/Pgsql_Result.cpp
|
||||||
pglab/Pgsql_Row.cpp
|
pglab/Pgsql_Row.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef ASYNCDBCONNECTION_H
|
#ifndef ASYNCDBCONNECTION_H
|
||||||
#define ASYNCDBCONNECTION_H
|
#define ASYNCDBCONNECTION_H
|
||||||
|
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "Pgsql_Params.h"
|
#include "Pgsql_Params.h"
|
||||||
#include "ConnectionConfig.h"
|
#include "ConnectionConfig.h"
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#include "OpenDatabase.h"
|
#include "OpenDatabase.h"
|
||||||
#include "PgDatabaseCatalogue.h"
|
#include "PgDatabaseCatalogue.h"
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "TypeSelectionItemModel.h"
|
#include "TypeSelectionItemModel.h"
|
||||||
|
|
||||||
Expected<OpenDatabase*> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
Expected<OpenDatabase*> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "PgAuthIdContainer.h"
|
#include "PgAuthIdContainer.h"
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "PgDatabaseCatalogue.h"
|
#include "PgDatabaseCatalogue.h"
|
||||||
|
|
||||||
PgAuthIdContainer::PgAuthIdContainer(PgDatabaseCatalogue *cat)
|
PgAuthIdContainer::PgAuthIdContainer(PgDatabaseCatalogue *cat)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#include "PgTypeContainer.h"
|
#include "PgTypeContainer.h"
|
||||||
#include "PgDatabaseContainer.h"
|
#include "PgDatabaseContainer.h"
|
||||||
#include "PgAuthIdContainer.h"
|
#include "PgAuthIdContainer.h"
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
|
|
||||||
|
|
||||||
QString getRoleNameFromOid(const PgDatabaseCatalogue *cat, Oid oid)
|
QString getRoleNameFromOid(const PgDatabaseCatalogue *cat, Oid oid)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "PgDatabaseContainer.h"
|
#include "PgDatabaseContainer.h"
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
|
|
||||||
PgDatabaseContainer::PgDatabaseContainer(PgDatabaseCatalogue *cat)
|
PgDatabaseContainer::PgDatabaseContainer(PgDatabaseCatalogue *cat)
|
||||||
: PgContainer<PgDatabase>(cat)
|
: PgContainer<PgDatabase>(cat)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "PgType.h"
|
#include "PgType.h"
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
|
|
||||||
PgType::PgType() = default;
|
PgType::PgType() = default;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#include "PgTypeContainer.h"
|
#include "PgTypeContainer.h"
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
PgTypeContainer::PgTypeContainer(PgDatabaseCatalogue *cat)
|
PgTypeContainer::PgTypeContainer(PgDatabaseCatalogue *cat)
|
||||||
|
|
|
||||||
|
|
@ -1,206 +0,0 @@
|
||||||
#include "PgsqlConn.h"
|
|
||||||
#include "Pgsql_declare.h"
|
|
||||||
#include "Pgsql_Params.h"
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace Pgsql;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Canceller::Canceller(PGcancel *c)
|
|
||||||
: m_cancel(c)
|
|
||||||
{}
|
|
||||||
|
|
||||||
Canceller::Canceller(Canceller&& rhs)
|
|
||||||
: m_cancel(rhs.m_cancel)
|
|
||||||
{
|
|
||||||
rhs.m_cancel = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Canceller& Canceller::operator=(Canceller&& rhs)
|
|
||||||
{
|
|
||||||
if (m_cancel) {
|
|
||||||
PQfreeCancel(m_cancel);
|
|
||||||
}
|
|
||||||
m_cancel = rhs.m_cancel;
|
|
||||||
rhs.m_cancel = nullptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Canceller::~Canceller()
|
|
||||||
{
|
|
||||||
if (m_cancel) {
|
|
||||||
PQfreeCancel(m_cancel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Canceller::cancel(std::string *error)
|
|
||||||
{
|
|
||||||
const int errbuf_size = 256;
|
|
||||||
char errbuf[errbuf_size];
|
|
||||||
bool res = PQcancel(m_cancel, errbuf, errbuf_size);
|
|
||||||
if (!res && error) {
|
|
||||||
*error = errbuf;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Connection::Connection() = default;
|
|
||||||
|
|
||||||
Connection::~Connection()
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Connection::Connection(Connection &&rhs)
|
|
||||||
: conn(rhs.conn)
|
|
||||||
{
|
|
||||||
rhs.conn = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Connection& Connection::operator=(Connection &&rhs)
|
|
||||||
{
|
|
||||||
close();
|
|
||||||
conn = rhs.conn;
|
|
||||||
rhs.conn = nullptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::close()
|
|
||||||
{
|
|
||||||
if (conn) {
|
|
||||||
PQfinish(conn);
|
|
||||||
conn = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Canceller Connection::getCancel()
|
|
||||||
{
|
|
||||||
Canceller c(PQgetCancel(conn));
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::connect(const char *params)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
conn = PQconnectdb(params);
|
|
||||||
if (conn) {
|
|
||||||
ConnStatusType status = PQstatus(conn);
|
|
||||||
result = (status == CONNECTION_OK);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::connect(const char *const * keywords, const char* const * values, int expand_dbname)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
conn = PQconnectdbParams(keywords, values, expand_dbname);
|
|
||||||
if (conn) {
|
|
||||||
ConnStatusType status = PQstatus(conn);
|
|
||||||
result = (status == CONNECTION_OK);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::connectStart(const char* params)
|
|
||||||
{
|
|
||||||
conn = PQconnectStart(params);
|
|
||||||
return conn != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::connectStart(const char * const *keywords,
|
|
||||||
const char * const *values)
|
|
||||||
{
|
|
||||||
conn = PQconnectStartParams(keywords, values, 0);
|
|
||||||
return conn != nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
PostgresPollingStatusType Connection::connectPoll()
|
|
||||||
{
|
|
||||||
return PQconnectPoll(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnStatusType Connection::status()
|
|
||||||
{
|
|
||||||
return PQstatus(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Connection::socket()
|
|
||||||
{
|
|
||||||
return PQsocket(conn);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Connection::getErrorMessage() const
|
|
||||||
{
|
|
||||||
std::string result;
|
|
||||||
if (conn) {
|
|
||||||
result = PQerrorMessage(conn);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result = "no connection";
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result Connection::query(const char * command)
|
|
||||||
{
|
|
||||||
PGresult *result = PQexec(conn, command);
|
|
||||||
return Result(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool Connection::sendQuery(const char *query)
|
|
||||||
{
|
|
||||||
int res = PQsendQuery(conn, query);
|
|
||||||
return res == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::sendQueryParams(const char * command, const Params ¶ms)
|
|
||||||
{
|
|
||||||
int res = PQsendQueryParams(conn, command, params.size(), params.types(),
|
|
||||||
params.values(), params.lengths(), params.formats(),
|
|
||||||
0); // text format
|
|
||||||
|
|
||||||
return res == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<Result> Connection::getResult()
|
|
||||||
{
|
|
||||||
PGresult *r = PQgetResult(conn);
|
|
||||||
if (r) {
|
|
||||||
return std::make_shared<Result>(r);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::consumeInput()
|
|
||||||
{
|
|
||||||
int res = PQconsumeInput(conn);
|
|
||||||
return res == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Connection::isBusy()
|
|
||||||
{
|
|
||||||
int res = PQisBusy(conn);
|
|
||||||
return res == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::setNoticeReceiver(std::function<void(const PGresult *)> callback)
|
|
||||||
{
|
|
||||||
notifyReceiver = callback;
|
|
||||||
PQsetNoticeReceiver(conn,
|
|
||||||
Connection::notifyReceiveFunc
|
|
||||||
, reinterpret_cast<void*>(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::notifyReceiveFunc(void *arg, const PGresult *result)
|
|
||||||
{
|
|
||||||
Connection *c = reinterpret_cast<Connection *>(arg);
|
|
||||||
c->notifyReceiver(result);
|
|
||||||
}
|
|
||||||
|
|
@ -1,217 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
|
||||||
#include <libpq-fe.h>
|
|
||||||
#include <cassert>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <codecvt>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <fmt/format.h>
|
|
||||||
|
|
||||||
#include "Pgsql_Result.h"
|
|
||||||
|
|
||||||
namespace Pgsql {
|
|
||||||
|
|
||||||
class Connection;
|
|
||||||
/*
|
|
||||||
This library has multiple layers.
|
|
||||||
|
|
||||||
Layer 1 delivers lowlevel C++ wrappers for the basic libpq functionality. Adding
|
|
||||||
automatic resource management.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// class ConnectionParams {
|
|
||||||
// public:
|
|
||||||
// std::string host;
|
|
||||||
// std::string hostaddr;
|
|
||||||
// unsigned short port = 5432;
|
|
||||||
// std::string dbname;
|
|
||||||
// std::string user;
|
|
||||||
// std::string password;
|
|
||||||
// int connect_timeout = -1; ///< -1 omit (ie uses default)
|
|
||||||
// std::string application_name;
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Result;
|
|
||||||
class Params;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** \brief Wrapper for a cancel object from libpq.
|
|
||||||
*/
|
|
||||||
class Canceller {
|
|
||||||
public:
|
|
||||||
Canceller() = default;
|
|
||||||
Canceller(PGcancel *c);
|
|
||||||
Canceller(const Canceller&) = delete;
|
|
||||||
Canceller& operator=(const Canceller&) = delete;
|
|
||||||
Canceller(Canceller&& rhs);
|
|
||||||
Canceller& operator=(Canceller&& rhs);
|
|
||||||
~Canceller();
|
|
||||||
|
|
||||||
bool cancel(std::string *error);
|
|
||||||
private:
|
|
||||||
PGcancel *m_cancel = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** \brief Class for connecting to the database.
|
|
||||||
*
|
|
||||||
* The class isolates the programmer from the worst C style parts
|
|
||||||
* of the libpq API but is mostly a very thin wrapper.
|
|
||||||
*/
|
|
||||||
class Connection {
|
|
||||||
public:
|
|
||||||
Connection();
|
|
||||||
~Connection();
|
|
||||||
|
|
||||||
Connection(const Connection &rhs) = delete;
|
|
||||||
Connection& operator=(const Connection &rhs) = delete;
|
|
||||||
|
|
||||||
Connection(Connection &&rhs);
|
|
||||||
Connection& operator=(Connection &&rhs);
|
|
||||||
|
|
||||||
// void connect(const ConnectionParams ¶ms);
|
|
||||||
bool connect(const char *params);
|
|
||||||
bool connect(const QString ¶ms)
|
|
||||||
{
|
|
||||||
return connect(params.toUtf8().data());
|
|
||||||
}
|
|
||||||
bool connect(const char *const * keywords, const char* const * values, int expand_dbname);
|
|
||||||
|
|
||||||
bool connectStart(const char *params);
|
|
||||||
|
|
||||||
bool connectStart(const std::string ¶ms)
|
|
||||||
{
|
|
||||||
return connectStart(params.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool connectStart(const QString ¶ms)
|
|
||||||
{
|
|
||||||
return connectStart(params.toUtf8().data());
|
|
||||||
}
|
|
||||||
bool connectStart(const char * const *keywords,
|
|
||||||
const char * const *values);
|
|
||||||
|
|
||||||
PostgresPollingStatusType connectPoll();
|
|
||||||
ConnStatusType status();
|
|
||||||
int socket();
|
|
||||||
|
|
||||||
void close();
|
|
||||||
Canceller getCancel();
|
|
||||||
|
|
||||||
std::string getErrorMessage() const;
|
|
||||||
|
|
||||||
Result query(const char * command);
|
|
||||||
Result query(const QString &command)
|
|
||||||
{
|
|
||||||
return query(command.toUtf8().data());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendQuery(const char * query);
|
|
||||||
bool sendQuery(const std::string &command)
|
|
||||||
{
|
|
||||||
return sendQuery(command.c_str());
|
|
||||||
}
|
|
||||||
bool sendQuery(const QString &command)
|
|
||||||
{
|
|
||||||
return sendQuery(command.toUtf8().data());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sendQueryParams(const char * command, const Params ¶ms);
|
|
||||||
|
|
||||||
std::shared_ptr<Result> getResult();
|
|
||||||
|
|
||||||
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 Field {
|
|
||||||
// public:
|
|
||||||
|
|
||||||
// std::string getName() const;
|
|
||||||
|
|
||||||
// private:
|
|
||||||
// //Tuples tuples;
|
|
||||||
// int field;
|
|
||||||
// //
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
// class Tuples {
|
|
||||||
// public:
|
|
||||||
// int getRowCount() const;
|
|
||||||
// int getColCount() const;
|
|
||||||
|
|
||||||
// Field getField(const std::string &fname);
|
|
||||||
// Field getField(const int idx);
|
|
||||||
|
|
||||||
// class const_iterator {
|
|
||||||
// public:
|
|
||||||
// const_iterator& operator++();
|
|
||||||
// };
|
|
||||||
|
|
||||||
// void rewind();
|
|
||||||
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
// class OkResult: public Result {
|
|
||||||
// public:
|
|
||||||
// /** If the result is a data result then returns an interface for processing this data.
|
|
||||||
|
|
||||||
// The returned interface remains valid as long as this OkResult exists.
|
|
||||||
// */
|
|
||||||
// Tuples* hasTuples();
|
|
||||||
// };
|
|
||||||
|
|
||||||
// class ErrorResult: public Result {
|
|
||||||
//
|
|
||||||
// };
|
|
||||||
|
|
||||||
// class ITransaction {
|
|
||||||
// public:
|
|
||||||
//
|
|
||||||
// Canceller Query(std::string query,
|
|
||||||
// std::function<void(OkResult)> on_success,
|
|
||||||
// std::function<void()> on_cancelled,
|
|
||||||
// std::function<void(ErrorResult)> on_error);
|
|
||||||
//
|
|
||||||
// Canceller Query(std::string query,
|
|
||||||
// std::function<void(OkResult)> on_success,
|
|
||||||
// std::function<void()> on_cancelled,
|
|
||||||
// std::function<void(ErrorResult)> on_error);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// void Rollback(
|
|
||||||
// std::function<void(OkResult)> on_success,
|
|
||||||
// std::function<void(ErrorResult)> on_error);
|
|
||||||
// void Commit(
|
|
||||||
// std::function<void(OkResult)> on_success,
|
|
||||||
// std::function<void()> on_cancelled,
|
|
||||||
// std::function<void(ErrorResult)> on_error);
|
|
||||||
//
|
|
||||||
// };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
#include "Pgsql_declare.h"
|
#include "Pgsql_declare.h"
|
||||||
#include "Pgsql_Params.h"
|
#include "Pgsql_Params.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define QUERYRESULTMODEL_H
|
#define QUERYRESULTMODEL_H
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
#include "PgsqlConn.h"
|
#include "Pgsql_Connection.h"
|
||||||
|
|
||||||
class QueryResultModel : public QAbstractTableModel
|
class QueryResultModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue