Scanner.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Scanner Class Prototypes
  8. Android (linux) implementation
  9. --------------------------------------------------------------------------- */
  10. #ifndef __SCANNER_H
  11. #define __SCANNER_H
  12. #include "../nde.h"
  13. #include "record.h"
  14. #include "../index.h"
  15. #include <nu/Vector.h>
  16. #include <nu/ValueSet.h>
  17. #include "../LinkedList.h"
  18. class Table;
  19. class Index;
  20. class Scanner : public LinkedListEntry
  21. {
  22. public:
  23. Record *GetRecord(int Idx);
  24. Scanner(Table *parentTable);
  25. void IndexModified(void);
  26. Index *GetIndex() { return index; }
  27. Index *index; // TODO: make protected
  28. protected:
  29. ~Scanner();
  30. Table *pTable;
  31. bool iModified;
  32. typedef Vector<StringField *> SearchStrings;
  33. SearchStrings search_strings;
  34. typedef ValueSet<unsigned char> SearchFields;
  35. SearchFields search_fields;
  36. bool search_any;
  37. void GetCurrentRecord(void);
  38. bool MatchFilters(void);
  39. bool MatchSearches();
  40. bool MatchSearch(const SearchFields &fields, StringField *search_field);
  41. //BOOL MatchJoins(void);
  42. bool CheckFilters(void);
  43. void CacheLastLocate(int Id, int From, Field *field, Index *i, int j);
  44. static int Query_LookupToken(const char *token);
  45. void Query_CleanUp(void);
  46. void Query_SyntaxError(int c);
  47. public:
  48. static int Query_GetNextToken(const char *p, int *size, char **token, int tokentable=0);
  49. static const char *Query_EatSpace(const char *p);
  50. static char *Query_ProbeSpace(char *p);
  51. static const char *Query_ProbeNonAlphaNum(const char *p);
  52. static char *Query_ProbeAlphaNum(char *p);
  53. static int Query_isControlChar(char p);
  54. bool Query(const char *query);
  55. bool Query_Parse(const char *query);
  56. const char *GetLastQuery();
  57. public://fucko: protected
  58. LinkedList pstack;
  59. char *token;
  60. char *last_query;
  61. int last_query_failed;
  62. protected:
  63. Record *CurrentRecord;
  64. int CurrentRecordIdx;
  65. LinkedList FilterList;
  66. Index *lastLocateIndex;
  67. int lastLocateIdx;
  68. Field *lastLocateFieldClone;
  69. int lastLocateFrom;
  70. int lastLocateId;
  71. bool Edition;
  72. int ResultPtr;
  73. bool FiltersOK;
  74. public:
  75. bool MatchFilter(Filter *filter);
  76. typedef bool (*FilterWalker)(Scanner *scanner, Filter *filter, void *context);
  77. void WalkFilters(FilterWalker walker, void *context);
  78. ColumnField *GetColumnByName(const char *FieldName);
  79. ColumnField *GetColumnById(unsigned char id);
  80. Field *NewFieldByName(const char *fieldName, unsigned char Perm);
  81. Field *NewFieldById(unsigned char Id, unsigned char Perm);
  82. void DeleteField(Field *field);
  83. void DeleteFieldByName(const char *name);
  84. void DeleteFieldById(unsigned char Id);
  85. void Cancel(void);
  86. void Insert(void);
  87. void Edit(void);
  88. void Post(void);
  89. void Delete(void);
  90. Field *GetFieldByName(const char *FieldName);
  91. Field *GetFieldById(unsigned char Id);
  92. void First(int *killswitch=0);
  93. void Last(int *killswitch=0);
  94. int Next(int *killswitch=0);
  95. int Previous(int *killswitch=0);
  96. bool Eof(void);
  97. bool Bof(void);
  98. void New(void);
  99. int GetRecordsCount(void);
  100. void GetRecordById(int Id, bool checkFilters=true);
  101. int GetRecordId(void);
  102. void Sync(void);
  103. bool LocateByName(const char *column, int From, Field *field, int *nskip=NULL);
  104. bool LocateById(int Id, int From, Field *field, int *nskip=NULL);
  105. bool LocateByIdEx(int Id, int From, Field *field, int *nskip, int comp_mode);
  106. // Filters
  107. int AddFilterByName(const char *name, Field *Data, unsigned char Op);
  108. int AddFilterById(unsigned char Id, Field *Data, unsigned char Op);
  109. int AddFilterOp(unsigned char Op);
  110. void RemoveFilters(void);
  111. Filter *GetLastFilter(void);
  112. bool SetWorkingIndexByName(const char *desc);
  113. bool SetWorkingIndexById(unsigned char Id);
  114. void Search(const char *search_string);
  115. bool HasIndexChanged(void) { return iModified; }
  116. void ClearDirtyBit(void);
  117. float FragmentationLevel(void);
  118. Table *GetTable();
  119. int in_query_parser;
  120. int disable_date_resolution;
  121. };
  122. #endif