29#include <sptk5/sptk.h>
34#include <sptk5/db/DatabaseField.h>
35#include <sptk5/db/ODBCEnvironment.h>
36#include <sptk5/db/PoolDatabaseConnection.h>
50class SP_DRIVER_EXPORT ODBCConnection
51 :
public PoolDatabaseConnection
60 explicit ODBCConnection(
const String& connectionString =
"", std::chrono::seconds connectTimeout = std::chrono::seconds(60));
62 ODBCConnection(
const ODBCConnection&) =
delete;
64 ODBCConnection(ODBCConnection&&) noexcept = default;
69 ~ODBCConnection()
override
74 ODBCConnection& operator=(
const ODBCConnection&) =
delete;
76 ODBCConnection& operator=(ODBCConnection&&) noexcept = default;
81 String nativeConnectionString() const override;
86 void closeDatabase() override;
91 bool active() const override;
96 DBHandle handle() const override;
101 String driverDescription() const override;
113 static std::map<ODBCConnection*, std::shared_ptr<ODBCConnection>> s_odbcConnections;
119 void driverBeginTransaction() override;
125 void driverEndTransaction(
bool commit) override;
131 String queryError(const Query* query) const override;
136 void queryAllocStmt(Query* query) override;
141 void queryFreeStmt(Query* query) override;
146 void queryCloseStmt(Query* query) override;
151 void queryPrepare(Query* query) override;
156 void queryExecute(Query* query) override;
161 int queryColCount(Query* query) override;
166 void queryColAttributes(Query* query, int16_t column, int16_t descType, int32_t& value) override;
171 void queryColAttributes(Query* query, int16_t column, int16_t descType,
char* buff,
int len) override;
176 void queryBindParameters(Query* query) override;
181 void queryOpen(Query* query) override;
186 void queryFetch(Query* query) override;
191 static
void ODBCtypeToCType(
int odbcType, int32_t& ctype,
VariantDataType& dataType);
196 ODBCConnectionBase* connection()
198 return m_connect.get();
205 static void listDataSources(Strings& dsns);
211 void _openDatabase(
const String& connectionString)
override;
221 void _executeBatchSQL(
const sptk::Strings& batchSQL, Strings* errors)
override;
223 void _bulkInsert(
const String& tableName,
const Strings& columnNames,
224 const std::vector<VariantVector>& data)
override;
227 static constexpr size_t MAX_NAME_LEN = 256;
232 std::shared_ptr<ODBCConnectionBase> m_connect {std::make_shared<ODBCConnectionBase>()};
238 String queryError(SQLHSTMT stmt)
const;
245 void parseColumns(Query* query,
int count);
256SP_DRIVER_EXPORT [[maybe_unused]]
void* odbc_create_connection(
const char* connectionString,
size_t connectionTimeoutSeconds);
257SP_DRIVER_EXPORT [[maybe_unused]]
void odbc_destroy_connection(
void* connection);
DatabaseObjectType
Definition: PoolDatabaseConnection.h:70
VariantDataType
Definition: VariantData.h:44