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
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #ifndef CPL_ODBC_H_INCLUDED
00083 #define CPL_ODBC_H_INCLUDED
00084
00085 #include "cpl_port.h"
00086
00087 #ifndef WIN32CE
00088
00089 #ifdef WIN32
00090 # include <windows.h>
00091 #endif
00092
00093 #include <sql.h>
00094 #include <sqlext.h>
00095 #include "cpl_string.h"
00096
00103 class CPLODBCStatement;
00104
00105
00106 #if !defined(MISSING_SQLULEN)
00107
00108 # define _SQLULEN SQLULEN
00109 # define _SQLLEN SQLLEN
00110 #else
00111 # define _SQLULEN SQLUINTEGER
00112 # define _SQLLEN SQLINTEGER
00113 #endif
00114
00115
00122 class CPL_DLL CPLODBCSession {
00123 char m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00124 HENV m_hEnv;
00125 HDBC m_hDBC;
00126
00127 public:
00128 CPLODBCSession();
00129 ~CPLODBCSession();
00130
00131 int EstablishSession( const char *pszDSN,
00132 const char *pszUserid,
00133 const char *pszPassword );
00134 const char *GetLastError();
00135
00136
00137
00138 int CloseSession();
00139
00140 int Failed( int, HSTMT = NULL );
00141 HDBC GetConnection() { return m_hDBC; }
00142 HENV GetEnvironment() { return m_hEnv; }
00143 };
00144
00154 class CPL_DLL CPLODBCStatement {
00155
00156 CPLODBCSession *m_poSession;
00157 HSTMT m_hStmt;
00158
00159 short m_nColCount;
00160 char **m_papszColNames;
00161 short *m_panColType;
00162 _SQLULEN *m_panColSize;
00163 short *m_panColPrecision;
00164 short *m_panColNullable;
00165
00166 char **m_papszColValues;
00167 int *m_panColValueLengths;
00168
00169 int Failed( int );
00170
00171 char *m_pszStatement;
00172 int m_nStatementMax;
00173 int m_nStatementLen;
00174
00175 public:
00176 CPLODBCStatement( CPLODBCSession * );
00177 ~CPLODBCStatement();
00178
00179 HSTMT GetStatement() { return m_hStmt; }
00180
00181
00182 void Clear();
00183 void AppendEscaped( const char * );
00184 void Append( const char * );
00185 void Append( int );
00186 void Append( double );
00187 int Appendf( const char *, ... );
00188 const char *GetCommand() { return m_pszStatement; }
00189
00190 int ExecuteSQL( const char * = NULL );
00191
00192
00193 int Fetch( int nOrientation = SQL_FETCH_NEXT,
00194 int nOffset = 0 );
00195 void ClearColumnData();
00196
00197 int GetColCount();
00198 const char *GetColName(int iCol);
00199 short GetColType(int iCol);
00200 short GetColSize(int iCol);
00201 short GetColPrecision(int iCol);
00202 short GetColNullable(int iCol);
00203
00204 int GetColId( const char * );
00205 const char *GetColData( int, const char * = NULL );
00206 const char *GetColData( const char *, const char * = NULL );
00207 int GetColDataLength( int );
00208
00209
00210 int GetColumns( const char *pszTable,
00211 const char *pszCatalog = NULL,
00212 const char *pszSchema = NULL );
00213 int GetPrimaryKeys( const char *pszTable,
00214 const char *pszCatalog = NULL,
00215 const char *pszSchema = NULL );
00216
00217 int GetTables( const char *pszCatalog = NULL,
00218 const char *pszSchema = NULL );
00219
00220 void DumpResult( FILE *fp, int bShowSchema = FALSE );
00221
00222 static CPLString GetTypeName( int );
00223
00224 int CollectResultsInfo();
00225 };
00226
00227 #endif
00228
00229 #endif
00230
00231