30#include <sptk5/db/PoolDatabaseConnection.h>
39#include <netinet/in.h>
50class PostgreSQLStatement;
57class SP_EXPORT PostgreSQLConnection
58 :
public PoolDatabaseConnection
63 enum class TimestampFormat : uint8_t
81 static void PostgreTypeToCType(PostgreSQLDataType postgreType,
VariantDataType& dataType);
86 static void CTypeToPostgreType(
VariantDataType dataType, PostgreSQLDataType& postgreType,
const String& paramName);
92 void _openDatabase(
const String& connectionString)
override;
104 void _bulkInsert(
const String& tableName,
const Strings& columnNames,
105 const std::vector<VariantVector>& data)
override;
115 void _executeBatchSQL(
const sptk::Strings& batchSQL, Strings* errors)
override;
126 explicit PostgreSQLConnection(
const String& connectionString =
"", std::chrono::seconds connectTimeout = std::chrono::seconds(60));
131 ~PostgreSQLConnection()
override;
136 String nativeConnectionString()
const override;
141 void closeDatabase()
override;
146 bool active()
const override;
151 DBHandle handle()
const override;
156 String driverDescription()
const override;
168 static std::map<PostgreSQLConnection*, std::shared_ptr<PostgreSQLConnection>> s_postgresqlConnections;
171 static Strings extractStatements(
const Strings& sqlBatch);
176 void driverBeginTransaction()
override;
182 void driverEndTransaction(
bool commit)
override;
189 String queryError(
const Query* query)
const override;
194 void queryAllocStmt(Query* query)
override;
199 void queryFreeStmt(Query* query)
override;
204 void queryCloseStmt(Query* query)
override;
209 void queryPrepare(Query* query)
override;
214 void queryExecute(Query* query)
override
222 int queryColCount(Query* query)
override;
227 void queryBindParameters(Query* query)
override;
232 void queryOpen(Query* query)
override;
237 void queryFetch(Query* query)
override;
245 String paramMark(
unsigned paramIndex)
override;
251 TimestampFormat timestampsFormat()
const
253 return m_timestampsFormat;
256 void queryColAttributes(Query* query, int16_t column, int16_t descType, int32_t& value)
override;
257 void queryColAttributes(Query* query, int16_t column, int16_t descType,
char* buff,
int len)
override;
258 void queryExecDirect(
const Query* query);
261 mutable std::mutex m_mutex;
262 PGconn* m_connect {
nullptr};
263 TimestampFormat m_timestampsFormat {TimestampFormat::UNKNOWN};
274SP_DRIVER_EXPORT
void* postgresql_create_connection(
const char* connectionString,
size_t connectionTimeoutSeconds);
275SP_DRIVER_EXPORT
void postgresql_destroy_connection(
void* connection);
DatabaseObjectType
Definition: PoolDatabaseConnection.h:70
VariantDataType
Definition: VariantData.h:44