DatabaseUtilities.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // DatabaseUtilites.h: interface for the CDatabaseUtilites class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_DATABASEUTILITES_H__039F53EB_228F_4640_8009_3D2B1FF435D4__INCLUDED_)
  5. #define AFX_DATABASEUTILITES_H__039F53EB_228F_4640_8009_3D2B1FF435D4__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #define DEFAULT_DB_NAME "DittoDB.mdb"
  10. #define CATCHDAO \
  11. catch(CDaoException* e) \
  12. { \
  13. e->ReportError(); \
  14. ASSERT(0); \
  15. e->Delete(); \
  16. }
  17. class CDaoTableDefEx : public CDaoTableDef
  18. {
  19. public:
  20. CDaoTableDefEx(CDaoDatabase* pDatabase)
  21. :CDaoTableDef(pDatabase)
  22. {
  23. }
  24. BOOL CreateIndex(BOOL bPrimaryKey, CString csField)
  25. {
  26. try
  27. {
  28. CDaoIndexInfo IndexInfo;
  29. CDaoIndexFieldInfo IndexFieldInfo[1];
  30. IndexFieldInfo[0].m_strName = csField;
  31. IndexFieldInfo[0].m_bDescending = TRUE;
  32. IndexInfo.m_strName = csField;
  33. IndexInfo.m_pFieldInfos = IndexFieldInfo;
  34. IndexInfo.m_nFields = 1;
  35. IndexInfo.m_bPrimary = bPrimaryKey;
  36. IndexInfo.m_bUnique = FALSE;
  37. IndexInfo.m_bIgnoreNulls = FALSE;
  38. IndexInfo.m_bRequired = FALSE;
  39. CDaoTableDef::CreateIndex( IndexInfo );
  40. }
  41. catch(CDaoException *e)
  42. {
  43. ASSERT(FALSE);
  44. e->Delete();
  45. return FALSE;
  46. }
  47. return TRUE;
  48. }
  49. BOOL CreateField(LPCTSTR lpszName, short nType, long lSize, long lAttributes = 0, CString csDefault = "")
  50. {
  51. try
  52. {
  53. CDaoFieldInfo fieldinfo;
  54. // Initialize everything so only correct properties will be set
  55. fieldinfo.m_strName = lpszName;
  56. fieldinfo.m_nType = nType;
  57. fieldinfo.m_lSize = lSize;
  58. fieldinfo.m_lAttributes = lAttributes;
  59. fieldinfo.m_nOrdinalPosition = 0;
  60. fieldinfo.m_bRequired = FALSE;
  61. fieldinfo.m_bAllowZeroLength = FALSE;
  62. fieldinfo.m_lCollatingOrder = 0;
  63. fieldinfo.m_strDefaultValue = csDefault;
  64. CDaoTableDef::CreateField(fieldinfo);
  65. return TRUE;
  66. }
  67. catch(CDaoException *e)
  68. {
  69. e->Delete();
  70. ASSERT(FALSE);
  71. }
  72. return FALSE;
  73. }
  74. };
  75. BOOL CreateBackup(CString csPath);
  76. CString GetDBName();
  77. CString GetDefaultDBName();
  78. BOOL CheckDBExists(CString csDBPath);
  79. BOOL ValidDB(CString csPath, BOOL bUpgrade=TRUE);
  80. BOOL CreateDB(CString csPath);
  81. BOOL Upgrade_mText(CDaoDatabase& db);
  82. BOOL Upgrade_Groups(CDaoDatabase& db);
  83. BOOL Upgrade_ShareData(CDaoDatabase& db);
  84. BOOL CompactDatabase();
  85. BOOL RepairDatabase();
  86. BOOL RemoveOldEntries();
  87. BOOL EnsureDirectory(CString csPath);
  88. BOOL ExecuteSQL(CString csSQL, BOOL bReportError = TRUE, CDaoException** ppEx = NULL);
  89. int GetFieldPos(CDaoRecordset& recs, LPCTSTR fieldName);
  90. void VerifyFieldPos(CDaoRecordset& recs, LPCTSTR fieldName, int index);
  91. CString GetFieldList(CDaoRecordset& recs);
  92. #endif // !defined(AFX_DATABASEUTILITES_H__039F53EB_228F_4640_8009_3D2B1FF435D4__INCLUDED_)