Main Page | Class Hierarchy | Class List | Directories | 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.10 2004/06/23 16:11:30 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.10  2004/06/23 16:11:30  warmerda
00032  * just testing cvs commits
00033  *
00034  * Revision 1.9  2004/06/01 20:40:02  warmerda
00035  * expanded tabs
00036  *
00037  * Revision 1.8  2003/11/24 20:45:00  warmerda
00038  * make CollectResultsInfo() public
00039  *
00040  * Revision 1.7  2003/10/29 17:56:57  warmerda
00041  * Added PrimaryKeys() support
00042  *
00043  * Revision 1.6  2003/10/06 20:04:08  warmerda
00044  * added escaping support
00045  *
00046  * Revision 1.5  2003/10/06 17:16:18  warmerda
00047  * added windows.h for windows, and fixed m_panColSize type
00048  *
00049  * Revision 1.4  2003/09/26 20:02:41  warmerda
00050  * update GetColData()
00051  *
00052  * Revision 1.3  2003/09/26 13:51:02  warmerda
00053  * Add documentation
00054  *
00055  * Revision 1.2  2003/09/25 17:09:49  warmerda
00056  * added some more methods
00057  *
00058  * Revision 1.1  2003/09/24 15:39:14  warmerda
00059  * New
00060  *
00061  */
00062 
00063 #ifndef CPL_ODBC_H_INCLUDED
00064 #define CPL_ODBC_H_INCLUDED
00065 
00066 #include "cpl_port.h"
00067 
00068 #ifdef WIN32
00069 #  include <windows.h>
00070 #endif
00071 
00072 #include <sql.h>
00073 #include <sqlext.h>
00074 
00081 class CPLODBCStatement;
00082 
00089 class CPL_DLL CPLODBCSession {
00090     char      m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00091     HENV      m_hEnv;
00092     HDBC      m_hDBC;
00093 
00094   public:
00095     CPLODBCSession();
00096     ~CPLODBCSession();
00097 
00098     int         EstablishSession( const char *pszDSN, 
00099                                   const char *pszUserid, 
00100                                   const char *pszPassword );
00101     const char  *GetLastError();
00102 
00103     // Essentially internal. 
00104 
00105     int         CloseSession();
00106 
00107     int         Failed( int, HSTMT = NULL );
00108     HDBC        GetConnection() { return m_hDBC; }
00109     HENV        GetEnvironment()  { return m_hEnv; }
00110 };
00111 
00121 class CPL_DLL CPLODBCStatement {
00122 
00123     CPLODBCSession     *m_poSession;
00124     HSTMT               m_hStmt;
00125 
00126     short          m_nColCount;
00127     char         **m_papszColNames;
00128     short         *m_panColType;
00129     SQLUINTEGER   *m_panColSize;
00130     short         *m_panColPrecision;
00131     short         *m_panColNullable;
00132 
00133     char         **m_papszColValues;
00134     
00135     int            Failed( int );
00136 
00137     char          *m_pszStatement;
00138     int            m_nStatementMax;
00139     int            m_nStatementLen;
00140 
00141   public:
00142     CPLODBCStatement( CPLODBCSession * );
00143     ~CPLODBCStatement();
00144 
00145     HSTMT          GetStatement() { return m_hStmt; }
00146 
00147     // Command buffer related.
00148     void           Clear();
00149     void           AppendEscaped( const char * );
00150     void           Append( const char * );
00151     void           Append( int );
00152     void           Append( double );
00153     int            Appendf( const char *, ... );
00154     const char    *GetCommand() { return m_pszStatement; }
00155 
00156     int            ExecuteSQL( const char * = NULL );
00157 
00158     // Results fetching
00159     int            Fetch( int nOrientation = SQL_FETCH_NEXT, 
00160                           int nOffset = 0 );
00161     void           ClearColumnData();
00162 
00163     int            GetColCount();
00164     const char    *GetColName(int iCol);
00165     short          GetColType(int iCol);
00166     short          GetColSize(int iCol);
00167     short          GetColPrecision(int iCol);
00168     short          GetColNullable(int iCol);
00169 
00170     int            GetColId( const char * );
00171     const char    *GetColData( int, const char * = NULL );
00172     const char    *GetColData( const char *, const char * = NULL );
00173 
00174     // Fetch special metadata.
00175     int            GetColumns( const char *pszTable, 
00176                                const char *pszCatalog = NULL,
00177                                const char *pszSchema = NULL );
00178     int            GetPrimaryKeys( const char *pszTable, 
00179                                    const char *pszCatalog = NULL,
00180                                    const char *pszSchema = NULL );
00181 
00182     int            GetTables( const char *pszCatalog = NULL,
00183                               const char *pszSchema = NULL );
00184 
00185     void           DumpResult( FILE *fp, int bShowSchema = FALSE );
00186 
00187     static const char *GetTypeName( int );
00188 
00189     int            CollectResultsInfo();
00190 };
00191 
00192 #endif
00193 
00194 

Generated on Tue Mar 15 07:12:56 2005 for OGR by  doxygen 1.4.0