00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
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
00089 # define _SQLULEN SQLULEN
00090 # define _SQLLEN SQLLEN
00091 #else
00092 # define _SQLULEN SQLUINTEGER
00093 # define _SQLLEN SQLINTEGER
00094 #endif
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
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
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
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
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