// GZRset.cpp: implementation of the GZRset class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "sp.h" #include "GZRset.h" #include #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// GZRset::GZRset(CString strErr) { #ifdef _RSTRACE_ log=new CLogTrace(); log->SetFileName("dblog.txt"); log->m_strAppName="AyaNova"; log->OnStartup(true,true); //log->WriteLine(">>>>Opening: %s\r\n",strErr); #endif m_bUseTransactions=false; m_bInUse=true; m_bPrinting=false; m_bRSPRINT=false; CString copyright="AyaNova Classic Edition Copyright 2000-2004 Ground Zero Tech-Works"; _ASSERT(!strErr.IsEmpty()); //set error message so that if various _ASSERTions fail //the user can be alerted with something meaningful to write //down and in turn tell us during a tech support call. //because this class will be used all over the place m_strErrMsg=strErr; m_bForwardOnly=false; //by default not an exclusive connection m_bExclusiveConnection=false; //set to null as a default m_pRecordSet=NULL; try{ // instantiate the recordset defined in the header m_pRecordSet.CreateInstance(__uuidof(Recordset)); //m_pRecordSet->PutCacheSize(500); m_pRecordSet->CursorLocation=adUseServer; m_bOpen = false;// signify no recordset m_strLastError.Empty(); } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); m_strLastError.Format("%s",(LPCTSTR) bstrDescription); if(m_pRecordSet==NULL) { AfxMessageBox( "Problem: It appears that you do not have the required \r\n" "Microsoft Data Access Components installed.\r\n\r\n" "They should have been installed automatically with AyaNova\r\n" "but are not present. Please contact tech support at:\r\n" "support@ayanova.com or ... \r\n\r\n" "The following page on our website gives instructions on installing\r\n" "the missing database driver files:\r\n" "http://www.ayanova.com/mdac.htm"); if(AfxMessageBox("Do you want to be taken to this page on our website now?\r\n(requires internet ability)",MB_YESNO)==IDYES) HINSTANCE h = ShellExecute(NULL, "open", "http://www.ayanova.com/mdac.htm", NULL, NULL, SW_SHOWNORMAL); } else AfxMessageBox(cstrErrMsg); PostQuitMessage(-1);//exit now before anything worse happens } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens } } GZRset::GZRset(CString strErr, bool bUseClientCursor) { m_bUseTransactions=false; #ifdef _RSTRACE_ log=new CLogTrace(); log->SetFileName("dblog.txt"); log->m_strAppName="AyaNova"; log->OnStartup(true,true); //log->WriteLine(">>>>Opening: %s\r\n",strErr); #endif m_bInUse=true; #ifdef _WTF_ //AfxMessageBox(strErr); #endif _ASSERT(!strErr.IsEmpty()); //set error message so that if various _ASSERTions fail //the user can be alerted with something meaningful to write //down and in turn tell us during a tech support call. //because this class will be used all over the place m_strErrMsg=strErr; // instantiate the recordset defined in the header m_pRecordSet.CreateInstance(__uuidof(Recordset)); //changed this July 1st for performance, //not sure why it was client before if(bUseClientCursor) m_pRecordSet->CursorLocation=adUseClient; else m_pRecordSet->CursorLocation=adUseServer; m_bOpen = false;// signify no recordset m_strLastError.Empty(); } GZRset::~GZRset() { #ifdef _RSTRACE_ //log->WriteLine("CLOSING: %s<<<<*\r\n",m_strErrMsg); delete log; #endif if(m_pRecordSet->GetState()==adStateOpen) m_pRecordSet->Close(); //releases on it's own despite this and causes error //lesson: don't release unless you call addref first //m_pRecordSet->Release(); } _RecordsetPtr GZRset::RecordSetPointer() { return m_pRecordSet; } /* bool GZRset::Open() { AfxMessageBox("OBSOLETE:\r\nbool GZRset::Open()"); //for confirming if recordset is open or not. return m_bOpen; } */ /* //Open forward only bool GZRset::OpenForwardOnly(CString strQuery) { AfxMessageBox("OBSOLETE:\r\nbool GZRset::OpenForwardOnly(CString strQuery)"); m_bForwardOnly=true; _ASSERT(!strQuery.IsEmpty()); _ASSERT(!m_strConnect.IsEmpty()); try { //if the recordset is already open, close it first. //because open is also requery if(m_bOpen) { m_pRecordSet->Close(); m_bOpen=false; } //no records at this point m_bNoRecords=true; //convert query to a variant _variant_t vQuery(strQuery); //convert connection string to a binary string _bstr_t bstrConn(m_strConnect); //open the forward only recordset based on the passed query m_pRecordSet->Open(vQuery, bstrConn, adOpenForwardOnly, adLockOptimistic, adCmdUnknown); //check for empty recordset if (m_pRecordSet->GetadoEOF()) m_bNoRecords = true;// no records found else m_bNoRecords = false;//there are records //open must be true or an exception would have happened before now m_bOpen=true; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("at: OLD OpenForwardOnly\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,strQuery); m_strLastError.Format("%s",(LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens } return m_bOpen; } */ //QUERY: replacement for openforwardonly //December 7th 2000 bool GZRset::Query(CString strQuery) { #ifdef _RSTRACE_ //don't log nulltable queries log->WriteLine("Query: %s\r\n",strQuery); #endif m_strLastQuery=strQuery; m_bForwardOnly=true; _ASSERT(!strQuery.IsEmpty()); _ASSERT(!m_strConnect.IsEmpty()); // long cs=m_pRecordSet->GetCacheSize(); try { //if the recordset is already open, close it first. //because open is also requery if(m_bOpen && m_bExclusiveConnection==false) { //sometimes, the recordset is actually //closed even though we don't know it //this is a 3am "I don't ***** understand why, but this fixes it" Hack if(m_pRecordSet->GetState()==adStateOpen) m_pRecordSet->Close(); m_pRecordSet->CursorLocation=adUseServer; if(m_bRSPRINT) m_pRecordSet->CursorLocation=adUseClient; m_bOpen=false; } /*EXCLUSIVE should mean this is no longer necessary //exclusivity is set in the pool now by GoExclusive() if(m_bIsClosed)//was it closed { m_strConnect=m_strLiveConnectString; if(m_bExclusiveConnection) m_strConnect=m_strLiveConnectStringExclusive; m_bIsClosed=false; } */ //no records at this point m_bNoRecords=true; //convert query to a variant _variant_t vQuery(strQuery); //convert connection string to a binary string _bstr_t bstrConn(m_strConnect); //open the forward only recordset based on the passed query //m_pRecordSet->Open(vQuery, bstrConn, adOpenForwardOnly, adLockOptimistic, adCmdUnknown); m_pRecordSet->Open(vQuery, _variant_t((IDispatch *)pTheConnection,true), adOpenForwardOnly, adLockOptimistic, adCmdUnknown); //check for empty recordset m_bNoRecords = false;//there are records if (m_pRecordSet->GetadoEOF()) m_bNoRecords = true;// no records found //open must be true or an exception would have happened before now m_bOpen=true; //Added just now while swilling wine and //eating pizza m_bInUse=true; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,strQuery); m_strLastError.Format("%s",(LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens } return m_bOpen; } //QUERY: replacement for openforwardonly //December 7th 2000 bool GZRset::QueryReadOnly(CString strQuery) { #ifdef _RSTRACE_ //don't log nulltable queries log->WriteLine("Query: %s\r\n",strQuery); #endif m_strLastQuery=strQuery; m_bForwardOnly=true; _ASSERT(!strQuery.IsEmpty()); _ASSERT(!m_strConnect.IsEmpty()); //long cs=m_pRecordSet->GetCacheSize(); try { //if the recordset is already open, close it first. //because open is also requery if(m_bOpen) { //sometimes, the recordset is actually //closed even though we don't know it //this is a 3am - "I don't understand //why, but this fixes it" Hack if(m_pRecordSet->GetState()==adStateOpen) m_pRecordSet->Close(); m_pRecordSet->CursorLocation=adUseServer; if(m_bRSPRINT) m_pRecordSet->CursorLocation=adUseClient; m_bOpen=false; } /*//SET IN rspool go exclusive function now if(m_bIsClosed)//was it closed { m_strConnect=m_strLiveConnectString; if(m_bExclusiveConnection) m_strConnect=m_strLiveConnectStringExclusive; m_bIsClosed=false; } */ //no records at this point m_bNoRecords=true; //convert query to a variant _variant_t vQuery(strQuery); //convert connection string to a binary string _bstr_t bstrConn(m_strConnect); //open the forward only recordset based on the passed query //THIS IS THE ONLY DIFFERENCE IN A READ ONLY RECORDSET //m_pRecordSet->Open(vQuery, bstrConn, adOpenForwardOnly, adLockReadOnly, adCmdUnknown); //TEST TEST TEST TEST adLockReadOnly adLockOptimistic adCmdUnknown adCmdText m_pRecordSet->Open(vQuery, _variant_t((IDispatch *)pTheConnection,true), adOpenForwardOnly,adLockReadOnly , adCmdText ); //check for empty recordset m_bNoRecords = false;//there are records if (m_pRecordSet->GetadoEOF()) m_bNoRecords = true;// no records found //open must be true or an exception would have happened before now m_bOpen=true; //Added just now while swilling wine and //eating pizza m_bInUse=true; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,strQuery); m_strLastError.Format("%s",(LPCTSTR) bstrDescription); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens } return m_bOpen; } /* //Open dynaset bool GZRset::Open(CString strQuery) { AfxMessageBox("OBSOLETE:\r\nbool GZRset::Open(CString strQuery)"); m_bForwardOnly=false; _ASSERT(!strQuery.IsEmpty()); _ASSERT(!m_strConnect.IsEmpty()); try { //if the recordset is already open, close it first. //because open is also requery if(m_bOpen) { m_pRecordSet->Close(); m_bOpen=false; } if(m_bIsClosed)//was it closed { if(m_bExclusiveConnection) m_strConnect=m_strLiveConnectStringExclusive; else m_strConnect=m_strLiveConnectString; m_bIsClosed=false; } //no records at this point m_bNoRecords=true; //convert query to a variant _variant_t vQuery(strQuery); //convert connection string to a binary string _bstr_t bstrConn(m_strConnect); //open the recordset based on the passed query m_pRecordSet->Open(vQuery, bstrConn, adOpenDynamic, adLockOptimistic, adCmdUnknown); //check for empty recordset if (m_pRecordSet->GetadoEOF()) m_bNoRecords = true;// no records found else m_bNoRecords = false;//there are records //open must be true or an exception would have happened before now //or so the theory goes m_bOpen=true; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens } return m_bOpen; } */ void GZRset::SetConnect(CString str) { _ASSERT(!str.IsEmpty()); //set connection string m_strConnect=str; } //returns lValue records //-1 on error. CAUTION:moves bookmark //Modified to do it manually as the cursor //type in use does not support record count long GZRset::FetchRecordCount() { m_lRecordCount=0; if(MoveFirst()) { do{ m_lRecordCount++; }while(MoveForward()); m_pRecordSet->MoveFirst(); } return m_lRecordCount; } //returns all text type fields in record as one string //ignores non text field types //Added v1.9.4.6 09-May-2005 to fix problem with indexing bool GZRset::FetchAllTextFieldsAsOneString( CString *strValue) { //Since this function appends instead of setting //must ensure passed in string is empty as expected strValue->Empty(); try{ _variant_t vItem; long lFieldCount=m_pRecordSet->GetFields()->Count; for(long x=0;xGetCollect(x); if ( vItem.vt==VT_BSTR) { *strValue+=vItem.bstrVal; *strValue+=" "; } } }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At FetchAllTextFieldsAsOneString:\r\n%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } bool GZRset::FetchAnyFieldAsString(CString fld, CString *strValue) { //takes a field name and sets the passed cstring contents //to that field in the current record try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); if (vItem.vt == VT_NULL) strValue->Empty(); else if(vItem.vt==VT_BOOL) { if(vItem.boolVal==-1) *strValue="1"; else *strValue="0"; } else { vItem.ChangeType(VT_BSTR,NULL); *strValue=vItem.bstrVal; } }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At CString FetchField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } bool GZRset::FetchField(CString fld, CString *strValue) { //takes a field name and sets the passed cstring contents //to that field in the current record try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); //to catch those little !@#$ups! _ASSERT(vItem.vt==VT_BSTR || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) strValue->Empty(); else *strValue=vItem.bstrVal; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At CString FetchField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } bool GZRset::FetchField(CString fld, bool *bValue) { //same as string field but for a bool item instead //_ASSERTs on invalid field name or type try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); //to catch those little !@#$ups! _ASSERT(vItem.vt==VT_BOOL || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) { *bValue=false; return true; } *bValue=(bool)vItem; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); // cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At BOOL FetchField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //************************************************ bool GZRset::FetchField(CString fld, long *lValue) { //same as string field but for a long variable instead //_ASSERTs on invalid field name or type //same as string field but for a bool item instead //_ASSERTs on invalid field name or type try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); //to catch those little !@#$ups! _ASSERT(vItem.vt==VT_I4 || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) { *lValue=0; return true; } *lValue=vItem.lVal; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At LONG FetchField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //************************************************ bool GZRset::FetchField(CString fld, float *fValue) { //same as string field but for a long variable instead //_ASSERTs on invalid field name or type //same as string field but for a bool item instead //_ASSERTs on invalid field name or type try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); //to catch those little !@#$ups! _ASSERT(vItem.vt==VT_R4 || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) { *fValue=0; return true; } *fValue=vItem.fltVal; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At Float FetchField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //******************************************** bool GZRset::IsEmpty() { return m_bNoRecords; } bool GZRset::MoveFirst() { //ASSERT(m_bForwardOnly==false); if(m_bNoRecords==true || m_bOpen==false) return false; HRESULT hr; hr=m_pRecordSet->MoveFirst(); if(FAILED(hr)) return false; return true; } bool GZRset::MoveLast() { if(m_bNoRecords==true || m_bOpen==false) return false; HRESULT hr; hr=m_pRecordSet->MoveLast(); if(FAILED(hr)) return false; return true; } bool GZRset::MoveForward() { if(m_bNoRecords==true || m_bOpen==false) return false; HRESULT hr; try{ hr=m_pRecordSet->MoveNext(); if(FAILED(hr)) return false; if(m_pRecordSet->GetadoEOF()) return false; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("At MoveForward:\r\n%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } bool GZRset::MoveBack() { ASSERT(m_bForwardOnly==false); if(m_bNoRecords==true || m_bOpen==false) return false; HRESULT hr; hr=m_pRecordSet->MovePrevious(); if(FAILED(hr)) return false; if(m_pRecordSet->GetBOF()) return false; return true; } //DATE AND TIME VERSION - Boo-ya! bool GZRset::FetchField(CString fld, COleDateTime *dtValue) { //Fetch a date time field //_ASSERTs on invalid field name or type //same as string field but for a bool item instead //_ASSERTs on invalid field name or type try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); //to catch those little !@#$ups! _ASSERT(vItem.vt==VT_DATE || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) { return false; } *dtValue=vItem.date; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At DT fetchfield:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //CURRENCY VERSION - Boo-ya! bool GZRset::FetchField(CString fld, COleCurrency *crValue) { //Fetch a date time field //_ASSERTs on invalid field name or type //same as string field but for a bool item instead //_ASSERTs on invalid field name or type try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); //to catch those little !@#$ups! _ASSERT(vItem.vt==VT_CY || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) { return false; } *crValue=vItem.cyVal; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At $$ fetchfield:\r\n%s: %s,\r\n%s\r\nField:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //************************************************ //Fetch unsigned char 0-255 BYTE value in database bool GZRset::FetchField(CString fld, unsigned char *byteValue) { try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); //to catch those little !@#$ups! //_ASSERT(vItem.vt==VT_UI1 || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) { *byteValue=0; return true; } *byteValue=vItem.bVal; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At BYTE FetchField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); //Added 08/03/2001 to hide errors on update if(!m_bSupressErrors) AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //***************************************************8 //byte value 0-255 bool GZRset::UpdateField(CString fld, unsigned char* byteValue) { try { _variant_t vItem(*byteValue); _bstr_t bsfld(fld); m_pRecordSet->Fields->GetItem(bsfld)->Value=vItem; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At BYTE UpdateField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //***************************************************8 bool GZRset::UpdateField(CString fld, long* lValue) { try { _variant_t vItem(*lValue); _bstr_t bsfld(fld); m_pRecordSet->Fields->GetItem(bsfld)->Value=vItem; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At LONG UpdateField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //***************************************************8 //FLOAT or SINGLE type bool GZRset::UpdateField(CString fld, float* fValue) { try { _variant_t vItem(*fValue); _bstr_t bsfld(fld); m_pRecordSet->Fields->GetItem(bsfld)->Value=vItem; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At float updatefield:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //********************************************************* bool GZRset::UpdateField(CString fld, bool* bValue) { try { _variant_t vItem(*bValue); _bstr_t bsfld(fld); m_pRecordSet->Fields->GetItem(bsfld)->Value=vItem; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At bool updatefield:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } bool GZRset::UpdateField(CString fld, CString *strValue) { try { _variant_t vItem(*strValue); if(strValue->IsEmpty()) vItem.vt=VT_NULL; _bstr_t bsfld(fld); m_pRecordSet->Fields->GetItem(bsfld)->Value=vItem; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); // cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At CString UpdateField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //******************************************************** bool GZRset::UpdateField(CString fld, COleDateTime *dtValue) { try { _variant_t vItem(*dtValue); _bstr_t bsfld(fld); m_pRecordSet->Fields->GetItem(bsfld)->Value=vItem; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At DT UpdateField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //CURRENCY: //******************************************************** bool GZRset::UpdateField(CString fld, COleCurrency *crValue) { try { _variant_t vItem(*crValue); _bstr_t bsfld(fld); m_pRecordSet->Fields->GetItem(bsfld)->Value=vItem; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At $$ UpdateField:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //*********************************************************** bool GZRset::AddNewRecord() { try{m_pRecordSet->AddNew(vtMissing, vtMissing);} catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } bool GZRset::SaveRecord() { try{ m_pRecordSet->Update(); } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //New close routine, no more stupid extra database calls //booya! //This function is really a refresh method //used to ensure that data is completely updated //before another query that requires it immediately following bool GZRset::Close() { ASSERT(!m_bSQLServer); try{ //changed may 21 2001 moved inside of check //IJetEnginePtr jet(__uuidof(JetEngine)); //jet->RefreshCache(pTheConnection); if(m_pRecordSet->GetState()==adStateOpen) { if(!m_bSQLServer) { IJetEnginePtr jet(__uuidof(JetEngine)); jet->RefreshCache(pTheConnection); } m_pRecordSet->Close(); } m_bOpen=false; m_bIsClosed=true; m_bInUse=false; } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return true; } //returns last error message //added 9/25/00 //returns last exception error message CString GZRset::GetLastError() { return m_strLastError; } //valid recordset? bool GZRset::Valid() { if(m_pRecordSet==NULL) return false; else return true; } //used to set a definable error message //that will be displayed on any kind //of recordset error when thrown //this is set by each calling function //so that the area where the error is occuring //can be easily determined void GZRset::SetErrorMsg(CString strError) { m_strErrMsg=strError; } void GZRset::Initialize(CString strError) { if(m_bInUse) { CString XX; XX.Format("Error:Recordset\r\n %s\r\nIs trying to be taken over by\r\n" "Recordset\r\n %s\r\nWhile still in use.",m_strErrMsg,strError); AfxMessageBox(XX); return; } else m_bInUse=true; m_strErrMsg=strError; } //Execute an SQL statement independant of recordset //supersedes Execute (dec 7 2000) bool GZRset::Ex(CString strQuery) { //TRACE(strQuery); //#ifdef _DEBUG // CString q; // q.Format("Transactions are:%s\r\n%s",m_bUseTransactions?"ON":"OFF",strQuery); // AfxMessageBox(q); //#endif bool status=true; //this function takes a sql statement and runs and execute //query using a connection object. It returns true if successful //False if not if(m_bExclusiveConnection) m_strConnect=m_strLiveConnectStringExclusive; else m_strConnect=m_strLiveConnectString; try { //convert the string to a bstr _bstr_t strSQL(strQuery); /* if(m_bUseTransactions) pTheConnection->BeginTrans(); //convert the string to a bstr _bstr_t strSQL(strQuery); pTheConnection->Execute(strSQL, NULL, adExecuteNoRecords); if(m_bUseTransactions) pTheConnection->CommitTrans(); */ if(m_bUseTransactions) pTheConnection->BeginTrans(); pTheConnection->Execute(strSQL, NULL, adExecuteNoRecords); if(m_bUseTransactions) pTheConnection->CommitTrans(); } catch (_com_error &e) { if(m_bUseTransactions) pTheConnection->RollbackTrans(); CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("at EX standard:\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,strQuery); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return status; } //Execute and set Identity return //New version 12/7/2000 bool GZRset::Ex(CString strQuery, long* lIdentity) { bool status=true; _variant_t vQuery; m_bForwardOnly=true; //#ifdef _DEBUG // CString q; // q.Format("Transactions are:%s\r\n%s",m_bUseTransactions?"ON":"OFF",strQuery); // AfxMessageBox(q); //#endif try { //if the recordset is already open, close it first. //because open is also requery if(m_bOpen) { m_pRecordSet->Close(); m_bOpen=false; } if(m_bExclusiveConnection) m_strConnect=m_strLiveConnectStringExclusive; else m_strConnect=m_strLiveConnectString; //RUN THE EXECUTE QUERY PART //convert the string to a bstr _bstr_t strSQL(strQuery); //new method using already open connection if(m_bUseTransactions) pTheConnection->BeginTrans(); pTheConnection->Execute(strSQL, NULL, adExecuteNoRecords); if(m_bUseTransactions) pTheConnection->CommitTrans(); //GET THE IDENTITY PART vQuery="SELECT @@Identity;"; m_pRecordSet->Open(vQuery, _variant_t((IDispatch *)pTheConnection,true), adOpenForwardOnly, adLockOptimistic, adCmdUnknown); //open must be true or an exception would have happened before now m_bOpen=true; _variant_t vItem; vItem = m_pRecordSet->Fields->GetItem( _variant_t( 0L ) )->Value; //to catch those little !@#$ups! _ASSERT(vItem.vt==VT_I4 || vItem.vt==VT_NULL); // clean out nasty nulls if (vItem.vt == VT_NULL) { AfxMessageBox("Error at: GZRset::Execute Identity = NULL"); *lIdentity=0; return false; } *lIdentity=vItem.lVal; } catch (_com_error &e) { if(m_bUseTransactions) pTheConnection->RollbackTrans(); CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("at EX(identity)\r\n%s: %s,\r\n%s\r\nQuery:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,strQuery); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return false; } return status; } //Added Dec 8th 2000 with new pooling class //this is required as it's no longer kosher //to set this in the constructor bool GZRset::SetToPrint(bool bPrinting) { if(bPrinting) { m_pRecordSet->CursorLocation=adUseClient; m_bPrinting=true; } else { m_pRecordSet->CursorLocation=adUseServer; m_bPrinting=false; } return true; } CString GZRset::GetRSInfo() { CString strTemp; strTemp.Format("RS#%i\r\nErr String ID:%s",m_nID,m_strErrMsg); return strTemp; } //used to set the error message/id string of a recordset //when it's re-used. void GZRset::SetErrMsg(CString strErrorID) { m_strErrMsg=strErrorID; } //required because query based recordsets don't //come across as memos and so crystal thinks //they are regular text 255 char size only //and truncates CString GZRset::SetFieldToMemo(CString fld) { int x; long lActualSize; long lDefinedSize; int nMySize; CString strData; _variant_t vItem; _variant_t vData; _variant_t vFld(fld); long lCount=m_pRecordSet->Fields->GetCount(); for(long lx=0;lxFields->GetItem(lx)->Type; vItem=m_pRecordSet->Fields->GetItem(lx)->Name; x = m_pRecordSet->Fields->GetItem(lx)->Type; lActualSize=m_pRecordSet->Fields->GetItem(lx)->GetActualSize(); lDefinedSize=m_pRecordSet->Fields->GetItem(lx)->GetDefinedSize(); vData=m_pRecordSet->Fields->GetItem(lx)->GetUnderlyingValue(); if(vItem==vFld) { strData=vData.bstrVal; nMySize=strData.GetLength(); break; } } return strData; } //given a field name return an int that indicates what //type it is int GZRset::FetchFieldType(CString fld) { //-1=unknown,0=text,1=long int,2=datetime,3=currency,4=float,5=bool; int nType=-1; //_ASSERTs on invalid field name try{ _variant_t vItem; _bstr_t bsfld(fld); vItem = m_pRecordSet->GetCollect(bsfld); switch(vItem.vt) { case (VT_BOOL): nType=5; break; case (VT_BSTR): nType=0; break; case (VT_I4): nType=1; break; case (VT_CY): nType=3; break; case (VT_DATE): nType=2; break; case (VT_R4): nType=4; break; default: nType=-1; break; } return nType; }//end try block catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); // cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); cstrErrMsg.Format("At FetchFieldType:\r\n%s: %s,\r\n%s\r\nField:%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription,fld); AfxMessageBox(cstrErrMsg); return -1; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox(m_strErrMsg); PostQuitMessage(-1);//exit now before anything worse happens return -1; } return true; } //*******************USEFUL INFORMATION ******************* /* //test of createable recordset and saving to disk bool CAyabaseDlg::test() { GZRset rs("test in memory",true); _bstr_t bsName("TEST"); _variant_t vt(_bstr_t("c:\\temp\\test.xml")); _variant_t vtTEST(_bstr_t("mangoes, mangoes everywhere!")); COleDateTime dtNow=COleDateTime::GetCurrentTime(); _variant_t vtDate(dtNow); try{ _RecordsetPtr pRS; pRS.CreateInstance( __uuidof(Recordset)); pRS->CursorLocation = adUseClient; pRS->CursorType = adOpenStatic; pRS->LockType = adLockBatchOptimistic; // append fields pRS->Fields->Append(_bstr_t("charfield"), adVarChar, 99,adFldFixed); pRS->Fields->Append(_bstr_t("boolfield"), adBoolean, 0,adFldFixed); pRS->Fields->Append(_bstr_t("currencyfield"), adCurrency, 0,adFldFixed); pRS->Fields->Append(_bstr_t("datefield"), adDate, 0,adFldFixed); pRS->Open(vtMissing, vtMissing, adOpenStatic,adLockBatchOptimistic,-1); pRS->AddNew(vtMissing, vtMissing); pRS->Fields->Item["charfield"]->Value = vtTEST; pRS->Fields->Item["datefield"]->Value = vtDate; pRS->Update(); pRS->Save(vt,adPersistXML); //rs.RecordSetPointer()->Fields->Append(bsName,adVarChar,25,adFldUnspecified,vt); } catch (_com_error &e) { CString cstrErrMsg; // get info from com error _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); TRACE("*************************************************\n"); TRACE("Exception thrown for classes generated by #import\n"); TRACE("\tCode = %081x\n", e.Error); TRACE("\tCode Meaning = %s\n", e.ErrorMessage()); TRACE("\tSource = %s\n", (LPCTSTR) bstrSource); TRACE("Description = %s\n", (LPCTSTR) bstrDescription); TRACE("*************************************************\n"); cstrErrMsg.Format("at in created rset\r\n: %s,\r\n%s\r\n", e.ErrorMessage(), (LPCTSTR) bstrDescription); //cstrErrMsg.Format("%s: %s,\r\n%s",m_strErrMsg, e.ErrorMessage(), (LPCTSTR) bstrDescription); AfxMessageBox(cstrErrMsg); return false; } catch (...) { TRACE("*** Unhandled exception ***"); AfxMessageBox("Created rset - unhandled exception"); //PostQuitMessage(-1);//exit now before anything worse happens return false; } //rs.RecordSetPointer()->Fields->"TEST",adVarChar,20 return true; } */ //*************************************************************************