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 );
93 int InstallDriver(
const char* pszDriver,
const char* pszPathIn,
94 WORD fRequest = ODBC_INSTALL_COMPLETE );
103 static void InstallMdbToolsDriver();
121 int RemoveDriver(
const char* pszDriverName,
int fRemoveDSN = FALSE );
152 #if defined(_MSC_VER) && !defined(SQLULEN) && !defined(_WIN64)
153 # define MISSING_SQLULEN
157 #if !defined(MISSING_SQLULEN)
159 # define CPL_SQLULEN SQLULEN
160 # define CPL_SQLLEN SQLLEN
162 # define CPL_SQLULEN SQLUINTEGER
163 # define CPL_SQLLEN SQLINTEGER
178 HENV m_hEnv =
nullptr;
179 HDBC m_hDBC =
nullptr;
180 int m_bInTransaction =
false;
181 int m_bAutoCommit =
true;
187 int EstablishSession(
const char *pszDSN,
188 const char *pszUserid,
189 const char *pszPassword );
190 const char *GetLastError();
194 int ClearTransaction();
195 int BeginTransaction();
196 int CommitTransaction();
197 int RollbackTransaction();
205 int Failed(
int, HSTMT =
nullptr );
211 bool ConnectToMsAccess(
const char * pszName,
const char* pszDSNStringTemplate );
231 HSTMT m_hStmt =
nullptr;
233 SQLSMALLINT m_nColCount = 0;
234 char **m_papszColNames =
nullptr;
235 SQLSMALLINT *m_panColType =
nullptr;
236 char **m_papszColTypeNames =
nullptr;
237 CPL_SQLULEN *m_panColSize =
nullptr;
238 SQLSMALLINT *m_panColPrecision =
nullptr;
239 SQLSMALLINT *m_panColNullable =
nullptr;
240 char **m_papszColColumnDef =
nullptr;
242 char **m_papszColValues =
nullptr;
243 CPL_SQLLEN *m_panColValueLengths =
nullptr;
244 double *m_padColValuesAsDouble =
nullptr;
248 char *m_pszStatement =
nullptr;
249 size_t m_nStatementMax = 0;
250 size_t m_nStatementLen = 0;
269 RetrieveNumericColumnsAsDouble = 1 << 0,
281 int Flags()
const {
return m_nFlags; }
285 void AppendEscaped(
const char * );
286 void Append(
const char * );
288 void Append(
double );
291 const
char *GetCommand() {
return m_pszStatement; }
293 int ExecuteSQL(
const char * =
nullptr );
296 int Fetch(
int nOrientation = SQL_FETCH_NEXT,
298 void ClearColumnData();
301 const char *GetColName(
int );
302 short GetColType(
int );
303 const char *GetColTypeName(
int );
304 short GetColSize(
int );
305 short GetColPrecision(
int );
306 short GetColNullable(
int );
307 const char *GetColColumnDef(
int );
309 int GetColId(
const char * )
const;
310 const char *GetColData(
int,
const char * =
nullptr );
311 const char *GetColData(
const char *,
const char * =
nullptr );
312 int GetColDataLength(
int );
314 double GetColDataAsDouble(
int )
const;
315 double GetColDataAsDouble(
const char * )
const;
317 int GetRowCountAffected();
320 int GetColumns(
const char *pszTable,
321 const char *pszCatalog =
nullptr,
322 const char *pszSchema =
nullptr );
323 int GetPrimaryKeys(
const char *pszTable,
324 const char *pszCatalog =
nullptr,
325 const char *pszSchema =
nullptr );
327 int GetTables(
const char *pszCatalog =
nullptr,
328 const char *pszSchema =
nullptr );
330 void DumpResult( FILE *fp,
int bShowSchema = FALSE );
333 static SQLSMALLINT GetTypeMapping( SQLSMALLINT );
335 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:124
const char * GetLastError() const
If InstallDriver returns FALSE, then GetLastError then error message can be obtained by calling this ...
Definition: cpl_odbc.h:136
const char * GetPathOut() const
Path of the target directory where the driver should be installed.
Definition: cpl_odbc.h:130
DWORD GetLastErrorCode() const
If InstallDriver returns FALSE, then GetLastErrorCode then error code can be obtained by calling this...
Definition: cpl_odbc.h:143
A class representing an ODBC database session.
Definition: cpl_odbc.h:173
int IsInTransaction()
Returns whether a transaction is active.
Definition: cpl_odbc.h:199
HDBC GetConnection()
Return connection handle.
Definition: cpl_odbc.h:207
HENV GetEnvironment()
Return GetEnvironment handle.
Definition: cpl_odbc.h:209
Abstraction for statement, and resultset.
Definition: cpl_odbc.h:224
int Flags() const
Returns statement flags.
Definition: cpl_odbc.h:281
HSTMT GetStatement()
Return statement handle.
Definition: cpl_odbc.h:276
Flag
Flags which control ODBC statement behavior.
Definition: cpl_odbc.h:258
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:856
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:841
#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:927
Various convenience functions for working with strings and string lists.