1
0

Table.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Table Class Prototypes
  8. Apple Mac OS X implementation
  9. --------------------------------------------------------------------------- */
  10. #ifndef __TABLE_H
  11. #define __TABLE_H
  12. #include <stdio.h>
  13. #include "Scanner.h"
  14. #include <map>
  15. #include "IndexRecord.h"
  16. class Table : private Scanner
  17. {
  18. public:
  19. // TODO: move these back to protected
  20. VFILE *Handle;
  21. using Scanner::index;
  22. bool use_row_cache;
  23. BOOL GLocateUpToDate;
  24. private:
  25. void Init();
  26. void Reset();
  27. private:
  28. LinkedList *Scanners;
  29. protected:
  30. char *Name; // TODO: CFStringRef
  31. char *IdxName; // TODO: CFStringRef
  32. VFILE *IdxHandle;
  33. BOOL AutoCreate;
  34. Record *FieldsRecord;
  35. IndexRecord *IndexList;
  36. Database *db;
  37. BOOL Cached;
  38. int numErrors;
  39. using Scanner::Edition;
  40. bool columns_cached;
  41. unsigned char column_ids[256];
  42. typedef std::map<int, Record*> RowCache;
  43. RowCache rowCache;
  44. // Tables
  45. static bool Compact_ColumnWalk(Record *record, Field *entry, void *context_in);
  46. static bool Compact_ColumnWalk2(Record *record, Field *entry, void *context_in);
  47. static bool Compact_IndexWalk(Table *table, IndexField *entry, void *context);
  48. static bool IndexWriteWalker(IndexRecord *record, Field *entry, void *context);
  49. static bool IndexWalkerThunk(IndexRecord *record, Field *entry, void *context);
  50. static bool IndexNewWalker(IndexRecord *record, Field *entry, void *context);
  51. static bool BuildColumnCache(Record *record, Field *entry, void *context);
  52. public:
  53. typedef bool (*IndexWalker)(Table *table, IndexField *entry, void *context);
  54. Table(const char *TableName, const char *IdxName, BOOL Create, Database *db, BOOL Cached);
  55. ~Table();
  56. BOOL Open(void);
  57. void Close(void);
  58. // Columns
  59. ColumnField *NewColumn(unsigned char Id, CFStringRef name, unsigned char type, BOOL indexUniques);
  60. void DeleteColumn(ColumnField *field); // todo
  61. void DeleteColumnByName(const wchar_t *name); // todo
  62. void DeleteColumnById(unsigned char Id); // todo
  63. void PostColumns(void);
  64. NDE_API Record *GetColumns(void);
  65. ColumnField *GetColumnByName(CFStringRef FieldName);
  66. ColumnField *GetColumnById(unsigned char Idx);
  67. unsigned char GetColumnType(unsigned char Id);
  68. // Fields
  69. using Scanner::NewFieldByName;
  70. using Scanner::NewFieldById;
  71. using Scanner::GetFieldByName;
  72. using Scanner::GetFieldById;
  73. using Scanner::DeleteField;
  74. using Scanner::DeleteFieldByName;
  75. using Scanner::DeleteFieldById;
  76. // Records
  77. using Scanner::First;
  78. using Scanner::Last;
  79. using Scanner::Next;
  80. using Scanner::Previous;
  81. using Scanner::Eof;
  82. using Scanner::Bof;
  83. using Scanner::New;
  84. using Scanner::Insert;
  85. using Scanner::Edit;
  86. using Scanner::Cancel;
  87. using Scanner::Post;
  88. using Scanner::Delete;
  89. using Scanner::GetRecordsCount;
  90. using Scanner::GetRecordById;
  91. using Scanner::GetRecordId;
  92. void Sync(void);
  93. using Scanner::LocateByName;
  94. using Scanner::LocateById;
  95. BOOL LocateByIdEx(int Id, int From, Field *field, int comp_mode);
  96. // Indexes
  97. void AddIndexByName(CFStringRef FieldName, CFStringRef KeyName);
  98. void AddIndexById(unsigned char Id, CFStringRef KeyName);
  99. void WalkIndices(IndexWalker callback, void *context);
  100. IndexField *GetIndexByName(CFStringRef name);
  101. IndexField *GetIndexById(unsigned char Id);
  102. using Scanner::SetWorkingIndexByName;
  103. using Scanner::SetWorkingIndexById;
  104. NDE_API BOOL CheckIndexing(void);
  105. void DropIndexByName(CFStringRef desc);
  106. void DropIndexById(unsigned char Id);
  107. void DropIndex(IndexField *Ptr);
  108. void IndexModified(void);
  109. // Filters
  110. using Scanner::AddFilterByName;
  111. using Scanner::AddFilterById;
  112. using Scanner::AddFilterOp;
  113. using Scanner::RemoveFilters;
  114. // Scanners
  115. Scanner *NewScanner();
  116. Scanner *GetDefaultScanner(void);
  117. void DeleteScanner(Scanner *scan);
  118. // Misc
  119. using Scanner::FragmentationLevel;
  120. void Compact(int *progress = NULL);
  121. void SetGlobalLocateUpToDate(BOOL is);
  122. // Row Cache
  123. void RowCache_Delete(int position);
  124. void RowCache_Remove(int position);
  125. void RowCache_Add(Record *record, int position);
  126. Record *RowCache_Get(int position);
  127. NDE_API void EnableRowCache();
  128. // Searching
  129. void SetFieldSearchableById(unsigned char field_id, bool searchable);
  130. int HasErrors()
  131. {
  132. return numErrors > 0;
  133. }
  134. int NumErrors()
  135. {
  136. return numErrors;
  137. }
  138. void IncErrorCount()
  139. {
  140. numErrors++;
  141. }
  142. };
  143. #endif