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