DatabaseUtilities.h 2.8 KB

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