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 #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
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
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
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
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