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
00067
00068
00069
00070 #ifndef CPL_ODBC_H_INCLUDED
00071 #define CPL_ODBC_H_INCLUDED
00072
00073 #include "cpl_port.h"
00074
00075 #ifdef WIN32
00076 # include <windows.h>
00077 #endif
00078
00079 #include <sql.h>
00080 #include <sqlext.h>
00081 #include <string>
00082
00089 class CPLODBCStatement;
00090
00091
00092 #ifdef SQLULEN
00093
00094 # define _SQLULEN SQLULEN
00095 # define _SQLLEN SQLLEN
00096 #else
00097 # define _SQLULEN SQLUINTEGER
00098 # define _SQLLEN SQLINTEGER
00099 #endif
00100
00101
00108 class CPL_DLL CPLODBCSession {
00109 char m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00110 HENV m_hEnv;
00111 HDBC m_hDBC;
00112
00113 public:
00114 CPLODBCSession();
00115 ~CPLODBCSession();
00116
00117 int EstablishSession( const char *pszDSN,
00118 const char *pszUserid,
00119 const char *pszPassword );
00120 const char *GetLastError();
00121
00122
00123
00124 int CloseSession();
00125
00126 int Failed( int, HSTMT = NULL );
00127 HDBC GetConnection() { return m_hDBC; }
00128 HENV GetEnvironment() { return m_hEnv; }
00129 };
00130
00140 class CPL_DLL CPLODBCStatement {
00141
00142 CPLODBCSession *m_poSession;
00143 HSTMT m_hStmt;
00144
00145 short m_nColCount;
00146 char **m_papszColNames;
00147 short *m_panColType;
00148 _SQLULEN *m_panColSize;
00149 short *m_panColPrecision;
00150 short *m_panColNullable;
00151
00152 char **m_papszColValues;
00153
00154 int Failed( int );
00155
00156 char *m_pszStatement;
00157 int m_nStatementMax;
00158 int m_nStatementLen;
00159
00160 public:
00161 CPLODBCStatement( CPLODBCSession * );
00162 ~CPLODBCStatement();
00163
00164 HSTMT GetStatement() { return m_hStmt; }
00165
00166
00167 void Clear();
00168 void AppendEscaped( const char * );
00169 void Append( const char * );
00170 void Append( int );
00171 void Append( double );
00172 int Appendf( const char *, ... );
00173 const char *GetCommand() { return m_pszStatement; }
00174
00175 int ExecuteSQL( const char * = NULL );
00176
00177
00178 int Fetch( int nOrientation = SQL_FETCH_NEXT,
00179 int nOffset = 0 );
00180 void ClearColumnData();
00181
00182 int GetColCount();
00183 const char *GetColName(int iCol);
00184 short GetColType(int iCol);
00185 short GetColSize(int iCol);
00186 short GetColPrecision(int iCol);
00187 short GetColNullable(int iCol);
00188
00189 int GetColId( const char * );
00190 const char *GetColData( int, const char * = NULL );
00191 const char *GetColData( const char *, const char * = NULL );
00192
00193
00194 int GetColumns( const char *pszTable,
00195 const char *pszCatalog = NULL,
00196 const char *pszSchema = NULL );
00197 int GetPrimaryKeys( const char *pszTable,
00198 const char *pszCatalog = NULL,
00199 const char *pszSchema = NULL );
00200
00201 int GetTables( const char *pszCatalog = NULL,
00202 const char *pszSchema = NULL );
00203
00204 void DumpResult( FILE *fp, int bShowSchema = FALSE );
00205
00206 static std::string GetTypeName( int );
00207
00208 int CollectResultsInfo();
00209 };
00210
00211 #endif
00212
00213