--- sql/odbc/parser3odbc.C 2002/05/15 10:21:46 1.8 +++ sql/odbc/parser3odbc.C 2002/12/09 12:33:28 1.12 @@ -5,7 +5,7 @@ Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char *RCSId="$Id: parser3odbc.C,v 1.8 2002/05/15 10:21:46 paf Exp $"; +static const char *RCSId="$Id: parser3odbc.C,v 1.12 2002/12/09 12:33:28 paf Exp $"; #ifndef _MSC_VER # error compile ISAPI module with MSVC [no urge for now to make it autoconf-ed (PAF)] @@ -20,10 +20,14 @@ static const char *RCSId="$Id: parser3od #include +// defines + +#define MAX_COLS 500 + #define MAX_STRING 0x400 #define MAX_NUMBER 40 -// MSSQL2000 +// new in MSSQL2000, no MFC constants #ifndef SQL_NVARCHAR #define SQL_NVARCHAR (-9) #endif @@ -161,60 +165,78 @@ public: || strncasecmp(statement, "call", 4)==0 || strncasecmp(statement, "{", 1)==0) { CRecordset rs(db); - rs.Open( - CRecordset::forwardOnly, - statement, - CRecordset::executeDirect - ); + TRY { + rs.Open( + CRecordset::forwardOnly, + statement, + CRecordset::executeDirect + ); + } CATCH_ALL (e) { + // could not fetch a table + TRY { + // then try resultless query + db->ExecuteSQL(statement); + // OK then + return; + } CATCH_ALL (e2) { + // still nothing good + _throw(services, e); // throw ORIGINAL exception + } END_CATCH_ALL + } END_CATCH_ALL int column_count=rs.GetODBCFieldCount(); if(!column_count) services._throw("result contains no columns"); + SWORD column_types[MAX_COLS]; + if(column_count>MAX_COLS) + column_count=MAX_COLS; + + SQL_Error sql_error; +#define CHECK(afailed) if(afailed) services._throw(sql_error) + for(int i=0; i=offset) { - handlers.add_row(); - for(int i=0; iExecuteSQL(statement); } - } - CATCH_ALL (e) { + } CATCH_ALL (e) { _throw(services, e); - } - END_CATCH_ALL + } END_CATCH_ALL } void getFromDBVariant(SQL_Driver_services& services, CDBVariant& v, void *& ptr, size_t& size) { @@ -260,8 +280,17 @@ public: m_fltVal break; case DBVT_DOUBLE m_dblVal - case DBVT_STRING m_pstring - case DBVT_BINARY m_pbinary */ + case DBVT_STRING m_pstring */ + case DBVT_BINARY: + { + if(size=v.m_pbinary->m_dwDataLength) { + ptr=services.malloc(size); + memcpy(ptr, ::GlobalLock(v.m_pbinary->m_hData), size); + ::GlobalUnlock(v.m_pbinary->m_hData); + } else + ptr=0; + break; + } case DBVT_DATE: { char local_buf[MAX_STRING];