summaryrefslogtreecommitdiff
path: root/libpqpp
diff options
context:
space:
mode:
Diffstat (limited to 'libpqpp')
-rw-r--r--libpqpp/pq-binarycolumn.h2
-rw-r--r--libpqpp/pq-bulkselectcommand.h1
-rw-r--r--libpqpp/pq-column.cpp6
-rw-r--r--libpqpp/pq-column.h2
-rw-r--r--libpqpp/pq-command.cpp18
-rw-r--r--libpqpp/pq-command.h1
-rw-r--r--libpqpp/pq-connection.cpp4
-rw-r--r--libpqpp/pq-cursorselectcommand.h1
-rw-r--r--libpqpp/pq-error.h1
-rw-r--r--libpqpp/pq-mock.cpp2
-rw-r--r--libpqpp/pq-modifycommand.h1
-rw-r--r--libpqpp/pq-prepared.h1
12 files changed, 36 insertions, 4 deletions
diff --git a/libpqpp/pq-binarycolumn.h b/libpqpp/pq-binarycolumn.h
index ed6eae7..e2a8044 100644
--- a/libpqpp/pq-binarycolumn.h
+++ b/libpqpp/pq-binarycolumn.h
@@ -6,8 +6,10 @@
namespace DB {
class HandleField;
}
+
namespace PQ {
class SelectBase;
+
class BinaryColumn : public Column {
public:
BinaryColumn(const SelectBase *, unsigned int field);
diff --git a/libpqpp/pq-bulkselectcommand.h b/libpqpp/pq-bulkselectcommand.h
index 6470905..6e186a1 100644
--- a/libpqpp/pq-bulkselectcommand.h
+++ b/libpqpp/pq-bulkselectcommand.h
@@ -9,6 +9,7 @@
namespace PQ {
class Connection;
+
class BulkSelectCommand : public SelectBase, public PreparedStatement {
public:
BulkSelectCommand(Connection *, const std::string & sql, const PQ::CommandOptionsCPtr & pqco,
diff --git a/libpqpp/pq-column.cpp b/libpqpp/pq-column.cpp
index e85ead5..cd0d60c 100644
--- a/libpqpp/pq-column.cpp
+++ b/libpqpp/pq-column.cpp
@@ -72,8 +72,7 @@ PQ::Column::apply(DB::HandleField & h) const
h.floatingpoint(atof(value()));
break;
case TIMEOID:
- case INTERVALOID:
- {
+ case INTERVALOID: {
int days = 0, hours = 0, minutes = 0, seconds = 0, fractions = 0, flen1 = 0, flen2 = 0;
const char * val = value();
// NOLINTNEXTLINE(hicpp-vararg)
@@ -97,8 +96,7 @@ PQ::Column::apply(DB::HandleField & h) const
case TIMESTAMPTZOID:
h.timestamp(boost::posix_time::time_from_string(value()));
break;
- case BYTEAOID:
- {
+ case BYTEAOID: {
if (buf) {
PQfreemem(buf);
}
diff --git a/libpqpp/pq-column.h b/libpqpp/pq-column.h
index f893fef..f86958e 100644
--- a/libpqpp/pq-column.h
+++ b/libpqpp/pq-column.h
@@ -7,6 +7,7 @@
namespace PQ {
class SelectBase;
+
class Column : public DB::Column {
public:
Column(const SelectBase *, unsigned int field);
@@ -24,6 +25,7 @@ namespace PQ {
std::memcpy(&v, value(), sizeof(T));
return v;
}
+
const char * value() const;
std::size_t length() const;
diff --git a/libpqpp/pq-command.cpp b/libpqpp/pq-command.cpp
index e366c51..3e359c0 100644
--- a/libpqpp/pq-command.cpp
+++ b/libpqpp/pq-command.cpp
@@ -8,6 +8,7 @@
namespace Glib {
class ustring;
}
+
namespace PQ {
class Connection;
}
@@ -15,6 +16,7 @@ namespace PQ {
NAMEDFACTORY("postgresql", PQ::CommandOptions, DB::CommandOptionsFactory)
AdHocFormatter(PQCommondStatement, "pStatement_id%?");
+
PQ::Command::Command(Connection * conn, const std::string & sql, const DB::CommandOptionsCPtr & opts) :
DB::Command(sql), hash(opts && opts->hash ? *opts->hash : std::hash<std::string>()(sql)),
stmntName(PQCommondStatement::get(hash)), c(conn)
@@ -33,6 +35,7 @@ PQ::CommandOptions::CommandOptions(std::size_t hash, unsigned int ft, bool uc, b
}
AdHocFormatter(PQCommandParamName, "$%?");
+
void
PQ::Command::prepareSql(std::stringstream & psql, const std::string & sql) const
{
@@ -68,6 +71,7 @@ PQ::Command::paramsAtLeast(unsigned int n)
}
AdHocFormatter(PQCommandParamFmt, "%?");
+
template<typename... T>
void
PQ::Command::paramSet(unsigned int n, T &&... v)
@@ -95,66 +99,79 @@ PQ::Command::bindParamI(unsigned int n, int v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamI(unsigned int n, long int v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamI(unsigned int n, long long int v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamI(unsigned int n, unsigned int v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamI(unsigned int n, long unsigned int v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamI(unsigned int n, long long unsigned int v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamB(unsigned int n, bool v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamF(unsigned int n, double v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamF(unsigned int n, float v)
{
paramSet(n, v);
}
+
void
PQ::Command::bindParamS(unsigned int n, const Glib::ustring & s)
{
paramSet(n, std::string_view(s.data(), s.bytes()));
}
+
void
PQ::Command::bindParamS(unsigned int n, const std::string_view s)
{
paramSet(n, s);
}
+
void
PQ::Command::bindParamT(unsigned int n, const boost::posix_time::time_duration v)
{
paramSet(n, boost::posix_time::to_simple_string(v));
}
+
void
PQ::Command::bindParamT(unsigned int n, const boost::posix_time::ptime v)
{
paramSet(n, boost::posix_time::to_iso_extended_string(v));
}
+
void
PQ::Command::bindParamBLOB(unsigned int n, const DB::Blob & v)
{
@@ -164,6 +181,7 @@ PQ::Command::bindParamBLOB(unsigned int n, const DB::Blob & v)
values[n] = static_cast<const char *>(v.data);
bufs[n].reset();
}
+
void
PQ::Command::bindNull(unsigned int n)
{
diff --git a/libpqpp/pq-command.h b/libpqpp/pq-command.h
index a99bd72..4f1f1ea 100644
--- a/libpqpp/pq-command.h
+++ b/libpqpp/pq-command.h
@@ -36,6 +36,7 @@ namespace PQ {
bool useCursor;
bool fetchBinary;
};
+
using CommandOptionsPtr = std::shared_ptr<CommandOptions>;
using CommandOptionsCPtr = std::shared_ptr<const CommandOptions>;
diff --git a/libpqpp/pq-connection.cpp b/libpqpp/pq-connection.cpp
index 96e09f1..ee1ddf9 100644
--- a/libpqpp/pq-connection.cpp
+++ b/libpqpp/pq-connection.cpp
@@ -19,6 +19,7 @@
NAMEDFACTORY("postgresql", PQ::Connection, DB::ConnectionFactory)
static void setup() __attribute__((constructor(101)));
+
static void
setup()
{
@@ -92,6 +93,7 @@ PQ::Connection::ping() const
// NOLINTNEXTLINE(hicpp-signed-bitwise)
PQsocket(conn), POLLRDHUP | POLLERR | POLLHUP | POLLNVAL, 0
};
+
if (PQstatus(conn) != CONNECTION_OK || poll(&fd, 1, 0)) {
if (inTx()) {
throw ConnectionError(conn);
@@ -147,6 +149,7 @@ PQ::Connection::checkResultFree(PGresult * res, int expected, int alt) const
}
AdHocFormatter(PQConnectionCopyFrom, "COPY %? FROM STDIN %?");
+
void
PQ::Connection::beginBulkUpload(const char * table, const char * extra)
{
@@ -182,6 +185,7 @@ PQ::Connection::bulkUploadData(const char * data, size_t len) const
static const std::string selectLastVal("SELECT lastval()");
static const DB::CommandOptionsCPtr selectLastValOpts
= std::make_shared<DB::CommandOptions>(std::hash<std::string>()(selectLastVal));
+
int64_t
PQ::Connection::insertId()
{
diff --git a/libpqpp/pq-cursorselectcommand.h b/libpqpp/pq-cursorselectcommand.h
index 36070bc..681659c 100644
--- a/libpqpp/pq-cursorselectcommand.h
+++ b/libpqpp/pq-cursorselectcommand.h
@@ -8,6 +8,7 @@
namespace PQ {
class Connection;
+
class CursorSelectCommand : public SelectBase, public Command {
public:
CursorSelectCommand(
diff --git a/libpqpp/pq-error.h b/libpqpp/pq-error.h
index bc701fa..ffa47c1 100644
--- a/libpqpp/pq-error.h
+++ b/libpqpp/pq-error.h
@@ -5,6 +5,7 @@
#include <exception.h>
#include <libpq-fe.h>
#include <string>
+
// IWYU pragma: no_forward_declare DB::Error
namespace PQ {
diff --git a/libpqpp/pq-mock.cpp b/libpqpp/pq-mock.cpp
index 748a350..b96fcdb 100644
--- a/libpqpp/pq-mock.cpp
+++ b/libpqpp/pq-mock.cpp
@@ -32,6 +32,7 @@ namespace PQ {
}
AdHocFormatter(MockConnStr, "user=postgres dbname=%?");
+
DB::ConnectionPtr
Mock::openConnection() const
{
@@ -39,6 +40,7 @@ namespace PQ {
}
AdHocFormatter(MockSetUnlogged, "ALTER TABLE %?.%? SET UNLOGGED");
+
void
Mock::SetTablesToUnlogged() const
{
diff --git a/libpqpp/pq-modifycommand.h b/libpqpp/pq-modifycommand.h
index cc4ce7b..04938bf 100644
--- a/libpqpp/pq-modifycommand.h
+++ b/libpqpp/pq-modifycommand.h
@@ -8,6 +8,7 @@
namespace PQ {
class Connection;
+
class ModifyCommand : public DB::ModifyCommand, public PreparedStatement {
public:
ModifyCommand(Connection *, const std::string & sql, const DB::CommandOptionsCPtr &);
diff --git a/libpqpp/pq-prepared.h b/libpqpp/pq-prepared.h
index bf88f9e..db520fa 100644
--- a/libpqpp/pq-prepared.h
+++ b/libpqpp/pq-prepared.h
@@ -7,6 +7,7 @@
namespace PQ {
class Connection;
+
class PreparedStatement : public Command {
protected:
PreparedStatement(Connection *, const std::string &, const DB::CommandOptionsCPtr &);