DatabaseUtilities.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. class CDaoTableDefEx : public CDaoTableDef
  11. {
  12. public:
  13. CDaoTableDefEx(CDaoDatabase* pDatabase)
  14. :CDaoTableDef(pDatabase)
  15. {
  16. }
  17. BOOL CreateIndex(BOOL bPrimaryKey, CString csField)
  18. {
  19. try
  20. {
  21. CDaoIndexInfo IndexInfo;
  22. CDaoIndexFieldInfo IndexFieldInfo[1];
  23. IndexFieldInfo[0].m_strName = csField;
  24. IndexFieldInfo[0].m_bDescending = TRUE;
  25. IndexInfo.m_strName = csField;
  26. IndexInfo.m_pFieldInfos = IndexFieldInfo;
  27. IndexInfo.m_nFields = 1;
  28. IndexInfo.m_bPrimary = bPrimaryKey;
  29. IndexInfo.m_bUnique = FALSE;
  30. IndexInfo.m_bIgnoreNulls = FALSE;
  31. IndexInfo.m_bRequired = FALSE;
  32. CDaoTableDef::CreateIndex( IndexInfo );
  33. }
  34. catch(CDaoException *e)
  35. {
  36. ASSERT(FALSE);
  37. e->Delete();
  38. return FALSE;
  39. }
  40. return TRUE;
  41. }
  42. BOOL CreateField(LPCTSTR lpszName, short nType, long lSize, long lAttributes = 0, CString csDefault = "")
  43. {
  44. try
  45. {
  46. CDaoFieldInfo fieldinfo;
  47. // Initialize everything so only correct properties will be set
  48. fieldinfo.m_strName = lpszName;
  49. fieldinfo.m_nType = nType;
  50. fieldinfo.m_lSize = lSize;
  51. fieldinfo.m_lAttributes = lAttributes;
  52. fieldinfo.m_nOrdinalPosition = 0;
  53. fieldinfo.m_bRequired = FALSE;
  54. fieldinfo.m_bAllowZeroLength = FALSE;
  55. fieldinfo.m_lCollatingOrder = 0;
  56. fieldinfo.m_strDefaultValue = csDefault;
  57. CDaoTableDef::CreateField(fieldinfo);
  58. return TRUE;
  59. }
  60. catch(CDaoException *e)
  61. {
  62. e->Delete();
  63. ASSERT(FALSE);
  64. }
  65. return FALSE;
  66. }
  67. };
  68. CString GetDBName();
  69. BOOL CompactDatabase();
  70. CString GetDefaultDBName();
  71. BOOL RepairDatabase();
  72. BOOL CheckDBExists(CString csDBPath);
  73. BOOL RemoveOldEntries();
  74. BOOL CreateDB(CString csPath);
  75. BOOL ValidDB(CString csPath);
  76. BOOL EnsureDirectory(CString csPath);
  77. #endif // !defined(AFX_DATABASEUTILITES_H__039F53EB_228F_4640_8009_3D2B1FF435D4__INCLUDED_)