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 #ifndef CPL_ODBC_H_INCLUDED
00077 #define CPL_ODBC_H_INCLUDED
00078
00079 #include "cpl_port.h"
00080
00081 #ifdef WIN32
00082 # include <windows.h>
00083 #endif
00084
00085 #include <sql.h>
00086 #include <sqlext.h>
00087 #include "cpl_string.h"
00088
00095 class CPLODBCStatement;
00096
00097
00098 #ifdef SQLULEN
00099
00100 # define _SQLULEN SQLULEN
00101 # define _SQLLEN SQLLEN
00102 #else
00103 # define _SQLULEN SQLUINTEGER
00104 # define _SQLLEN SQLINTEGER
00105 #endif
00106
00107
00114 class CPL_DLL CPLODBCSession {
00115 char m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
00116 HENV m_hEnv;
00117 HDBC m_hDBC;
00118
00119 public:
00120 CPLODBCSession();
00121 ~CPLODBCSession();
00122
00123 int EstablishSession( const char *pszDSN,
00124 const char *pszUserid,
00125 const char *pszPassword );
00126 const char *GetLastError();
00127
00128
00129
00130 int CloseSession();
00131
00132 int Failed( int, HSTMT = NULL );
00133 HDBC GetConnection() { return m_hDBC; }
00134 HENV GetEnvironment() { return m_hEnv; }
00135 };
00136
00146 class CPL_DLL CPLODBCStatement {
00147
00148 CPLODBCSession *m_poSession;
00149 HSTMT m_hStmt;
00150
00151 short m_nColCount;
00152 char **m_papszColNames;
00153 short *m_panColType;
00154 _SQLULEN *m_panColSize;
00155 short *m_panColPrecision;
00156 short *m_panColNullable;
00157
00158 char **m_papszColValues;
00159 int *m_panColValueLengths;
00160
00161 int Failed( int );
00162
00163 char *m_pszStatement;
00164 int m_nStatementMax;
00165 int m_nStatementLen;
00166
00167 public:
00168 CPLODBCStatement( CPLODBCSession * );
00169 ~CPLODBCStatement();
00170
00171 HSTMT GetStatement() { return m_hStmt; }
00172
00173
00174 void Clear();
00175 void AppendEscaped( const char * );
00176 void Append( const char * );
00177 void Append( int );
00178 void Append( double );
00179 int Appendf( const char *, ... );
00180 const char *GetCommand() { return m_pszStatement; }
00181
00182 int ExecuteSQL( const char * = NULL );
00183
00184
00185 int Fetch( int nOrientation = SQL_FETCH_NEXT,
00186 int nOffset = 0 );
00187 void ClearColumnData();
00188
00189 int GetColCount();
00190 const char *GetColName(int iCol);
00191 short GetColType(int iCol);
00192 short GetColSize(int iCol);
00193 short GetColPrecision(int iCol);
00194 short GetColNullable(int iCol);
00195
00196 int GetColId( const char * );
00197 const char *GetColData( int, const char * = NULL );
00198 const char *GetColData( const char *, const char * = NULL );
00199 int GetColDataLength( int );
00200
00201
00202 int GetColumns( const char *pszTable,
00203 const char *pszCatalog = NULL,
00204 const char *pszSchema = NULL );
00205 int GetPrimaryKeys( const char *pszTable,
00206 const char *pszCatalog = NULL,
00207 const char *pszSchema = NULL );
00208
00209 int GetTables( const char *pszCatalog = NULL,
00210 const char *pszSchema = NULL );
00211
00212 void DumpResult( FILE *fp, int bShowSchema = FALSE );
00213
00214 static CPLString GetTypeName( int );
00215
00216 int CollectResultsInfo();
00217 };
00218
00219 #endif
00220
00221