30 #ifndef CPL_ODBC_H_INCLUDED
31 #define CPL_ODBC_H_INCLUDED
46 #define ODBC_FILENAME_MAX PATH_MAX
48 #define ODBC_FILENAME_MAX (255 + 1)
63 char m_szPathOut[ODBC_FILENAME_MAX];
64 char m_szError[SQL_MAX_MESSAGE_LENGTH];
68 static bool FindMdbToolsDriverLib(
CPLString &osDriverFile);
69 static bool LibraryExists(
const char *pszLibPath);
92 int InstallDriver(
const char *pszDriver,
const char *pszPathIn,
93 WORD fRequest = ODBC_INSTALL_COMPLETE);
102 static void InstallMdbToolsDriver();
120 int RemoveDriver(
const char *pszDriverName,
int fRemoveDSN = FALSE);
125 return m_nUsageCount;
163 #if defined(_MSC_VER) && !defined(SQLULEN) && !defined(_WIN64)
164 #define MISSING_SQLULEN
168 #if !defined(MISSING_SQLULEN)
170 #define CPL_SQLULEN SQLULEN
171 #define CPL_SQLLEN SQLLEN
173 #define CPL_SQLULEN SQLUINTEGER
174 #define CPL_SQLLEN SQLINTEGER
192 HENV m_hEnv =
nullptr;
193 HDBC m_hDBC =
nullptr;
194 int m_bInTransaction =
false;
195 int m_bAutoCommit =
true;
202 int EstablishSession(
const char *pszDSN,
const char *pszUserid,
203 const char *pszPassword);
204 const char *GetLastError();
208 int ClearTransaction();
209 int BeginTransaction();
210 int CommitTransaction();
211 int RollbackTransaction();
216 return m_bInTransaction;
223 int Failed(
int, HSTMT =
nullptr);
237 bool ConnectToMsAccess(
const char *pszName,
238 const char *pszDSNStringTemplate);
260 HSTMT m_hStmt =
nullptr;
262 SQLSMALLINT m_nColCount = 0;
263 char **m_papszColNames =
nullptr;
264 SQLSMALLINT *m_panColType =
nullptr;
265 char **m_papszColTypeNames =
nullptr;
266 CPL_SQLULEN *m_panColSize =
nullptr;
267 SQLSMALLINT *m_panColPrecision =
nullptr;
268 SQLSMALLINT *m_panColNullable =
nullptr;
269 char **m_papszColColumnDef =
nullptr;
271 char **m_papszColValues =
nullptr;
272 CPL_SQLLEN *m_panColValueLengths =
nullptr;
273 double *m_padColValuesAsDouble =
nullptr;
277 char *m_pszStatement =
nullptr;
278 size_t m_nStatementMax = 0;
279 size_t m_nStatementLen = 0;
302 RetrieveNumericColumnsAsDouble = 1 << 0,
324 void AppendEscaped(
const char *);
325 void Append(
const char *);
326 void Append(
const std::string &);
334 const
char *GetCommand()
336 return m_pszStatement;
339 int ExecuteSQL(
const char * =
nullptr);
342 int Fetch(
int nOrientation = SQL_FETCH_NEXT,
int nOffset = 0);
343 void ClearColumnData();
346 const char *GetColName(
int);
347 short GetColType(
int);
348 const char *GetColTypeName(
int);
349 short GetColSize(
int);
350 short GetColPrecision(
int);
351 short GetColNullable(
int);
352 const char *GetColColumnDef(
int);
354 int GetColId(
const char *)
const;
355 const char *GetColData(
int,
const char * =
nullptr);
356 const char *GetColData(
const char *,
const char * =
nullptr);
357 int GetColDataLength(
int);
359 double GetColDataAsDouble(
int)
const;
360 double GetColDataAsDouble(
const char *)
const;
362 int GetRowCountAffected();
365 int GetColumns(
const char *pszTable,
const char *pszCatalog =
nullptr,
366 const char *pszSchema =
nullptr);
367 int GetPrimaryKeys(
const char *pszTable,
const char *pszCatalog =
nullptr,
368 const char *pszSchema =
nullptr);
370 int GetTables(
const char *pszCatalog =
nullptr,
371 const char *pszSchema =
nullptr);
373 void DumpResult(FILE *fp,
int bShowSchema = FALSE);
376 static SQLSMALLINT GetTypeMapping(SQLSMALLINT);
378 int CollectResultsInfo();
A class providing functions to install or remove ODBC driver.
Definition: cpl_odbc.h:62
int GetUsageCount() const
The usage count of the driver after this function has been called.
Definition: cpl_odbc.h:123
const char * GetLastError() const
If InstallDriver returns FALSE, then GetLastError then error message can be obtained by calling this ...
Definition: cpl_odbc.h:141
const char * GetPathOut() const
Path of the target directory where the driver should be installed.
Definition: cpl_odbc.h:132
DWORD GetLastErrorCode() const
If InstallDriver returns FALSE, then GetLastErrorCode then error code can be obtained by calling this...
Definition: cpl_odbc.h:151
A class representing an ODBC database session.
Definition: cpl_odbc.h:185
int IsInTransaction()
Returns whether a transaction is active.
Definition: cpl_odbc.h:214
HDBC GetConnection()
Return connection handle.
Definition: cpl_odbc.h:226
HENV GetEnvironment()
Return GetEnvironment handle.
Definition: cpl_odbc.h:232
Abstraction for statement, and resultset.
Definition: cpl_odbc.h:251
int Flags() const
Returns statement flags.
Definition: cpl_odbc.h:317
HSTMT GetStatement()
Return statement handle.
Definition: cpl_odbc.h:309
Flag
Flags which control ODBC statement behavior.
Definition: cpl_odbc.h:287
Convenient string class based on std::string.
Definition: cpl_string.h:320
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:966
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:950
#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:1042
Various convenience functions for working with strings and string lists.