DataTable.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // DataTable.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AccessToSqlite.h"
  5. #include "DataTable.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #pragma warning(disable : 4995)
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDataTable
  14. IMPLEMENT_DYNAMIC(CDataTable, CDaoRecordset)
  15. CDataTable::CDataTable(CDaoDatabase* pdb)
  16. :CDaoRecordset(pdb)
  17. {
  18. //{{AFX_FIELD_INIT(CDataTable)
  19. m_lID = 0;
  20. m_lDataID = 0;
  21. m_strClipBoardFormat = _T("");
  22. m_nFields = 4;
  23. //}}AFX_FIELD_INIT
  24. m_nDefaultType = dbOpenDynaset;
  25. }
  26. CString CDataTable::GetDefaultSQL()
  27. {
  28. return _T("[Data]");
  29. }
  30. void CDataTable::DoFieldExchange(CDaoFieldExchange* pFX)
  31. {
  32. //{{AFX_FIELD_MAP(CDataTable)
  33. pFX->SetFieldType(CDaoFieldExchange::outputColumn);
  34. DFX_Long(pFX, _T("[lID]"), m_lID);
  35. DFX_Long(pFX, _T("[lDataID]"), m_lDataID);
  36. DFX_Text(pFX, _T("[strClipBoardFormat]"), m_strClipBoardFormat);
  37. DFX_LongBinary(pFX, _T("[ooData]"), m_ooData);
  38. //}}AFX_FIELD_MAP
  39. }
  40. // caller must free
  41. // takes m_ooData's HGLOBAL (do not update recset after calling this)
  42. // This should be faster than making a copy, but is this SAFE ??
  43. HGLOBAL CDataTable::TakeData()
  44. {
  45. // if there is nothing to take
  46. if( m_ooData.m_hData == 0 || m_ooData.m_dwDataLength == 0 )
  47. return 0;
  48. // Unlock the handle that was locked by DaoLongBinaryAllocCallback()
  49. // (through DFX_LongBinary()).
  50. ::GlobalUnlock( m_ooData.m_hData );
  51. // we have to do a realloc in order to make the hGlobal m_dwDataLength
  52. HGLOBAL hGlobal = ::GlobalReAlloc(m_ooData.m_hData, m_ooData.m_dwDataLength, GMEM_MOVEABLE );
  53. if( !hGlobal || ::GlobalSize(hGlobal) == 0 )
  54. {
  55. //::_RPT0( _CRT_WARN, GetErrorString(::GetLastError()) );
  56. ASSERT(FALSE);
  57. }
  58. // no longer valid
  59. m_ooData.m_hData = 0;
  60. m_ooData.m_dwDataLength = 0;
  61. return hGlobal;
  62. }
  63. // allocates a new copy of the data
  64. HGLOBAL CDataTable::LoadData()
  65. {
  66. HGLOBAL hGlobal;
  67. ULONG ulBufLen = m_ooData.m_dwDataLength; //Retrieve size of array
  68. if( ulBufLen == 0 || m_ooData.m_hData == 0 )
  69. return 0;
  70. hGlobal = NewGlobalH( m_ooData.m_hData, ulBufLen );
  71. return hGlobal;
  72. }
  73. void CDataTable::Open(LPCTSTR lpszFormat,...)
  74. {
  75. CString csText;
  76. va_list vlist;
  77. ASSERT(AfxIsValidString(lpszFormat));
  78. va_start(vlist,lpszFormat);
  79. csText.FormatV(lpszFormat,vlist);
  80. va_end(vlist);
  81. CDaoRecordset::Open(AFX_DAO_USE_DEFAULT_TYPE, csText, 0);
  82. }