14#ifndef CPL_ODBC_H_INCLUDED
15#define CPL_ODBC_H_INCLUDED
30#define ODBC_FILENAME_MAX PATH_MAX
32#define ODBC_FILENAME_MAX (255 + 1)
47 char m_szPathOut[ODBC_FILENAME_MAX];
48 char m_szError[SQL_MAX_MESSAGE_LENGTH];
52 static bool FindMdbToolsDriverLib(
CPLString &osDriverFile);
53 static bool LibraryExists(
const char *pszLibPath);
76 int InstallDriver(
const char *pszDriver,
const char *pszPathIn,
77 WORD fRequest = ODBC_INSTALL_COMPLETE);
86 static void InstallMdbToolsDriver();
104 int RemoveDriver(
const char *pszDriverName,
int fRemoveDSN = FALSE);
109 return m_nUsageCount;
147#if defined(_MSC_VER) && !defined(SQLULEN) && !defined(_WIN64)
148#define MISSING_SQLULEN
152#if !defined(MISSING_SQLULEN)
154#define CPL_SQLULEN SQLULEN
155#define CPL_SQLLEN SQLLEN
157#define CPL_SQLULEN SQLUINTEGER
158#define CPL_SQLLEN SQLINTEGER
176 HENV m_hEnv =
nullptr;
177 HDBC m_hDBC =
nullptr;
178 int m_bInTransaction =
false;
179 int m_bAutoCommit =
true;
186 int EstablishSession(
const char *pszDSN,
const char *pszUserid,
187 const char *pszPassword);
188 const char *GetLastError();
192 int ClearTransaction();
193 int BeginTransaction();
194 int CommitTransaction();
195 int RollbackTransaction();
200 return m_bInTransaction;
207 int Failed(
int, HSTMT =
nullptr);
221 bool ConnectToMsAccess(
const char *pszName,
222 const char *pszDSNStringTemplate);
244 HSTMT m_hStmt =
nullptr;
246 SQLSMALLINT m_nColCount = 0;
247 char **m_papszColNames =
nullptr;
248 SQLSMALLINT *m_panColType =
nullptr;
249 char **m_papszColTypeNames =
nullptr;
250 CPL_SQLULEN *m_panColSize =
nullptr;
251 SQLSMALLINT *m_panColPrecision =
nullptr;
252 SQLSMALLINT *m_panColNullable =
nullptr;
253 char **m_papszColColumnDef =
nullptr;
255 char **m_papszColValues =
nullptr;
256 CPL_SQLLEN *m_panColValueLengths =
nullptr;
257 double *m_padColValuesAsDouble =
nullptr;
261 char *m_pszStatement =
nullptr;
262 size_t m_nStatementMax = 0;
263 size_t m_nStatementLen = 0;
286 RetrieveNumericColumnsAsDouble = 1 << 0,
308 void AppendEscaped(
const char *);
309 void Append(
const char *);
310 void Append(
const std::string &);
318 const
char *GetCommand()
320 return m_pszStatement;
323 int ExecuteSQL(
const char * =
nullptr);
326 int Fetch(
int nOrientation = SQL_FETCH_NEXT,
int nOffset = 0);
327 void ClearColumnData();
330 const char *GetColName(
int);
331 short GetColType(
int);
332 const char *GetColTypeName(
int);
333 short GetColSize(
int);
334 short GetColPrecision(
int);
335 short GetColNullable(
int);
336 const char *GetColColumnDef(
int);
338 int GetColId(
const char *)
const;
339 const char *GetColData(
int,
const char * =
nullptr);
340 const char *GetColData(
const char *,
const char * =
nullptr);
341 int GetColDataLength(
int);
343 double GetColDataAsDouble(
int)
const;
344 double GetColDataAsDouble(
const char *)
const;
346 int GetRowCountAffected();
349 int GetColumns(
const char *pszTable,
const char *pszCatalog =
nullptr,
350 const char *pszSchema =
nullptr);
351 int GetPrimaryKeys(
const char *pszTable,
const char *pszCatalog =
nullptr,
352 const char *pszSchema =
nullptr);
354 int GetTables(
const char *pszCatalog =
nullptr,
355 const char *pszSchema =
nullptr);
357 void DumpResult(FILE *fp,
int bShowSchema = FALSE);
360 static SQLSMALLINT GetTypeMapping(SQLSMALLINT);
362 int CollectResultsInfo();
A class providing functions to install or remove ODBC driver.
Definition: cpl_odbc.h:46
int GetUsageCount() const
The usage count of the driver after this function has been called.
Definition: cpl_odbc.h:107
const char * GetPathOut() const
Path of the target directory where the driver should be installed.
Definition: cpl_odbc.h:116
const char * GetLastError() const
If InstallDriver returns FALSE, then GetLastError then error message can be obtained by calling this ...
Definition: cpl_odbc.h:125
DWORD GetLastErrorCode() const
If InstallDriver returns FALSE, then GetLastErrorCode then error code can be obtained by calling this...
Definition: cpl_odbc.h:135
A class representing an ODBC database session.
Definition: cpl_odbc.h:169
int IsInTransaction()
Returns whether a transaction is active.
Definition: cpl_odbc.h:198
HDBC GetConnection()
Return connection handle.
Definition: cpl_odbc.h:210
HENV GetEnvironment()
Return GetEnvironment handle.
Definition: cpl_odbc.h:216
Abstraction for statement, and resultset.
Definition: cpl_odbc.h:235
int Flags() const
Returns statement flags.
Definition: cpl_odbc.h:301
HSTMT GetStatement()
Return statement handle.
Definition: cpl_odbc.h:293
Flag
Flags which control ODBC statement behavior.
Definition: cpl_odbc.h:271
Convenient string class based on std::string.
Definition: cpl_string.h:307
Core portability definitions for CPL.
#define CPL_FORMAT_STRING(arg)
Macro into which to wrap the format argument of a printf-like function.
Definition: cpl_port.h:954
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:938
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:1030
Various convenience functions for working with strings and string lists.