Database.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Database Class
  8. --------------------------------------------------------------------------- */
  9. #include "Database.h"
  10. #include "Table.h"
  11. //---------------------------------------------------------------------------
  12. Database::Database()
  13. {
  14. #ifdef WIN32
  15. hInstance = (HINSTANCE)0;
  16. #endif
  17. }
  18. #ifdef WIN32
  19. //---------------------------------------------------------------------------
  20. Database::Database(HINSTANCE hinst)
  21. {
  22. hInstance = hinst;
  23. }
  24. #endif
  25. //---------------------------------------------------------------------------
  26. Database::~Database()
  27. {
  28. }
  29. #ifdef WIN32
  30. //---------------------------------------------------------------------------
  31. void Database::SetInstance(HINSTANCE inst) {
  32. hInstance = inst;
  33. }
  34. HINSTANCE Database::GetInstance() {
  35. return hInstance;
  36. }
  37. #endif
  38. //--------------------------------------------------------------------------
  39. #ifdef _WIN32
  40. Table *Database::OpenTable(const wchar_t *TableName, const wchar_t *IdxName, BOOL Create, BOOL Cached)
  41. #else
  42. Table *Database::OpenTable(const char *TableName, const char *IdxName, BOOL Create, BOOL Cached)
  43. #endif
  44. //char *tablefn, char*indexfn, BOOL create)
  45. {
  46. Table *table = new Table(TableName, IdxName, Create, this, Cached);
  47. if (table)
  48. {
  49. if (table->Open())
  50. return table;
  51. table->Close();
  52. delete table;
  53. }
  54. return NULL;
  55. }
  56. //---------------------------------------------------------------------------
  57. void Database::CloseTable(Table *table)
  58. {
  59. if (table)
  60. {
  61. table->Close();
  62. delete table;
  63. }
  64. }