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 #ifndef CPL_ODBC_H_INCLUDED
00046 #define CPL_ODBC_H_INCLUDED
00047
00048 #include "cpl_port.h"
00049
00050 #include <sql.h>
00051 #include <sqlext.h>
00052
00059 class CPLODBCStatement;
00060
00067 class CPL_DLL CPLODBCSession {
00068 char m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00069 HENV m_hEnv;
00070 HDBC m_hDBC;
00071
00072 public:
00073 CPLODBCSession();
00074 ~CPLODBCSession();
00075
00076 int EstablishSession( const char *pszDSN,
00077 const char *pszUserid,
00078 const char *pszPassword );
00079 const char *GetLastError();
00080
00081
00082
00083 int CloseSession();
00084
00085 int Failed( int, HSTMT = NULL );
00086 HDBC GetConnection() { return m_hDBC; }
00087 HENV GetEnvironment() { return m_hEnv; }
00088 };
00089
00099 class CPL_DLL CPLODBCStatement {
00100
00101 CPLODBCSession *m_poSession;
00102 HSTMT m_hStmt;
00103
00104 short m_nColCount;
00105 char **m_papszColNames;
00106 short *m_panColType;
00107 SQLULEN *m_panColSize;
00108 short *m_panColPrecision;
00109 short *m_panColNullable;
00110
00111 char **m_papszColValues;
00112
00113 int Failed( int );
00114
00115 char *m_pszStatement;
00116 int m_nStatementMax;
00117 int m_nStatementLen;
00118
00119 int CollectResultsInfo();
00120
00121 public:
00122 CPLODBCStatement( CPLODBCSession * );
00123 ~CPLODBCStatement();
00124
00125 HSTMT GetStatement() { return m_hStmt; }
00126
00127
00128 void Clear();
00129 void Append( const char * );
00130 void Append( int );
00131 void Append( double );
00132 int Appendf( const char *, ... );
00133 const char *GetCommand() { return m_pszStatement; }
00134
00135 int ExecuteSQL( const char * = NULL );
00136
00137
00138 int Fetch( int nOrientation = SQL_FETCH_NEXT,
00139 int nOffset = 0 );
00140 void ClearColumnData();
00141
00142 int GetColCount();
00143 const char *GetColName(int iCol);
00144 short GetColType(int iCol);
00145 short GetColSize(int iCol);
00146 short GetColPrecision(int iCol);
00147 short GetColNullable(int iCol);
00148
00149 int GetColId( const char * );
00150 const char *GetColData( int, const char * = NULL );
00151 const char *GetColData( const char *, const char * = NULL );
00152
00153
00154 int GetColumns( const char *pszTable,
00155 const char *pszCatalog = NULL,
00156 const char *pszSchema = NULL );
00157
00158 int GetTables( const char *pszCatalog = NULL,
00159 const char *pszSchema = NULL );
00160
00161 void DumpResult( FILE *fp, int bShowSchema = FALSE );
00162
00163 static const char *GetTypeName( int );
00164 };
00165
00166
00167
00168 #endif
00169
00170