Created IndexModel for displaying the indexes on a table. Constraints can now show the SQL to drop and create them.

The keyword list is now directly based of the official keyword list from postgresql.
This commit is contained in:
eelke 2018-01-06 21:22:22 +01:00
parent b436814eb5
commit 97d4e2a1a4
24 changed files with 754 additions and 228 deletions

View file

@ -1,6 +1,7 @@
#include "Pgsql_Connection.h"
#include "Pgsql_declare.h"
#include "Pgsql_Params.h"
#include <memory>
#include <stdexcept>
@ -199,6 +200,52 @@ void Connection::setNoticeReceiver(std::function<void(const PGresult *)> callbac
, reinterpret_cast<void*>(this));
}
std::string Connection::escapeLiteral(const std::string_view &literal)
{
std::unique_ptr<char, void(*)(char*)> result(
PQescapeLiteral(conn, literal.data(), literal.length()),
[](char*p) { if (p) PQfreemem(p); });
if (result) {
return std::string(result.get());
}
throw std::runtime_error("escapeLiteral(string_view) failed");
}
QString Connection::escapeLiteral(const QString &literal)
{
auto u8 = literal.toUtf8();
std::unique_ptr<char, void(*)(char*)> result(
PQescapeLiteral(conn, u8.data(), u8.length()),
[](char*p) { if (p) PQfreemem(p); });
if (result) {
return QString::fromUtf8(result.get());
}
throw std::runtime_error("escapeLiteral(QString) failed");
}
std::string Connection::escapeIdentifier(const std::string_view &ident)
{
std::unique_ptr<char, void(*)(char*)> result(
PQescapeIdentifier(conn, ident.data(), ident.length()),
[](char*p) { if (p) PQfreemem(p); });
if (result) {
return std::string(result.get());
}
throw std::runtime_error("escapeIdentifier failed");
}
QString Connection::escapeIdentifier(const QString &ident)
{
auto u8 = ident.toUtf8();
std::unique_ptr<char, void(*)(char*)> result(
PQescapeIdentifier(conn, u8.data(), u8.length()),
[](char*p) { if (p) PQfreemem(p); });
if (result) {
return QString::fromUtf8(result.get());
}
throw std::runtime_error("escapeIdentifier(QString) failed");
}
void Connection::notifyReceiveFunc(void *arg, const PGresult *result)
{
Connection *c = reinterpret_cast<Connection *>(arg);

View file

@ -25,28 +25,9 @@ namespace Pgsql {
*/
// 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 {
@ -80,16 +61,14 @@ namespace Pgsql {
Connection(Connection &&rhs);
Connection& operator=(Connection &&rhs);
// void connect(const ConnectionParams &params);
bool connect(const char *params);
bool connect(const QString &params)
{
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 &params)
{
return connectStart(params.c_str());
@ -99,6 +78,7 @@ namespace Pgsql {
{
return connectStart(params.toUtf8().data());
}
bool connectStart(const char * const *keywords,
const char * const *values);
@ -135,6 +115,11 @@ namespace Pgsql {
bool isBusy();
void setNoticeReceiver(std::function<void(const PGresult *)> callback);
std::string escapeLiteral(const std::string_view &literal);
QString escapeLiteral(const QString &literal);
std::string escapeIdentifier(const std::string_view &ident);
QString escapeIdentifier(const QString &ident);
private:
PGconn *conn = nullptr;
std::function<void(const PGresult *)> notifyReceiver;
@ -142,75 +127,6 @@ namespace Pgsql {
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);
//
// };
}