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 #ifndef CPL_ODBC_H_INCLUDED
00055 #define CPL_ODBC_H_INCLUDED
00056
00057 #include "cpl_port.h"
00058
00059 #ifdef WIN32
00060 # include <windows.h>
00061 #endif
00062
00063 #include <sql.h>
00064 #include <sqlext.h>
00065
00072 class CPLODBCStatement;
00073
00080 class CPL_DLL CPLODBCSession {
00081 char m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00082 HENV m_hEnv;
00083 HDBC m_hDBC;
00084
00085 public:
00086 CPLODBCSession();
00087 ~CPLODBCSession();
00088
00089 int EstablishSession( const char *pszDSN,
00090 const char *pszUserid,
00091 const char *pszPassword );
00092 const char *GetLastError();
00093
00094
00095
00096 int CloseSession();
00097
00098 int Failed( int, HSTMT = NULL );
00099 HDBC GetConnection() { return m_hDBC; }
00100 HENV GetEnvironment() { return m_hEnv; }
00101 };
00102
00112 class CPL_DLL CPLODBCStatement {
00113
00114 CPLODBCSession *m_poSession;
00115 HSTMT m_hStmt;
00116
00117 short m_nColCount;
00118 char **m_papszColNames;
00119 short *m_panColType;
00120 SQLUINTEGER *m_panColSize;
00121 short *m_panColPrecision;
00122 short *m_panColNullable;
00123
00124 char **m_papszColValues;
00125
00126 int Failed( int );
00127
00128 char *m_pszStatement;
00129 int m_nStatementMax;
00130 int m_nStatementLen;
00131
00132 int CollectResultsInfo();
00133
00134 public:
00135 CPLODBCStatement( CPLODBCSession * );
00136 ~CPLODBCStatement();
00137
00138 HSTMT GetStatement() { return m_hStmt; }
00139
00140
00141 void Clear();
00142 void AppendEscaped( const char * );
00143 void Append( const char * );
00144 void Append( int );
00145 void Append( double );
00146 int Appendf( const char *, ... );
00147 const char *GetCommand() { return m_pszStatement; }
00148
00149 int ExecuteSQL( const char * = NULL );
00150
00151
00152 int Fetch( int nOrientation = SQL_FETCH_NEXT,
00153 int nOffset = 0 );
00154 void ClearColumnData();
00155
00156 int GetColCount();
00157 const char *GetColName(int iCol);
00158 short GetColType(int iCol);
00159 short GetColSize(int iCol);
00160 short GetColPrecision(int iCol);
00161 short GetColNullable(int iCol);
00162
00163 int GetColId( const char * );
00164 const char *GetColData( int, const char * = NULL );
00165 const char *GetColData( const char *, const char * = NULL );
00166
00167
00168 int GetColumns( const char *pszTable,
00169 const char *pszCatalog = NULL,
00170 const char *pszSchema = NULL );
00171 int GetPrimaryKeys( const char *pszTable,
00172 const char *pszCatalog = NULL,
00173 const char *pszSchema = NULL );
00174
00175 int GetTables( const char *pszCatalog = NULL,
00176 const char *pszSchema = NULL );
00177
00178 void DumpResult( FILE *fp, int bShowSchema = FALSE );
00179
00180 static const char *GetTypeName( int );
00181 };
00182
00183
00184
00185 #endif
00186
00187