Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

cpl_odbc.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  * $Id: cpl_odbc.h,v 1.7 2003/10/29 17:56:57 warmerda 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.7  2003/10/29 17:56:57  warmerda
00032  * Added PrimaryKeys() support
00033  *
00034  * Revision 1.6  2003/10/06 20:04:08  warmerda
00035  * added escaping support
00036  *
00037  * Revision 1.5  2003/10/06 17:16:18  warmerda
00038  * added windows.h for windows, and fixed m_panColSize type
00039  *
00040  * Revision 1.4  2003/09/26 20:02:41  warmerda
00041  * update GetColData()
00042  *
00043  * Revision 1.3  2003/09/26 13:51:02  warmerda
00044  * Add documentation
00045  *
00046  * Revision 1.2  2003/09/25 17:09:49  warmerda
00047  * added some more methods
00048  *
00049  * Revision 1.1  2003/09/24 15:39:14  warmerda
00050  * New
00051  *
00052  */
00053 
00054 #ifndef CPL_ODBC_H_INCLUDED
00055 #define CPL_ODBC_H_INCLUDED
00056 
00057 #include "cpl_port.h"
00058 
00059 #ifdef WIN32
00060 #  include <windows.h>
00061 #endif
00062 
00063 #include <sql.h>
00064 #include <sqlext.h>
00065 
00072 class CPLODBCStatement;
00073 
00080 class CPL_DLL CPLODBCSession {
00081     char      m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00082     HENV      m_hEnv;
00083     HDBC      m_hDBC;
00084 
00085   public:
00086     CPLODBCSession();
00087     ~CPLODBCSession();
00088 
00089     int         EstablishSession( const char *pszDSN, 
00090                                   const char *pszUserid, 
00091                                   const char *pszPassword );
00092     const char  *GetLastError();
00093 
00094     // Essentially internal. 
00095 
00096     int         CloseSession();
00097 
00098     int         Failed( int, HSTMT = NULL );
00099     HDBC        GetConnection() { return m_hDBC; }
00100     HENV        GetEnvironment()  { return m_hEnv; }
00101 };
00102 
00112 class CPL_DLL CPLODBCStatement {
00113 
00114     CPLODBCSession     *m_poSession;
00115     HSTMT               m_hStmt;
00116 
00117     short          m_nColCount;
00118     char         **m_papszColNames;
00119     short         *m_panColType;
00120     SQLUINTEGER   *m_panColSize;
00121     short         *m_panColPrecision;
00122     short         *m_panColNullable;
00123 
00124     char         **m_papszColValues;
00125     
00126     int            Failed( int );
00127 
00128     char          *m_pszStatement;
00129     int            m_nStatementMax;
00130     int            m_nStatementLen;
00131 
00132     int            CollectResultsInfo();
00133 
00134   public:
00135     CPLODBCStatement( CPLODBCSession * );
00136     ~CPLODBCStatement();
00137 
00138     HSTMT          GetStatement() { return m_hStmt; }
00139 
00140     // Command buffer related.
00141     void           Clear();
00142     void           AppendEscaped( const char * );
00143     void           Append( const char * );
00144     void           Append( int );
00145     void           Append( double );
00146     int            Appendf( const char *, ... );
00147     const char    *GetCommand() { return m_pszStatement; }
00148 
00149     int            ExecuteSQL( const char * = NULL );
00150 
00151     // Results fetching
00152     int            Fetch( int nOrientation = SQL_FETCH_NEXT, 
00153                           int nOffset = 0 );
00154     void           ClearColumnData();
00155 
00156     int            GetColCount();
00157     const char    *GetColName(int iCol);
00158     short          GetColType(int iCol);
00159     short          GetColSize(int iCol);
00160     short          GetColPrecision(int iCol);
00161     short          GetColNullable(int iCol);
00162 
00163     int            GetColId( const char * );
00164     const char    *GetColData( int, const char * = NULL );
00165     const char    *GetColData( const char *, const char * = NULL );
00166 
00167     // Fetch special metadata.
00168     int            GetColumns( const char *pszTable, 
00169                                const char *pszCatalog = NULL,
00170                                const char *pszSchema = NULL );
00171     int            GetPrimaryKeys( const char *pszTable, 
00172                                    const char *pszCatalog = NULL,
00173                                    const char *pszSchema = NULL );
00174 
00175     int            GetTables( const char *pszCatalog = NULL,
00176                               const char *pszSchema = NULL );
00177 
00178     void           DumpResult( FILE *fp, int bShowSchema = FALSE );
00179 
00180     static const char *GetTypeName( int );
00181 };
00182 
00183 
00184 
00185 #endif
00186 
00187 

Generated on Thu Nov 13 00:08:19 2003 for GDAL by doxygen 1.3.4