- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# cpl_odbc.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: cpl_odbc.h,v 1.21 2006/10/19 17:22:54 dron Exp $
    00003  *
    00004  * Project:  OGR ODBC Driver
    00005  * Purpose:  Declarations for ODBC Access Cover API.
    00006  * Author:   Frank Warmerdam, warmerdam@pobox.com
    00007  *
    00008  ******************************************************************************
    00009  * Copyright (c) 2003, Frank Warmerdam
    00010  *
    00011  * Permission is hereby granted, free of charge, to any person obtaining a
    00012  * copy of this software and associated documentation files (the "Software"),
    00013  * to deal in the Software without restriction, including without limitation
    00014  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00015  * and/or sell copies of the Software, and to permit persons to whom the
    00016  * Software is furnished to do so, subject to the following conditions:
    00017  *
    00018  * The above copyright notice and this permission notice shall be included
    00019  * in all copies or substantial portions of the Software.
    00020  *
    00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    00022  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00023  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    00024  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00025  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00026  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00027  * DEALINGS IN THE SOFTWARE.
    00028  ******************************************************************************
    00029  *
    00030  * $Log: cpl_odbc.h,v $
    00031  * Revision 1.21  2006/10/19 17:22:54  dron
    00032  * Added GetTypeMapping() conversion function; numerous clean-ups.
    00033  *
    00034  * Revision 1.20  2006/06/30 18:15:35  dron
    00035  * Avoid warnings on win64 target.
    00036  *
    00037  * Revision 1.19  2006/06/30 18:00:20  dron
    00038  * Do not define MISSING_SQLULEN on MSVC/x64 target.
    00039  *
    00040  * Revision 1.18  2006/06/01 12:15:39  mloskot
    00041  * Added CPLODBCDriverInstaller utility class to CPL.
    00042  *
    00043  * Revision 1.17  2006/05/12 15:22:23  fwarmerdam
    00044  * on MSVC 6 we sometimes dont have SQLULEN
    00045  *
    00046  * Revision 1.16  2006/04/03 23:08:58  fwarmerdam
    00047  * Use SQLULEN by default now.
    00048  *
    00049  * Revision 1.15  2006/02/19 21:54:34  mloskot
    00050  * [WINCE] Changes related to Windows CE port of CPL. Most changes are #ifdef wrappers.
    00051  *
    00052  * Revision 1.14  2005/09/05 20:18:43  fwarmerdam
    00053  * added binary column support
    00054  *
    00055  * Revision 1.13  2005/08/31 03:32:41  fwarmerdam
    00056  * GetTypeName now returns CPLString
    00057  *
    00058  * Revision 1.12  2005/06/29 01:01:01  ssoule
    00059  * Changed return type of CPLODBCStatement::GetTypeName from const char * to
    00060  * std::string.
    00061  *
    00062  * Revision 1.11  2005/01/13 03:24:54  fwarmerdam
    00063  * changed type of m_panColSize, per ODBC 3.52 requirements
    00064  *
    00065  * Revision 1.10  2004/06/23 16:11:30  warmerda
    00066  * just testing cvs commits
    00067  *
    00068  * Revision 1.9  2004/06/01 20:40:02  warmerda
    00069  * expanded tabs
    00070  *
    00071  * Revision 1.8  2003/11/24 20:45:00  warmerda
    00072  * make CollectResultsInfo() public
    00073  *
    00074  * Revision 1.7  2003/10/29 17:56:57  warmerda
    00075  * Added PrimaryKeys() support
    00076  *
    00077  * Revision 1.6  2003/10/06 20:04:08  warmerda
    00078  * added escaping support
    00079  *
    00080  * Revision 1.5  2003/10/06 17:16:18  warmerda
    00081  * added windows.h for windows, and fixed m_panColSize type
    00082  *
    00083  * Revision 1.4  2003/09/26 20:02:41  warmerda
    00084  * update GetColData()
    00085  *
    00086  * Revision 1.3  2003/09/26 13:51:02  warmerda
    00087  * Add documentation
    00088  *
    00089  * Revision 1.2  2003/09/25 17:09:49  warmerda
    00090  * added some more methods
    00091  *
    00092  * Revision 1.1  2003/09/24 15:39:14  warmerda
    00093  * New
    00094  *
    00095  */
    00096
    00097 #ifndef CPL_ODBC_H_INCLUDED
    00098 #define CPL_ODBC_H_INCLUDED
    00099
    00100 #include "cpl_port.h"
    00101
    00102 #ifndef WIN32CE /* ODBC is not supported on Windows CE. */
    00103
    00104 #ifdef WIN32
    00105 #  include <windows.h>
    00106 #endif
    00107
    00108 #include <sql.h>
    00109 #include <sqlext.h>
    00110 #include <odbcinst.h>
    00111 #include "cpl_string.h"
    00112
    00113 #ifdef PATH_MAX
    00114 #  define ODBC_FILENAME_MAX PATH_MAX
    00115 #else
    00116 #  define ODBC_FILENAME_MAX (255 + 1) /* Max path length */
    00117 #endif
    00118
    00119
    00129 class CPL_DLL CPLODBCDriverInstaller
    00130 {
    00131     char m_szPathOut[ODBC_FILENAME_MAX];
    00132     char m_szError[SQL_MAX_MESSAGE_LENGTH];
    00133     DWORD m_nErrorCode;
    00134     DWORD m_nUsageCount;
    00135
    00136   public:
    00137
    00138     // Default constructor.
    00139     CPLODBCDriverInstaller();
    00140
    00141
    00159     int InstallDriver( const char* pszDriver, const char* pszPathIn,
    00160             WORD fRequest = ODBC_INSTALL_COMPLETE );
    00161
    00178     int RemoveDriver( const char* pszDriverName, int fRemoveDSN = FALSE );
    00179
    00180
    00181     // The usage count of the driver after this function has been called
    00182     int GetUsageCount() const {  return m_nUsageCount; }
    00183
    00184
    00185     // Path of the target directory where the driver should be installed.
    00186     // For details, see ODBC API Reference and lpszPathOut
    00187     // parameter of SQLInstallDriverEx
    00188     const char* GetPathOut() const { return m_szPathOut; }
    00189
    00190
    00191     // If InstallDriver returns FALSE, then GetLastError then
    00192     // error message can be obtained by calling this function.
    00193     // Internally, it calls ODBC's SQLInstallerError function.
    00194     const char* GetLastError() const { return m_szError; }
    00195
    00196
    00197     // If InstallDriver returns FALSE, then GetLastErrorCode then
    00198     // error code can be obtained by calling this function.
    00199     // Internally, it calls ODBC's SQLInstallerError function.
    00200     // See ODBC API Reference for possible error flags.
    00201     DWORD GetLastErrorCode() const { return m_nErrorCode; }
    00202 };
    00203
    00204 class CPLODBCStatement;
    00205
    00206 /* On MSVC SQLULEN is missing in some cases (ie. VC6)
    00207 ** but it is always a #define so test this way.   On Unix
    00208 ** it is a typedef so we can't always do this.
    00209 */
    00210 #if defined(_MSC_VER) && !defined(SQLULEN) && !defined(_WIN64)
    00211 #  define MISSING_SQLULEN
    00212 #endif
    00213
    00214 #if !defined(MISSING_SQLULEN)
    00215 /* ODBC types to support 64 bit compilation */
    00216 #  define _SQLULEN SQLULEN
    00217 #  define _SQLLEN  SQLLEN
    00218 #else
    00219 #  define _SQLULEN SQLUINTEGER
    00220 #  define _SQLLEN  SQLINTEGER
    00221 #endif  /* ifdef SQLULEN */
    00222
    00223
    00230 class CPL_DLL CPLODBCSession {
    00231     char      m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
    00232     HENV      m_hEnv;
    00233     HDBC      m_hDBC;
    00234
    00235   public:
    00236     CPLODBCSession();
    00237     ~CPLODBCSession();
    00238
    00239     int         EstablishSession( const char *pszDSN,
    00240                                   const char *pszUserid,
    00241                                   const char *pszPassword );
    00242     const char  *GetLastError();
    00243
    00244     // Essentially internal.
    00245
    00246     int         CloseSession();
    00247
    00248     int         Failed( int, HSTMT = NULL );
    00249     HDBC        GetConnection() { return m_hDBC; }
    00250     HENV        GetEnvironment()  { return m_hEnv; }
    00251 };
    00252
    00262 class CPL_DLL CPLODBCStatement {
    00263
    00264     CPLODBCSession     *m_poSession;
    00265     HSTMT               m_hStmt;
    00266
    00267     SQLSMALLINT    m_nColCount;
    00268     char         **m_papszColNames;
    00269     SQLSMALLINT   *m_panColType;
    00270     char         **m_papszColTypeNames;
    00271     _SQLULEN      *m_panColSize;
    00272     SQLSMALLINT   *m_panColPrecision;
    00273     SQLSMALLINT   *m_panColNullable;
    00274
    00275     char         **m_papszColValues;
    00276     _SQLLEN       *m_panColValueLengths;
    00277
    00278     int            Failed( int );
    00279
    00280     char          *m_pszStatement;
    00281     size_t         m_nStatementMax;
    00282     size_t         m_nStatementLen;
    00283
    00284   public:
    00285     CPLODBCStatement( CPLODBCSession * );
    00286     ~CPLODBCStatement();
    00287
    00288     HSTMT          GetStatement() { return m_hStmt; }
    00289
    00290     // Command buffer related.
    00291     void           Clear();
    00292     void           AppendEscaped( const char * );
    00293     void           Append( const char * );
    00294     void           Append( int );
    00295     void           Append( double );
    00296     int            Appendf( const char *, ... );
    00297     const char    *GetCommand() { return m_pszStatement; }
    00298
    00299     int            ExecuteSQL( const char * = NULL );
    00300
    00301     // Results fetching
    00302     int            Fetch( int nOrientation = SQL_FETCH_NEXT,
    00303                           int nOffset = 0 );
    00304     void           ClearColumnData();
    00305
    00306     int            GetColCount();
    00307     const char    *GetColName( int );
    00308     short          GetColType( int );
    00309     const char    *GetColTypeName( int );
    00310     short          GetColSize( int );
    00311     short          GetColPrecision( int );
    00312     short          GetColNullable( int );
    00313
    00314     int            GetColId( const char * );
    00315     const char    *GetColData( int, const char * = NULL );
    00316     const char    *GetColData( const char *, const char * = NULL );
    00317     int            GetColDataLength( int );
    00318
    00319     // Fetch special metadata.
    00320     int            GetColumns( const char *pszTable,
    00321                                const char *pszCatalog = NULL,
    00322                                const char *pszSchema = NULL );
    00323     int            GetPrimaryKeys( const char *pszTable,
    00324                                    const char *pszCatalog = NULL,
    00325                                    const char *pszSchema = NULL );
    00326
    00327     int            GetTables( const char *pszCatalog = NULL,
    00328                               const char *pszSchema = NULL );
    00329
    00330     void           DumpResult( FILE *fp, int bShowSchema = FALSE );
    00331
    00332     static CPLString GetTypeName( int );
    00333     static SQLSMALLINT GetTypeMapping( SQLSMALLINT );
    00334
    00335     int            CollectResultsInfo();
    00336 };
    00337
    00338 #endif /* #ifndef WIN32CE */
    00339
    00340 #endif
    00341
    00342

Generated for GDAL by 1.5.1.