OOFILE  1.9
oofquery.h
Go to the documentation of this file.
1 #ifndef H_OOFQUERY
2 #define H_OOFQUERY
3 
4 // COPYRIGHT 1994 A.D. Software, All rights reserved
5 
26 #ifndef H_OOF1
27  #include "oof1.h"
28 #endif
29 
30 class dbQueryField ;
31 class dbQueryLiteral;
32 class dbQueryLiteralStr;
34 class dbQueryBinaryCombo;
36 class dbField;
37 class dbCompoundField;
38 class dbTable;
39 class oofWordParser;
40 
41 
47 public:
48  enum BinaryQueryOps {equals, notEquals, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, startsWith,
49  hasWord, hasAnyWord, hasAllWords, hasWordStartsWith, hasAnyWordStartsWith, hasAllWordsStartsWith};
50  enum TrinaryQueryOps {between, outside};
51  enum QueryCombinatorialOps {oofAND, oofOR};
52  enum QueryClauseTypes {binaryfieldToLiteral, binaryfieldTofield, trinaryFieldToLiterals, entireTable, atomicfield, atomicLiteral, atomicLiteralStr, multiLiteralStr, binaryCombination, builtQuery};
53 
54  // use default copy ctor
55  virtual ~dbQueryClause() {};
56  virtual dbQueryClause* clone() const=0;
57 
58  virtual dbQueryClause::QueryClauseTypes queryClauseType() const=0;
59  bool isSimpleIndexedSearch() const;
60  virtual void getSearchTables(const dbTable* inSchTable,
61  dbTable*& outDiffFieldTable,
62  dbTable*& outRelatedTable) const;
63  virtual dbQueryClause* cloneReplacingTable(const dbTable* inTable, const dbTable* repTable) const;
64 
65 // combinatorial operators
66  dbQueryBinaryCombo operator&(const dbQueryClause&) const;
67  dbQueryBinaryCombo operator&&(const dbQueryClause&) const;
68  dbQueryBinaryCombo operator|(const dbQueryClause&) const;
69  dbQueryBinaryCombo operator||(const dbQueryClause&) const;
70 
71  dbQueryBinaryComboOwner* operator|(dbQueryClause* adoptRHS);
72  dbQueryBinaryComboOwner* operator||(dbQueryClause* adoptRHS);
73  dbQueryBinaryComboOwner* operator&(dbQueryClause* adoptRHS);
74  dbQueryBinaryComboOwner* operator&&(dbQueryClause* adoptRHS);
75 
76  virtual void describe(std::ostream&) const=0;
77 
78 protected:
80 
81 // other protocol
82 // part of testing dbTable *AppliesToTable();
83 
84 public:
85  static bool wildcardsInString(const char*);
86  static char sWildcardMultiple; // not const so user can change!
87  static char sWildcardSingle;
88  static bool isWordSearch(dbQueryClause::BinaryQueryOps);
89 };
90 //operator=(dbTable lhs, dbQueryClause& rhs);
91 OOFILE_EXPORT std::ostream& operator<<(std::ostream&, dbQueryClause::BinaryQueryOps);
92 OOFILE_EXPORT std::ostream& operator<<(std::ostream&, dbQueryClause::TrinaryQueryOps);
94 OOFILE_EXPORT std::ostream& operator<<(std::ostream&, dbQueryClause::QueryClauseTypes);
95 
96 
102 public:
103  dbQuery();
104  // use default copy ctor
105  virtual ~dbQuery();
106  virtual dbQueryClause* clone() const;
107 
109  virtual void getSearchTables(const dbTable* inSchTable,
110  dbTable*& outDiffFieldTable,
111  dbTable*& outRelatedTable) const;
112  virtual dbQueryClause* cloneReplacingTable(const dbTable* inTable, const dbTable* repTable) const;
113 
114  void operator|=(dbQueryClause* adoptedPortion);
115  void operator&=(dbQueryClause* adoptedPortion);
116 
117  const dbQueryClause* query() const;
118 
119  virtual void describe(std::ostream&) const;
120 
121 private:
122  dbQueryClause* mQuery; // recursively built as binary combos
123 };
124 
125 
131 public:
134  virtual ~dbQueryBinaryNofield();
135  virtual dbQueryClause* clone() const;
136 private:
138 
139 public:
141  dbQueryLiteralStr* literalStrClause() const;
142  dbQueryLiteralStrMultiValue* literalMultiStrClause() const;
143  dbQueryLiteral* literalClause() const;
144  dbQueryClause::BinaryQueryOps binaryOperator() const;
145 
146  virtual void describe(std::ostream&) const;
147 
148 protected:
149 
150 // other protocol
151 // part of testing dbTable *AppliesToTable();
152 
153 // data storage
154 protected:
155  dbQueryClause* mRhs; // owned
157 };
158 
159 
166 public:
168  dbQueryBinary(BinaryQueryOps op, dbQueryClause* litOrFld); // for table searches
170  virtual ~dbQueryBinary();
171  virtual dbQueryClause* clone() const;
172 private:
173  dbQueryBinary& operator=(dbQueryBinary&);
174 
175 public:
177  virtual void getSearchTables(const dbTable* inSchTable,
178  dbTable*& outDiffFieldTable,
179  dbTable*& outRelatedTable) const;
180  virtual dbQueryClause* cloneReplacingTable(const dbTable* inTable, const dbTable* repTable) const;
181 
182  const dbField* lhsField() const;
183  bool isSimpleIndexedSearch() const;
184 
185  virtual void describe(std::ostream&) const;
186 
187 protected:
188 
189 // other protocol
190 // part of testing dbTable *AppliesToTable();
191 
192 // data storage
193 protected:
194  dbQueryField *mLhs; // owned
195 };
196 
197 
204 public:
205 // NOT YET IMPLEMENTED extend to any number of clauses with same op
208  virtual ~dbQueryBinaryCombo();
209  virtual dbQueryClause* clone() const;
210 private:
212 
213 public:
215  dbQueryClause::QueryCombinatorialOps binaryOperator() const;
216  const dbQueryClause* item(unsigned int) const;
217  unsigned long pairFieldsIfCouldUseCompoundIndex() const;
218  dbQueryClause* makeCompoundSearch(const dbCompoundField*);
219 
220  virtual dbQueryClause* cloneReplacingTable(const dbTable* inTable, const dbTable* repTable) const;
221  virtual void describe(std::ostream&) const;
222 
223 protected:
224 
225 // other protocol
226 // part of testing dbTable *AppliesToTable();
227 
228 // data storage
229 protected:
230 // NOTE unlike the other Binary and Trinary, we do NOT own our lhs & rhs
231  const dbQueryClause *mLhs, *mRhs;
233  char *mTempKeyStoreToDispose, *mTempKeyStoreToDispose2;
234 };
235 
236 
245 public:
247  // use default copy ctor
248  virtual ~dbQueryBinaryComboOwner();
249  virtual dbQueryClause* clone() const;
250 
251  virtual void describe(std::ostream&) const;
252 
253 private:
254  dbQueryClause *mOurLhs, *mOurRhs; // owned
255 };
256 
257 
264 public:
266  mLhs(fld),
267  mFrom(litOrFldFrom),
268  mTo(litOrFldTo),
269  mTrinOp(op)
270  {};
272  virtual ~dbQueryTrinary();
273  virtual dbQueryClause* clone() const;
274 private:
275  dbQueryTrinary& operator=(dbQueryTrinary&);
276 
277 public:
279  virtual void getSearchTables(const dbTable* inSchTable,
280  dbTable*& outDiffFieldTable,
281  dbTable*& outRelatedTable) const;
282  virtual dbQueryClause* cloneReplacingTable(const dbTable* inTable, const dbTable* repTable) const;
283 
284  dbQueryLiteralStr* literalStrFromClause() const;
285  dbQueryLiteralStr* literalStrToClause() const;
286  dbQueryLiteral* literalFromClause() const;
287  dbQueryLiteral* literalToClause() const;
288  dbQueryClause::TrinaryQueryOps trinaryOperator() const;
289  const dbField* lhsField() const;
290 
291  virtual void describe(std::ostream&) const;
292 
293 protected:
294 
295 // data storage
296 protected:
297  dbQueryField *mLhs; // owned
298  dbQueryClause *mFrom, *mTo; // owned
300 };
301 
302 
308 public:
310  virtual const void* binaryContents() const;
311  virtual unsigned short literalLen() const;
312  virtual ~dbQueryLiteral() {};
313 
314 protected:
316  // use default copy ctor
317 };
318 
319 
325 public:
326  dbQueryLiteralStr(const char* inStr) :
327  mStr(inStr),
328  mCheckedForWildcards(neverChecked)
329  {}
330  // use default copy ctor
331  virtual ~dbQueryLiteralStr() {}
332  virtual dbQueryClause* clone() const;
333 
335  const char* str() const;
336  virtual const void* binaryContents() const;
337  virtual unsigned short literalLen() const;
338 
339  bool hasWildcards();
340 
341  virtual void describe(std::ostream&) const;
342 
343 // data storage
344 private:
345  OOF_String mStr;
346  enum WildcardCheckT { neverChecked, hasNone, hasWild };
347  WildcardCheckT mCheckedForWildcards;
348 };
349 
350 
356 public:
357  virtual void start()=0;
358  virtual bool more()=0;
359  virtual void next()=0;
360  virtual const char* current()=0;
362 };
363 
364 
370 public:
371  dbQueryLiteralStrDelimited(const char* str, char delim) :
372  mStr(str),
373  mDelim(delim)
374  {};
375  // use default copy ctor
376  virtual ~dbQueryLiteralStrDelimited();
377  virtual dbQueryClause* clone() const;
378 
379  virtual void start();
380  virtual bool more();
381  virtual void next();
382  virtual const char* current();
383 
384  virtual void describe(std::ostream&) const;
385 
386 private:
387  void CalcWordLen();
388 
389 // data storage
390  const char* mStr;
391  const char* mReadFrom;
392  const char* mEndStr;
393  char mDelim;
394  oofString mCurrent;
395  unsigned long mStrLen, mWordLen;
396 };
397 
398 
404 public:
405  dbQueryLiteralStrArray(const char **schStrs, unsigned long count) :
406  mSchStrs(schStrs),
407  mCount(count)
408  {};
409  // use default copy ctor
410  virtual ~dbQueryLiteralStrArray();
411  virtual dbQueryClause* clone() const;
412 
413  virtual void start();
414  virtual bool more();
415  virtual void next();
416  virtual const char* current();
417 
418  virtual void describe(std::ostream&) const;
419 
420 // data storage
421 private:
422  const char **mSchStrs;
423  unsigned long mCount, mIter;
424 };
425 
426 
432 public:
434  mNum(d) {};
435  // use default copy ctor
436  virtual ~dbQueryLiteralDouble() {};
437  virtual dbQueryClause* clone() const;
438 
439  virtual const void* binaryContents() const;
440  virtual unsigned short literalLen() const;
441 
442  virtual void describe(std::ostream&) const;
443 
444 // data storage
445 private:
446  const double mNum;
447 };
448 
449 
455 public:
456  dbQueryLiteralBLOB(void* blob, unsigned short len) :
457  mBLOB(blob),
458  mBLOBlen(len)
459  {};
460  // use default copy ctor
461  virtual ~dbQueryLiteralBLOB();
462  virtual dbQueryClause* clone() const;
463 
464  virtual const void* binaryContents() const;
465  virtual unsigned short literalLen() const;
466 
467  virtual void describe(std::ostream&) const;
468 
469 // data storage
470 private:
471  const void* mBLOB;
472  unsigned short mBLOBlen;
473 };
474 
475 
481 public:
483  mNum(l) {};
484  // use default copy ctor
485  virtual ~dbQueryLiteralLong() {};
486  virtual dbQueryClause* clone() const;
487 
488  virtual const void* binaryContents() const;
489  virtual unsigned short literalLen() const;
490 
491  virtual void describe(std::ostream&) const;
492 
493 // data storage
494 private:
495  const long mNum;
496 };
497 
498 
504 public:
505  dbQueryLiteralUlong(unsigned long l) :
506  mNum(l) {};
507  // use default copy ctor
508  virtual ~dbQueryLiteralUlong() {};
509  virtual dbQueryClause* clone() const;
510 
511  virtual const void* binaryContents() const;
512  virtual unsigned short literalLen() const;
513 
514  virtual void describe(std::ostream&) const;
515 
516 // data storage
517 private:
518  const unsigned long mNum;
519 };
520 
521 
527 public:
529  mNum(s) {};
530  // use default copy ctor
531  virtual ~dbQueryLiteralShort() {};
532  virtual dbQueryClause* clone() const;
533 
534  virtual const void* binaryContents() const;
535  virtual unsigned short literalLen() const;
536 
537  virtual void describe(std::ostream&) const;
538 
539 // data storage
540 private:
541  const short mNum;
542 };
543 
544 
550 public:
551  dbQueryLiteralUshort(unsigned short s) :
552  mNum(s) {};
553  // use default copy ctor
555  virtual dbQueryClause* clone() const;
556 
557  virtual const void* binaryContents() const;
558  virtual unsigned short literalLen() const;
559 
560  virtual void describe(std::ostream&) const;
561 
562 // data storage
563 private:
564  const unsigned short mNum;
565 };
566 
567 
573 public:
574 // constructors
575  dbQueryField(const dbField* fld) :
576  mField(fld) {};
577  // use default copy ctor
578  virtual ~dbQueryField();
579  virtual dbQueryClause* clone() const;
580 
581  const dbField* field() const {return mField;};
583  virtual void getSearchTables(const dbTable* inSchTable,
584  dbTable*& outDiffFieldTable,
585  dbTable*& outRelatedTable) const;
586  virtual dbQueryClause* cloneReplacingTable(const dbTable* inTable, const dbTable* repTable) const;
587 
588  virtual void describe(std::ostream&) const;
589 
590 // data storage
591  const dbField* mField;
592 };
593 
594 
595 
596 // -------------------------------------------------------
597 // d b Q u e r y
598 // -------------------------------------------------------
599 inline const dbQueryClause*
601 {
602  return mQuery;
603 }
604 
605 
606 // -------------------------------------------------------
607 // d b Q u e r y B i n a r y N o F i e l d
608 // -------------------------------------------------------
611 {
612  return mBinOp;
613 }
614 
615 
616 // -------------------------------------------------------
617 // d b Q u e r y B i n a r y
618 // -------------------------------------------------------
619 inline const dbField*
621 {
622  return mLhs->field();
623 }
624 
625 
626 // -------------------------------------------------------
627 // d b Q u e r y B i n a r y C o m b o
628 // -------------------------------------------------------
631 {
632  return mComboOp;
633 }
634 
635 
636 // -------------------------------------------------------
637 // d b Q u e r y T r i n a r y
638 // -------------------------------------------------------
641 {
642  return mTrinOp;
643 }
644 
645 
646 inline const dbField* dbQueryTrinary::lhsField() const
647 {
648  return mLhs->field();
649 }
650 
651 
652 // -------------------------------------------------------
653 // d b Q u e r y F i e l d
654 // -------------------------------------------------------
655 //inline const dbField*
656 //dbQueryField::field() const
657 //{
658 // return mField;
659 //}
660 
661 
662 // -------------------------------------------------------
663 // d b Q u e r y L i t e r a l S t r
664 // -------------------------------------------------------
665 inline const char*
667 {
668  return mStr;
669 }
670 
671 
672 #endif
673 
dbQueryField(const dbField *fld)
Definition: oofquery.h:575
virtual void describe(std::ostream &) const
Definition: oofquery.cpp:259
const dbField * lhsField() const
Definition: oofquery.h:620
RHS unsigned long argument to queries on fields like dbUlong.
Definition: oofquery.h:503
virtual ~dbQueryClause()
Definition: oofquery.h:55
virtual dbQueryClause * clone() const
Definition: oofquery.cpp:244
virtual void describe(std::ostream &) const =0
Binary query combining two sub-queries.
Definition: oofquery.h:203
String fragment arguments passed in as array of C strings.
Definition: oofquery.h:403
Base class for user-replaceable word parser.
Definition: oofwords.h:40
dbQueryLiteralUlong(unsigned long l)
Definition: oofquery.h:505
BinaryQueryOps mBinOp
Definition: oofquery.h:156
Highest level used to assemble queries.
Definition: oofquery.h:46
String fragment arguments passed in as single string with a delimiter character.
Definition: oofquery.h:369
dbQueryClause::QueryCombinatorialOps binaryOperator() const
Definition: oofquery.h:630
char * mTempKeyStoreToDispose2
Definition: oofquery.h:233
virtual dbQueryClause::QueryClauseTypes queryClauseType() const
Definition: oofquery.cpp:891
virtual dbQueryClause * clone() const
Definition: oofquery.cpp:438
const dbQueryClause * query() const
Definition: oofquery.h:600
RHS double argument to queries on fields like dbReal.
Definition: oofquery.h:431
dbQueryClause * mRhs
Definition: oofquery.h:155
virtual ~dbQueryLiteralDouble()
Definition: oofquery.h:436
dbQueryClause::BinaryQueryOps binaryOperator() const
Definition: oofquery.h:610
Abstract base for string fragment queries like OOF_mixKeywordableField::hasAnyWordsOf.
Definition: oofquery.h:355
Common trinary query for field, eg: People.Salary.between(50000, 90000); Very similar to dbQueryBinar...
Definition: oofquery.h:263
virtual void getSearchTables(const dbTable *inSchTable, dbTable *&outDiffFieldTable, dbTable *&outRelatedTable) const
Definition: oofquery.cpp:41
virtual ~dbQueryLiteralShort()
Definition: oofquery.h:531
RHS long argument to queries on fields like dbLong.
Definition: oofquery.h:480
bool isSimpleIndexedSearch() const
Definition: oofquery.cpp:65
virtual dbQueryClause * cloneReplacingTable(const dbTable *inTable, const dbTable *repTable) const
Definition: oofquery.cpp:48
dbQueryLiteralStrDelimited(const char *str, char delim)
Definition: oofquery.h:371
virtual ~dbQueryLiteralLong()
Definition: oofquery.h:485
Common binary query for field, eg: People.Salary > 90000.
Definition: oofquery.h:165
const dbQueryClause * mRhs
Definition: oofquery.h:231
virtual unsigned short literalLen() const
Definition: oofquery.cpp:905
Builder class used to combine sub-queries when constructing runtime queries.
Definition: oofquery.h:244
virtual dbQueryClause * clone() const =0
LHS argument to queries on fields.
Definition: oofquery.h:572
virtual const char * current()=0
virtual const void * binaryContents() const
Definition: oofquery.cpp:898
static char sWildcardMultiple
Definition: oofquery.h:86
QueryCombinatorialOps
Definition: oofquery.h:51
class for building queries of arbitrary complexity with application logic.
Definition: oofquery.h:101
TrinaryQueryOps mTrinOp
Definition: oofquery.h:299
dbQueryLiteralStrArray(const char **schStrs, unsigned long count)
Definition: oofquery.h:405
Argument mainly used to support compound key queries ending in binary number.
Definition: oofquery.h:454
virtual ~dbQueryLiteralStr()
Definition: oofquery.h:331
virtual ~dbQueryLiteralUshort()
Definition: oofquery.h:554
dbQueryLiteralShort(short s)
Definition: oofquery.h:528
Persistent field used to store a set of segments referring to other fields.
Definition: oof3.h:575
Base class for persistent tables.
Definition: oof1.h:452
dbQueryClause::TrinaryQueryOps trinaryOperator() const
Definition: oofquery.h:640
Portable highly capable string class.
Definition: oofstr.h:101
virtual dbQueryClause::QueryClauseTypes queryClauseType() const
Definition: oofquery.cpp:268
virtual void describe(std::ostream &) const
Definition: oofquery.cpp:481
const dbField * lhsField() const
Definition: oofquery.h:646
RHS short argument to queries on fields like dbShort.
Definition: oofquery.h:526
const dbField * mField
Definition: oofquery.h:591
dbQueryLiteralBLOB(void *blob, unsigned short len)
Definition: oofquery.h:456
dbQueryLiteralLong(long l)
Definition: oofquery.h:482
RHS unsigned short argument to queries on fields like dbUshort.
Definition: oofquery.h:549
static char sWildcardSingle
Definition: oofquery.h:87
RHS String argument to queries on fields like dbChar.
Definition: oofquery.h:324
const char * str() const
Definition: oofquery.h:666
virtual ~dbQueryLiteral()
Definition: oofquery.h:312
std::ostream & operator<<(std::ostream &, const oofE_Base &)
dbQueryLiteralDouble(double d)
Definition: oofquery.h:433
dbQueryTrinary(dbQueryField *fld, TrinaryQueryOps op, dbQueryClause *litOrFldFrom, dbQueryClause *litOrFldTo)
Definition: oofquery.h:265
dbQueryClause * mTo
Definition: oofquery.h:298
#define OOFILE_EXPORT
Prefix for OOFILE database & general classes to enable optional DLL linking.
Definition: oof0.h:187
QueryCombinatorialOps mComboOp
Definition: oofquery.h:232
dbQueryField * mLhs
Definition: oofquery.h:297
dbQueryLiteralUshort(unsigned short s)
Definition: oofquery.h:551
Binary query where LHS is table, eg: dbTable::hasAllWordsDelimited.
Definition: oofquery.h:130
dbQueryLiteralStr(const char *inStr)
Definition: oofquery.h:326
Base for the RHS arguments to combinatorial queries dbQueryBinary, dbQueryTrinary.
Definition: oofquery.h:307
Base class for persistent fields in dbTable's.
Definition: oof3.h:63
virtual ~dbQueryLiteralUlong()
Definition: oofquery.h:508
dbQueryField * mLhs
Definition: oofquery.h:194
const dbField * field() const
Definition: oofquery.h:581
virtual dbQueryClause::QueryClauseTypes queryClauseType() const =0