cpl_odbc.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_odbc.h,v 1.11 2005/01/13 03:24:54 fwarmerdam 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.11  2005/01/13 03:24:54  fwarmerdam
00032  * changed type of m_panColSize, per ODBC 3.52 requirements
00033  *
00034  * Revision 1.10  2004/06/23 16:11:30  warmerda
00035  * just testing cvs commits
00036  *
00037  * Revision 1.9  2004/06/01 20:40:02  warmerda
00038  * expanded tabs
00039  *
00040  * Revision 1.8  2003/11/24 20:45:00  warmerda
00041  * make CollectResultsInfo() public
00042  *
00043  * Revision 1.7  2003/10/29 17:56:57  warmerda
00044  * Added PrimaryKeys() support
00045  *
00046  * Revision 1.6  2003/10/06 20:04:08  warmerda
00047  * added escaping support
00048  *
00049  * Revision 1.5  2003/10/06 17:16:18  warmerda
00050  * added windows.h for windows, and fixed m_panColSize type
00051  *
00052  * Revision 1.4  2003/09/26 20:02:41  warmerda
00053  * update GetColData()
00054  *
00055  * Revision 1.3  2003/09/26 13:51:02  warmerda
00056  * Add documentation
00057  *
00058  * Revision 1.2  2003/09/25 17:09:49  warmerda
00059  * added some more methods
00060  *
00061  * Revision 1.1  2003/09/24 15:39:14  warmerda
00062  * New
00063  *
00064  */
00065 
00066 #ifndef CPL_ODBC_H_INCLUDED
00067 #define CPL_ODBC_H_INCLUDED
00068 
00069 #include "cpl_port.h"
00070 
00071 #ifdef WIN32
00072 #  include <windows.h>
00073 #endif
00074 
00075 #include <sql.h>
00076 #include <sqlext.h>
00077 
00084 class CPLODBCStatement;
00085 
00086 
00087 #ifdef SQLULEN
00088 /* ODBC types to support 64 bit compilation */
00089 #  define _SQLULEN SQLULEN
00090 #  define _SQLLEN  SQLLEN
00091 #else
00092 #  define _SQLULEN SQLUINTEGER
00093 #  define _SQLLEN  SQLINTEGER
00094 #endif  /* ifdef SQLULEN */
00095 
00096 
00103 class CPL_DLL CPLODBCSession {
00104     char      m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00105     HENV      m_hEnv;
00106     HDBC      m_hDBC;
00107 
00108   public:
00109     CPLODBCSession();
00110     ~CPLODBCSession();
00111 
00112     int         EstablishSession( const char *pszDSN, 
00113                                   const char *pszUserid, 
00114                                   const char *pszPassword );
00115     const char  *GetLastError();
00116 
00117     // Essentially internal. 
00118 
00119     int         CloseSession();
00120 
00121     int         Failed( int, HSTMT = NULL );
00122     HDBC        GetConnection() { return m_hDBC; }
00123     HENV        GetEnvironment()  { return m_hEnv; }
00124 };
00125 
00135 class CPL_DLL CPLODBCStatement {
00136 
00137     CPLODBCSession     *m_poSession;
00138     HSTMT               m_hStmt;
00139 
00140     short          m_nColCount;
00141     char         **m_papszColNames;
00142     short         *m_panColType;
00143     _SQLULEN       *m_panColSize;
00144     short         *m_panColPrecision;
00145     short         *m_panColNullable;
00146 
00147     char         **m_papszColValues;
00148     
00149     int            Failed( int );
00150 
00151     char          *m_pszStatement;
00152     int            m_nStatementMax;
00153     int            m_nStatementLen;
00154 
00155   public:
00156     CPLODBCStatement( CPLODBCSession * );
00157     ~CPLODBCStatement();
00158 
00159     HSTMT          GetStatement() { return m_hStmt; }
00160 
00161     // Command buffer related.
00162     void           Clear();
00163     void           AppendEscaped( const char * );
00164     void           Append( const char * );
00165     void           Append( int );
00166     void           Append( double );
00167     int            Appendf( const char *, ... );
00168     const char    *GetCommand() { return m_pszStatement; }
00169 
00170     int            ExecuteSQL( const char * = NULL );
00171 
00172     // Results fetching
00173     int            Fetch( int nOrientation = SQL_FETCH_NEXT, 
00174                           int nOffset = 0 );
00175     void           ClearColumnData();
00176 
00177     int            GetColCount();
00178     const char    *GetColName(int iCol);
00179     short          GetColType(int iCol);
00180     short          GetColSize(int iCol);
00181     short          GetColPrecision(int iCol);
00182     short          GetColNullable(int iCol);
00183 
00184     int            GetColId( const char * );
00185     const char    *GetColData( int, const char * = NULL );
00186     const char    *GetColData( const char *, const char * = NULL );
00187 
00188     // Fetch special metadata.
00189     int            GetColumns( const char *pszTable, 
00190                                const char *pszCatalog = NULL,
00191                                const char *pszSchema = NULL );
00192     int            GetPrimaryKeys( const char *pszTable, 
00193                                    const char *pszCatalog = NULL,
00194                                    const char *pszSchema = NULL );
00195 
00196     int            GetTables( const char *pszCatalog = NULL,
00197                               const char *pszSchema = NULL );
00198 
00199     void           DumpResult( FILE *fp, int bShowSchema = FALSE );
00200 
00201     static const char *GetTypeName( int );
00202 
00203     int            CollectResultsInfo();
00204 };
00205 
00206 #endif
00207 
00208 

Generated on Mon Jan 9 18:03:31 2006 for OGR by  doxygen 1.4.6