- Main Page
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# cpl_odbc.h

Go to the documentation of this file.

    00001 /******************************************************************************
    00002  * $Id: cpl_odbc.h,v 1.16 2006/04/03 23:08:58 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.16  2006/04/03 23:08:58  fwarmerdam
    00032  * Use SQLULEN by default now.
    00033  *
    00034  * Revision 1.15  2006/02/19 21:54:34  mloskot
    00035  * [WINCE] Changes related to Windows CE port of CPL. Most changes are #ifdef wrappers.
    00036  *
    00037  * Revision 1.14  2005/09/05 20:18:43  fwarmerdam
    00038  * added binary column support
    00039  *
    00040  * Revision 1.13  2005/08/31 03:32:41  fwarmerdam
    00041  * GetTypeName now returns CPLString
    00042  *
    00043  * Revision 1.12  2005/06/29 01:01:01  ssoule
    00044  * Changed return type of CPLODBCStatement::GetTypeName from const char * to
    00045  * std::string.
    00046  *
    00047  * Revision 1.11  2005/01/13 03:24:54  fwarmerdam
    00048  * changed type of m_panColSize, per ODBC 3.52 requirements
    00049  *
    00050  * Revision 1.10  2004/06/23 16:11:30  warmerda
    00051  * just testing cvs commits
    00052  *
    00053  * Revision 1.9  2004/06/01 20:40:02  warmerda
    00054  * expanded tabs
    00055  *
    00056  * Revision 1.8  2003/11/24 20:45:00  warmerda
    00057  * make CollectResultsInfo() public
    00058  *
    00059  * Revision 1.7  2003/10/29 17:56:57  warmerda
    00060  * Added PrimaryKeys() support
    00061  *
    00062  * Revision 1.6  2003/10/06 20:04:08  warmerda
    00063  * added escaping support
    00064  *
    00065  * Revision 1.5  2003/10/06 17:16:18  warmerda
    00066  * added windows.h for windows, and fixed m_panColSize type
    00067  *
    00068  * Revision 1.4  2003/09/26 20:02:41  warmerda
    00069  * update GetColData()
    00070  *
    00071  * Revision 1.3  2003/09/26 13:51:02  warmerda
    00072  * Add documentation
    00073  *
    00074  * Revision 1.2  2003/09/25 17:09:49  warmerda
    00075  * added some more methods
    00076  *
    00077  * Revision 1.1  2003/09/24 15:39:14  warmerda
    00078  * New
    00079  *
    00080  */
    00081
    00082 #ifndef CPL_ODBC_H_INCLUDED
    00083 #define CPL_ODBC_H_INCLUDED
    00084
    00085 #include "cpl_port.h"
    00086
    00087 #ifndef WIN32CE /* ODBC is not supported on Windows CE. */
    00088
    00089 #ifdef WIN32
    00090 #  include <windows.h>
    00091 #endif
    00092
    00093 #include <sql.h>
    00094 #include <sqlext.h>
    00095 #include "cpl_string.h"
    00096
    00103 class CPLODBCStatement;
    00104
    00105
    00106 #if !defined(MISSING_SQLULEN)
    00107 /* ODBC types to support 64 bit compilation */
    00108 #  define _SQLULEN SQLULEN
    00109 #  define _SQLLEN  SQLLEN
    00110 #else
    00111 #  define _SQLULEN SQLUINTEGER
    00112 #  define _SQLLEN  SQLINTEGER
    00113 #endif  /* ifdef SQLULEN */
    00114
    00115
    00122 class CPL_DLL CPLODBCSession {
    00123     char      m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
    00124     HENV      m_hEnv;
    00125     HDBC      m_hDBC;
    00126
    00127   public:
    00128     CPLODBCSession();
    00129     ~CPLODBCSession();
    00130
    00131     int         EstablishSession( const char *pszDSN,
    00132                                   const char *pszUserid,
    00133                                   const char *pszPassword );
    00134     const char  *GetLastError();
    00135
    00136     // Essentially internal.
    00137
    00138     int         CloseSession();
    00139
    00140     int         Failed( int, HSTMT = NULL );
    00141     HDBC        GetConnection() { return m_hDBC; }
    00142     HENV        GetEnvironment()  { return m_hEnv; }
    00143 };
    00144
    00154 class CPL_DLL CPLODBCStatement {
    00155
    00156     CPLODBCSession     *m_poSession;
    00157     HSTMT               m_hStmt;
    00158
    00159     short          m_nColCount;
    00160     char         **m_papszColNames;
    00161     short         *m_panColType;
    00162     _SQLULEN       *m_panColSize;
    00163     short         *m_panColPrecision;
    00164     short         *m_panColNullable;
    00165
    00166     char         **m_papszColValues;
    00167     int           *m_panColValueLengths;
    00168
    00169     int            Failed( int );
    00170
    00171     char          *m_pszStatement;
    00172     int            m_nStatementMax;
    00173     int            m_nStatementLen;
    00174
    00175   public:
    00176     CPLODBCStatement( CPLODBCSession * );
    00177     ~CPLODBCStatement();
    00178
    00179     HSTMT          GetStatement() { return m_hStmt; }
    00180
    00181     // Command buffer related.
    00182     void           Clear();
    00183     void           AppendEscaped( const char * );
    00184     void           Append( const char * );
    00185     void           Append( int );
    00186     void           Append( double );
    00187     int            Appendf( const char *, ... );
    00188     const char    *GetCommand() { return m_pszStatement; }
    00189
    00190     int            ExecuteSQL( const char * = NULL );
    00191
    00192     // Results fetching
    00193     int            Fetch( int nOrientation = SQL_FETCH_NEXT,
    00194                           int nOffset = 0 );
    00195     void           ClearColumnData();
    00196
    00197     int            GetColCount();
    00198     const char    *GetColName(int iCol);
    00199     short          GetColType(int iCol);
    00200     short          GetColSize(int iCol);
    00201     short          GetColPrecision(int iCol);
    00202     short          GetColNullable(int iCol);
    00203
    00204     int            GetColId( const char * );
    00205     const char    *GetColData( int, const char * = NULL );
    00206     const char    *GetColData( const char *, const char * = NULL );
    00207     int            GetColDataLength( int );
    00208
    00209     // Fetch special metadata.
    00210     int            GetColumns( const char *pszTable,
    00211                                const char *pszCatalog = NULL,
    00212                                const char *pszSchema = NULL );
    00213     int            GetPrimaryKeys( const char *pszTable,
    00214                                    const char *pszCatalog = NULL,
    00215                                    const char *pszSchema = NULL );
    00216
    00217     int            GetTables( const char *pszCatalog = NULL,
    00218                               const char *pszSchema = NULL );
    00219
    00220     void           DumpResult( FILE *fp, int bShowSchema = FALSE );
    00221
    00222     static CPLString GetTypeName( int );
    00223
    00224     int            CollectResultsInfo();
    00225 };
    00226
    00227 #endif /* #ifndef WIN32CE */
    00228
    00229 #endif
    00230
    00231

Generated for GDAL by 1.4.5.