13#ifndef CPL_ODBC_H_INCLUDED
14#define CPL_ODBC_H_INCLUDED
29#define ODBC_FILENAME_MAX PATH_MAX
31#define ODBC_FILENAME_MAX (255 + 1)
44class CPL_DLL CPLODBCDriverInstaller
46 char m_szPathOut[ODBC_FILENAME_MAX];
47 char m_szError[SQL_MAX_MESSAGE_LENGTH];
51 static bool FindMdbToolsDriverLib(
CPLString &osDriverFile);
52 static bool LibraryExists(
const char *pszLibPath);
56 CPLODBCDriverInstaller();
75 int InstallDriver(
const char *pszDriver,
const char *pszPathIn,
76 WORD fRequest = ODBC_INSTALL_COMPLETE);
103 int RemoveDriver(
const char *pszDriverName,
int fRemoveDSN = FALSE);
108 return m_nUsageCount;
146#if defined(_MSC_VER) && !defined(SQLULEN) && !defined(_WIN64)
147#define MISSING_SQLULEN
151#if !defined(MISSING_SQLULEN)
153#define CPL_SQLULEN SQLULEN
154#define CPL_SQLLEN SQLLEN
156#define CPL_SQLULEN SQLUINTEGER
157#define CPL_SQLLEN SQLINTEGER
175 HENV m_hEnv =
nullptr;
176 HDBC m_hDBC =
nullptr;
177 int m_bInTransaction =
false;
178 int m_bAutoCommit =
true;
186 const char *pszPassword);
199 return m_bInTransaction;
206 int Failed(
int, HSTMT =
nullptr);
220 bool ConnectToMsAccess(
const char *pszName,
221 const char *pszDSNStringTemplate);
243 HSTMT m_hStmt =
nullptr;
245 SQLSMALLINT m_nColCount = 0;
246 char **m_papszColNames =
nullptr;
247 SQLSMALLINT *m_panColType =
nullptr;
248 char **m_papszColTypeNames =
nullptr;
249 CPL_SQLULEN *m_panColSize =
nullptr;
250 SQLSMALLINT *m_panColPrecision =
nullptr;
251 SQLSMALLINT *m_panColNullable =
nullptr;
252 char **m_papszColColumnDef =
nullptr;
254 char **m_papszColValues =
nullptr;
255 CPL_SQLLEN *m_panColValueLengths =
nullptr;
256 double *m_padColValuesAsDouble =
nullptr;
260 char *m_pszStatement =
nullptr;
261 size_t m_nStatementMax = 0;
262 size_t m_nStatementLen = 0;
307 void AppendEscaped(
const char *);
308 void Append(
const char *);
309 void Append(
const std::string &);
319 return m_pszStatement;
322 int ExecuteSQL(
const char * =
nullptr);
325 int Fetch(
int nOrientation = SQL_FETCH_NEXT,
int nOffset = 0);
326 void ClearColumnData();
329 const char *GetColName(
int);
330 short GetColType(
int);
331 const char *GetColTypeName(
int);
332 short GetColSize(
int);
333 short GetColPrecision(
int);
334 short GetColNullable(
int);
335 const char *GetColColumnDef(
int);
337 int GetColId(
const char *)
const;
338 const char *GetColData(
int,
const char * =
nullptr);
339 const char *GetColData(
const char *,
const char * =
nullptr);
340 int GetColDataLength(
int);
342 double GetColDataAsDouble(
int)
const;
343 double GetColDataAsDouble(
const char *)
const;
345 int GetRowCountAffected();
348 int GetColumns(
const char *pszTable,
const char *pszCatalog =
nullptr,
349 const char *pszSchema =
nullptr);
350 int GetPrimaryKeys(
const char *pszTable,
const char *pszCatalog =
nullptr,
351 const char *pszSchema =
nullptr);
353 int GetTables(
const char *pszCatalog =
nullptr,
354 const char *pszSchema =
nullptr);
356 void DumpResult(FILE *fp,
int bShowSchema = FALSE);
359 static SQLSMALLINT GetTypeMapping(SQLSMALLINT);
361 int CollectResultsInfo();
int GetUsageCount() const
The usage count of the driver after this function has been called.
Definition cpl_odbc.h:106
static void InstallMdbToolsDriver()
Attempts to install the MDB Tools driver for Microsoft Access databases.
Definition cpl_odbc.cpp:258
int InstallDriver(const char *pszDriver, const char *pszPathIn, WORD fRequest=ODBC_INSTALL_COMPLETE)
Installs ODBC driver or updates definition of already installed driver.
Definition cpl_odbc.cpp:60
int RemoveDriver(const char *pszDriverName, int fRemoveDSN=FALSE)
Removes or changes information about the driver from the Odbcinst.ini entry in the system information...
Definition cpl_odbc.cpp:318
const char * GetPathOut() const
Path of the target directory where the driver should be installed.
Definition cpl_odbc.h:115
const char * GetLastError() const
If InstallDriver returns FALSE, then GetLastError then error message can be obtained by calling this ...
Definition cpl_odbc.h:124
DWORD GetLastErrorCode() const
If InstallDriver returns FALSE, then GetLastErrorCode then error code can be obtained by calling this...
Definition cpl_odbc.h:134
A class representing an ODBC database session.
Definition cpl_odbc.h:168
int IsInTransaction()
Returns whether a transaction is active.
Definition cpl_odbc.h:197
HDBC GetConnection()
Return connection handle.
Definition cpl_odbc.h:209
const char * GetLastError()
Returns the last ODBC error message.
Definition cpl_odbc.cpp:756
int EstablishSession(const char *pszDSN, const char *pszUserid, const char *pszPassword)
Connect to database and logon.
Definition cpl_odbc.cpp:668
int ClearTransaction()
Clear transaction.
Definition cpl_odbc.cpp:391
HENV GetEnvironment()
Return GetEnvironment handle.
Definition cpl_odbc.h:215
int RollbackTransaction()
Rollback transaction.
Definition cpl_odbc.cpp:488
CPLODBCSession()
Constructor.
Definition cpl_odbc.cpp:343
int BeginTransaction()
Begin transaction.
Definition cpl_odbc.cpp:426
int CommitTransaction()
Commit transaction.
Definition cpl_odbc.cpp:465
Abstraction for statement, and resultset.
Definition cpl_odbc.h:234
int Flags() const
Returns statement flags.
Definition cpl_odbc.h:300
const char * GetCommand()
Return statement string.
Definition cpl_odbc.h:317
HSTMT GetStatement()
Return statement handle.
Definition cpl_odbc.h:292
CPLODBCStatement(CPLODBCSession *, int flags=0)
Constructor.
Definition cpl_odbc.cpp:778
Flag
Flags which control ODBC statement behavior.
Definition cpl_odbc.h:270
@ RetrieveNumericColumnsAsDouble
Numeric column values should be retrieved as doubles, using either the SQL_C_DOUBLE or SQL_C_FLOAT ty...
Definition cpl_odbc.h:285
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:860
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:844
#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:936
Various convenience functions for working with strings and string lists.