ExecuteSQLProc.cpp
Upload User: jsxglz
Upload Date: 2007-01-03
Package Size: 117k
Code Size: 2k
Category:

SQL Server

Development Platform:

Visual C++

  1. // ExecuteSQLProc.cpp: implementation of the CExecuteSQLProc class.
  2. //
  3. #include "stdafx.h"
  4. #include "interactivesql.h"
  5. #include "ExecuteSQLProc.h"
  6. #include "ResultView.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. const char* g_szFunctionSequenceError = "State:S1010";
  13. //////////////////////////////////////////////////////////////////////
  14. // CExecuteSQLProc
  15. CExecuteSQLProc::CExecuteSQLProc()
  16. {
  17. }
  18. CExecuteSQLProc::~CExecuteSQLProc()
  19. {
  20. }
  21. UINT ExecuteSQLProc(LPVOID lpVoid)
  22. {
  23. ThreadParam* pTP = (ThreadParam*)lpVoid;
  24. ASSERT(pTP);
  25. ASSERT(!pTP->m_strSQL.IsEmpty());
  26. CMainFrame* pFrame = pTP->m_pFrame;
  27. ASSERT(pFrame);
  28. ASSERT(pTP->m_pView);
  29. ASSERT(pTP->m_pFrame->m_pSet);
  30. BOOL bCaughtException = FALSE;
  31. try
  32. {
  33. if(pTP->m_pFrame->m_pSet->m_hstmt && pTP->m_pFrame->m_pSet->IsOpen())
  34. pTP->m_pFrame->m_pSet->Close();
  35. pTP->m_pFrame->m_database.SetQueryTimeout(pTP->m_pFrame->m_nQueryTimeOut);
  36. pTP->m_pFrame->m_pSet->ExecDirect(pTP->m_strSQL);
  37. }
  38. catch(CDBException* e)
  39. {
  40. bCaughtException = TRUE;
  41. if(e)
  42. {
  43. CString sMsg;
  44. if(e->m_strStateNativeOrigin.Find(g_szFunctionSequenceError) != -1)
  45. {
  46. pTP->m_pFrame->m_bCanceled = TRUE;
  47. sMsg = "Query canceled by user.";
  48. pTP->m_pFrame->m_strStatusText = "Canceled";
  49. }
  50. else
  51. {
  52. if(!e->m_strError.IsEmpty())
  53. sMsg.Format("%s%s", (LPCTSTR)e->m_strError, (LPCTSTR)e->m_strStateNativeOrigin);
  54. else
  55. sMsg = e->m_strStateNativeOrigin;
  56. pTP->m_pFrame->m_strStatusText.Format("CDBException::m_nRetCode == %d", e->m_nRetCode);
  57. }
  58. pTP->m_pView->SetWindowText(sMsg);
  59. e->Delete();
  60.    }
  61. }
  62. catch(CMemoryException* e)
  63. {
  64. bCaughtException = TRUE;
  65. pTP->m_pFrame->m_strStatusText = "Out-of-memory";
  66. pTP->m_pView->SetWindowText(pTP->m_pFrame->m_strStatusText);
  67. if(e)
  68. e->Delete();
  69. }
  70. if(bCaughtException)
  71. if(pTP->m_pFrame->m_pSet->IsOpen())
  72. pTP->m_pFrame->m_pSet->Close();
  73. ::PostMessage(pTP->m_pFrame->m_hWnd, WM_EXECUTION_COMPLETE, bCaughtException, 0L);
  74. return 0; // Gracefully exit
  75. }