cpl_odbc.h

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

Generated on Sun Jul 2 22:18:21 2006 for OGR by  doxygen 1.4.6