1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // CegoAttrComp.cc
4 // ---------------
5 // Cego database table attribute comparison description
6 //
7 // Design and Implementation by Bjoern Lemke
8 //
9 // (C)opyright 2000-2019 Bjoern Lemke
10 //
11 // IMPLEMENTATION MODULE
12 //
13 // Class: CegoAttrComp
14 //
15 // Description: Attribute comparison utility class
16 //
17 // Status: CLEAN
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21 // CEGO INCLUDES
22 #include "CegoAttrComp.h"
23
24 // POSIX INCLUDES
25 #include <stdlib.h>
26 #include <string.h>
27
CegoAttrComp()28 CegoAttrComp::CegoAttrComp()
29 {
30 _compMode = UNDEF;
31 _pMatcher = 0;
32 _pos=0;
33 }
34
CegoAttrComp(const Chain & tableName,const Chain & attrName)35 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName)
36 {
37 _tableName = tableName;
38 _attrName = attrName;
39 _compMode = UNDEF;
40 _pMatcher = 0;
41 _pos=0;
42 }
43
CegoAttrComp(const Chain & tableName,const Chain & attrName,CegoComparison comp,const CegoFieldValue & fv)44 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName, CegoComparison comp, const CegoFieldValue& fv)
45 {
46 _tableName = tableName;
47 _attrName = attrName;
48 _comp = comp;
49 _fv = fv;
50 _compMode = VAL;
51 _isSetup = false;
52 _pMatcher = 0;
53 _pos=0;
54 _isParentSetup = false;
55 _posSetup=false;
56 }
57
CegoAttrComp(const Chain & tableName,const Chain & attrName,CegoComparison comp,const CegoAttrDesc & attrDesc)58 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName, CegoComparison comp, const CegoAttrDesc& attrDesc)
59 {
60 _tableName = tableName;
61 _attrName = attrName;
62 _comp = comp;
63 _attrDesc = attrDesc;
64 _compMode = ATTR;
65 _pMatcher = 0;
66 _isSetup = false;
67 _pos=0;
68 _isParentSetup = false;
69 _posSetup=false;
70 }
71
CegoAttrComp(const Chain & tableName,const Chain & attrName,const CegoFieldValue & fv,const CegoFieldValue & fv2)72 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName, const CegoFieldValue& fv, const CegoFieldValue& fv2)
73 {
74 _tableName = tableName;
75 _attrName = attrName;
76 _fv = fv;
77 _fv2 = fv2;
78 _compMode = BTWN;
79 _btwnMode = VALUE2VALUE;
80 _pMatcher = 0;
81 _isSetup = true;
82 _isSetup2 = true;
83 _pos=0;
84 _isParentSetup = false;
85 _posSetup=false;
86
87 }
88
CegoAttrComp(const Chain & tableName,const Chain & attrName,const CegoAttrDesc & attrDesc,const CegoFieldValue & fv2)89 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName, const CegoAttrDesc& attrDesc, const CegoFieldValue& fv2)
90 {
91 _tableName = tableName;
92 _attrName = attrName;
93 _attrDesc = attrDesc;
94 _fv2 = fv2;
95 _compMode = BTWN;
96 _btwnMode = ATTR2VALUE;
97 _pMatcher = 0;
98 _isSetup = false;
99 _isSetup2 = true;
100 _pos=0;
101 _isParentSetup = false;
102 _posSetup=false;
103
104 }
105
CegoAttrComp(const Chain & tableName,const Chain & attrName,const CegoFieldValue & fv,const CegoAttrDesc & attrDesc2)106 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName, const CegoFieldValue& fv, const CegoAttrDesc& attrDesc2)
107 {
108 _tableName = tableName;
109 _attrName = attrName;
110 _fv = fv;
111 _attrDesc2 = attrDesc2;
112 _compMode = BTWN;
113 _btwnMode = VALUE2ATTR;
114 _pMatcher = 0;
115 _isSetup = true;
116 _isSetup2 = false;
117 _pos=0;
118 _isParentSetup = false;
119 _posSetup=false;
120 }
121
CegoAttrComp(const Chain & tableName,const Chain & attrName,const CegoAttrDesc & attrDesc,const CegoAttrDesc & attrDesc2)122 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName, const CegoAttrDesc& attrDesc, const CegoAttrDesc& attrDesc2)
123 {
124 _tableName = tableName;
125 _attrName = attrName;
126 _attrDesc = attrDesc;
127 _attrDesc2 = attrDesc2;
128 _compMode = BTWN;
129 _btwnMode = ATTR2ATTR;
130 _pMatcher = 0;
131 _isSetup = false;
132 _isSetup2 = false;
133 _pos=0;
134 _isParentSetup = false;
135 _posSetup=false;
136 }
137
CegoAttrComp(const Chain & tableName,const Chain & attrName,const Chain & pattern,bool isNot)138 CegoAttrComp::CegoAttrComp(const Chain& tableName, const Chain& attrName, const Chain& pattern, bool isNot)
139 {
140 _tableName = tableName;
141 _attrName = attrName;
142 _pattern = pattern;
143
144 if ( isNot )
145 _compMode = ISNOTLIKE;
146 else
147 _compMode = ISLIKE;
148 _pMatcher = 0;
149 _pos=0;
150 }
151
~CegoAttrComp()152 CegoAttrComp::~CegoAttrComp()
153 {
154 if ( _pMatcher )
155 delete _pMatcher;
156 }
157
getCompMode() const158 CegoAttrComp::CompMode CegoAttrComp::getCompMode() const
159 {
160 return _compMode;
161 }
162
getPos() const163 int CegoAttrComp::getPos() const
164 {
165 return _pos;
166 }
167
setPos(int pos)168 void CegoAttrComp::setPos(int pos)
169 {
170 _pos = pos;
171 }
172
setTableName(const Chain & tableName)173 void CegoAttrComp::setTableName(const Chain& tableName)
174 {
175 _tableName = tableName;
176 }
177
getTableName() const178 const Chain& CegoAttrComp::getTableName() const
179 {
180 return _tableName;
181 }
182
setAttrName(const Chain & attrName)183 void CegoAttrComp::setAttrName(const Chain& attrName)
184 {
185 _attrName = attrName;
186 }
187
getAttrName() const188 const Chain& CegoAttrComp::getAttrName() const
189 {
190 return _attrName;
191 }
192
getComparison() const193 CegoComparison CegoAttrComp::getComparison() const
194 {
195 return _comp;
196 }
197
setComparison(CegoComparison comp)198 void CegoAttrComp::setComparison(CegoComparison comp)
199 {
200 _comp = comp;
201 }
202
setFieldValue(const CegoFieldValue & fv)203 void CegoAttrComp::setFieldValue(const CegoFieldValue& fv)
204 {
205 _fv = fv;
206 }
207
setFieldValue2(const CegoFieldValue & fv)208 void CegoAttrComp::setFieldValue2(const CegoFieldValue& fv)
209 {
210 _fv2 = fv;
211 }
212
getFieldValue() const213 const CegoFieldValue& CegoAttrComp::getFieldValue() const
214 {
215 return _fv;
216 }
217
getFieldValue2() const218 const CegoFieldValue& CegoAttrComp::getFieldValue2() const
219 {
220 return _fv2;
221 }
222
setAttrDesc(const CegoAttrDesc & attrDesc)223 void CegoAttrComp::setAttrDesc(const CegoAttrDesc& attrDesc)
224 {
225 _attrDesc = attrDesc;
226 }
227
getAttrDesc() const228 const CegoAttrDesc& CegoAttrComp::getAttrDesc() const
229 {
230 return _attrDesc;
231 }
232
setAttrDesc2(const CegoAttrDesc & attrDesc)233 void CegoAttrComp::setAttrDesc2(const CegoAttrDesc& attrDesc)
234 {
235 _attrDesc2 = attrDesc;
236 }
237
getAttrDesc2() const238 const CegoAttrDesc& CegoAttrComp::getAttrDesc2() const
239 {
240 return _attrDesc2;
241 }
242
isNullComp() const243 bool CegoAttrComp::isNullComp() const
244 {
245 return ( _compMode == VAL && _fv.isNull() );
246 }
247
isSetup()248 bool CegoAttrComp::isSetup()
249 {
250 if ( _compMode == ATTR )
251 return _isSetup;
252 if ( _compMode == BTWN )
253 return _isSetup && _isSetup2;
254 // in any other case, not relevant
255 return true;
256 }
257
getPattern() const258 const Chain& CegoAttrComp::getPattern() const
259 {
260 return _pattern;
261 }
262
getMatcher()263 Matcher* CegoAttrComp::getMatcher()
264 {
265 if ( _pMatcher == 0)
266 {
267 Chain sqlPattern = Chain("^") + _pattern + Chain("$");
268 sqlPattern.replaceAll(Chain("%"), Chain(".*"), sqlPattern);
269 sqlPattern.replaceAll(Chain("_"), Chain("."), sqlPattern);
270 _pMatcher = new Matcher(sqlPattern);
271 _pMatcher->prepare();
272
273 }
274 return _pMatcher;
275 }
276
reset()277 void CegoAttrComp::reset()
278 {
279
280 if ( _compMode == ATTR )
281 _isSetup=false;
282 else if ( _compMode == BTWN )
283 {
284 if ( _btwnMode == VALUE2VALUE )
285 {
286 _isSetup=true;
287 _isSetup2=true;
288 }
289 else if ( _btwnMode == VALUE2ATTR )
290 {
291 _isSetup=true;
292 _isSetup2=false;
293 }
294 else if ( _btwnMode == ATTR2VALUE )
295 {
296 _isSetup=false;
297 _isSetup2=true;
298 }
299 else if ( _btwnMode == ATTR2ATTR )
300 {
301 _isSetup=false;
302 _isSetup2=false;
303 }
304 }
305 }
306
setup(const ListT<CegoField> & fl)307 bool CegoAttrComp::setup(const ListT<CegoField>& fl)
308 {
309 if ( _compMode == ATTR )
310 {
311 CegoField* pF = fl.First();
312 while ( pF && _isSetup == false )
313 {
314 if ( ( _attrDesc.getTableName() == pF->getTableName() || _attrDesc.getTableName()== pF->getTableAlias() )
315 && _attrDesc.getAttrName() == pF->getAttrName() )
316 {
317 _isSetup=true;
318 _fv = pF->getValue();
319 }
320 pF = fl.Next();
321 }
322 return _isSetup;
323 }
324 else if ( _compMode == BTWN )
325 {
326 CegoField* pF = fl.First();
327 while ( pF && _isSetup == false )
328 {
329 if ( ( _attrDesc.getTableName() == pF->getTableName() || _attrDesc.getTableName()== pF->getTableAlias() )
330 && _attrDesc.getAttrName() == pF->getAttrName() )
331 {
332 _isSetup=true;
333 _fv = pF->getValue();
334 }
335 pF = fl.Next();
336 }
337 pF = fl.First();
338 while ( pF && _isSetup2 == false )
339 {
340 if ( ( _attrDesc2.getTableName() == pF->getTableName() || _attrDesc2.getTableName()== pF->getTableAlias() )
341 && _attrDesc2.getAttrName() == pF->getAttrName() )
342 {
343 _isSetup2=true;
344 _fv2 = pF->getValue();
345 }
346 pF = fl.Next();
347 }
348 return _isSetup && _isSetup2;
349 }
350 else
351 {
352 throw Exception(EXLOC, Chain("Cannot setup attribute comparison"));
353 }
354 }
355
setup(ListT<CegoField> ** pJoinBuf,int offset)356 bool CegoAttrComp::setup(ListT<CegoField>** pJoinBuf, int offset)
357 {
358 int i = offset;
359
360 if ( _compMode == ATTR )
361 {
362 if ( _posSetup )
363 {
364 // cout << "Possetup for " << *this << endl;
365 // cout << "xpos=" << i + _xpos - 1 << " ypos=" << _ypos - 1 << endl;
366 _fv = (*pJoinBuf[i + _xpos-1])[_ypos-1].getValue();
367 // cout << "Set up fv to " << _fv << endl;
368 _isSetup = true;
369 }
370 else
371 {
372 _xpos=0;
373 while ( pJoinBuf[i] && _isSetup == false )
374 {
375 _ypos=0;
376 CegoField* pF = pJoinBuf[i]->First();
377 while (pF && _isSetup == false)
378 {
379 // cout << "Checking T=" << pF->getTableName() << " A=" << pF->getAttrName() << "Alias=" << pF->getTableAlias() << endl;
380 if ( ( _attrDesc.getTableName() == pF->getTableName() || _attrDesc.getTableName()== pF->getTableAlias() )
381 && _attrDesc.getAttrName() == pF->getAttrName() )
382 {
383 _isSetup = true;
384 _posSetup = true;
385 _fv = pF->getValue();
386 }
387 pF = pJoinBuf[i]->Next();
388 _ypos++;
389 }
390 i++;
391 _xpos++;
392 }
393 }
394 return _isSetup;
395 }
396 else if ( _compMode == BTWN )
397 {
398 if ( _posSetup )
399 {
400
401 /*
402 cout << "Possetup for " << *this << endl;
403 cout << "xpos=" << i + _xpos - 1 << " ypos=" << _ypos - 1 << endl;
404 cout << "xpos2=" << i + _xpos2 - 1 << " ypos2=" << _ypos2 - 1 << endl;
405 */
406
407 if ( _btwnMode == ATTR2VALUE || _btwnMode == ATTR2ATTR )
408 {
409 _fv = (*pJoinBuf[i + _xpos-1])[_ypos-1].getValue();
410 _isSetup = true;
411 }
412 if ( _btwnMode == VALUE2ATTR || _btwnMode == ATTR2ATTR )
413 {
414 _fv2 = (*pJoinBuf[i + _xpos2-1])[_ypos2-1].getValue();
415 _isSetup2 = true;
416 }
417 // cout << "Set up fv to " << _fv << endl;
418 // return true;
419 }
420 else
421 {
422
423 // cout << "Setting up " << toChain() << endl;
424
425 // we start with value 1, since setup condition interferes
426 _xpos=1;
427 _xpos2=1;
428
429 while ( pJoinBuf[i] && ( _isSetup == false || _isSetup2 == false ) )
430 {
431 _ypos=0;
432 CegoField* pF = pJoinBuf[i]->First();
433 while (pF && _isSetup == false)
434 {
435 // cout << "1 Checking " << _attrDesc.getAttrName() << " T=" << pF->getTableName() << " A=" << pF->getAttrName() << " Alias=" << pF->getTableAlias() << endl;
436 if ( ( _attrDesc.getTableName() == pF->getTableName() || _attrDesc.getTableName()== pF->getTableAlias() )
437 && _attrDesc.getAttrName() == pF->getAttrName() )
438 {
439 _isSetup = true;
440 _fv = pF->getValue();
441 }
442 pF = pJoinBuf[i]->Next();
443 _ypos++;
444 }
445 _ypos2=0;
446 pF = pJoinBuf[i]->First();
447 while (pF && _isSetup2 == false)
448 {
449 // cout << "2 Checking T=" << pF->getTableName() << " A=" << pF->getAttrName() << "Alias=" << pF->getTableAlias() << endl;
450 if ( ( _attrDesc2.getTableName() == pF->getTableName() || _attrDesc2.getTableName()== pF->getTableAlias() )
451 && _attrDesc2.getAttrName() == pF->getAttrName() )
452 {
453 _isSetup2 = true;
454 _fv2 = pF->getValue();
455 }
456 pF = pJoinBuf[i]->Next();
457 _ypos2++;
458 }
459 i++;
460
461 if ( _isSetup == false )
462 _xpos++;
463 if ( _isSetup2 == false )
464 _xpos2++;
465
466 }
467
468 _posSetup = _isSetup && _isSetup2;
469 }
470
471 return _posSetup;
472 }
473 else
474 {
475 throw Exception(EXLOC, Chain("Cannot setup attribute comparison"));
476 }
477 }
478
operator =(const CegoAttrComp & ac)479 CegoAttrComp& CegoAttrComp::operator = ( const CegoAttrComp& ac)
480 {
481 _tableName = ac._tableName;
482 _attrName = ac._attrName;
483 _comp = ac._comp;
484 _fv = ac._fv;
485 _fv2 = ac._fv2;
486 _attrDesc = ac._attrDesc;
487 _attrDesc2 = ac._attrDesc2;
488 _compMode = ac._compMode;
489 _btwnMode = ac._btwnMode;
490 _isSetup = ac._isSetup;
491 _isSetup2 = ac._isSetup2;
492 _posSetup = ac._posSetup;
493 _isParentSetup = ac._isParentSetup;
494 _xpos = ac._xpos;
495 _xpos2 = ac._xpos2;
496 _ypos = ac._ypos;
497 _ypos2 = ac._ypos2;
498 _pattern = ac._pattern;
499 _pMatcher = 0;
500 _pos = ac._pos;
501 return (*this);
502
503 }
504
operator ==(const CegoAttrComp & ac) const505 bool CegoAttrComp::operator == ( const CegoAttrComp& ac) const
506 {
507 if ( _compMode != ac._compMode )
508 return false;
509 if ( _compMode == ATTR )
510 return ( _tableName == ac._tableName && _attrName == ac._attrName && _comp == ac._comp );
511 if ( _compMode == VAL )
512 // we don't compare the values ( _fv == ac._fv ), since CegoAttrCond::update sets it up
513 return ( _tableName == ac._tableName && _attrName == ac._attrName && _comp == ac._comp );
514 if ( _compMode == BTWN )
515 {
516 // we don't compare the values ( _fv == ac._fv && _fv2 == ac._fv2 ), since CegoAttrCond::update sets it up
517
518 switch ( _btwnMode )
519 {
520 case VALUE2VALUE:
521 return ( _tableName == ac._tableName && _attrName == ac._attrName );
522 case VALUE2ATTR:
523 return ( ( _tableName == ac._tableName && _attrName == ac._attrName ) && ( _attrDesc2 == ac._attrDesc2 ) );
524 case ATTR2VALUE:
525 return ( ( _tableName == ac._tableName && _attrName == ac._attrName ) && ( _attrDesc == ac._attrDesc ) );
526 case ATTR2ATTR:
527 return ( ( _tableName == ac._tableName && _attrName == ac._attrName ) && ( _attrDesc == ac._attrDesc ) && ( _attrDesc2 == ac._attrDesc2 ) );
528 }
529 }
530 if ( _compMode == ISLIKE || _compMode == ISNOTLIKE )
531 return ( _tableName == ac._tableName && _attrName == ac._attrName && _pattern == ac._pattern );
532
533 return false;
534 }
535
operator <(const CegoAttrComp & ac) const536 bool CegoAttrComp::operator < ( const CegoAttrComp& ac) const
537 {
538 if ( _pos < ac._pos )
539 return true;
540 if ( _pos > ac._pos )
541 return false;
542
543 if ( _tableName < ac._tableName )
544 return true;
545 if ( _tableName > ac._tableName )
546 return false;
547
548 if ( _attrName < ac._attrName )
549 return true;
550 if ( _attrName > ac._attrName )
551 return false;
552
553 if ( _compMode == BTWN )
554 {
555 if ( _btwnMode == VALUE2VALUE )
556 {
557 if ( _fv < ac._fv )
558 return true;
559 if ( _fv > ac._fv )
560 return false;
561 return ( _fv2 < ac._fv2 );
562 }
563 else if ( _btwnMode == VALUE2ATTR )
564 {
565 if ( (Chain)_attrDesc2.getTableName() < (Chain)ac.getAttrDesc2().getTableName() )
566 return true;
567 if ( (Chain)_attrDesc2.getTableName() > (Chain)ac.getAttrDesc2().getTableName() )
568 return false;
569 if ( (Chain)_attrDesc2.getAttrName() < (Chain)ac.getAttrDesc2().getAttrName() )
570 return true;
571 if ( (Chain)_attrDesc2.getAttrName() > (Chain)ac.getAttrDesc2().getAttrName() )
572 return false;
573 if ( _fv < ac._fv )
574 return true;
575 if ( _fv > ac._fv )
576 return false;
577 return ( _fv2 < ac._fv2 );
578 }
579 else if ( _btwnMode == ATTR2VALUE )
580 {
581 if ( (Chain)_attrDesc.getTableName() < (Chain)ac.getAttrDesc().getTableName() )
582 return true;
583 if ( (Chain)_attrDesc.getTableName() > (Chain)ac.getAttrDesc().getTableName() )
584 return false;
585 if ( (Chain)_attrDesc.getAttrName() < (Chain)ac.getAttrDesc().getAttrName() )
586 return true;
587 if ( (Chain)_attrDesc.getAttrName() > (Chain)ac.getAttrDesc().getAttrName() )
588 return false;
589 if ( _fv < ac._fv )
590 return true;
591 if ( _fv > ac._fv )
592 return false;
593 return ( _fv2 < ac._fv2 );
594 }
595 else // if ( _btwnMode == ATTR2ATTR )
596 {
597 if ( (Chain)_attrDesc.getTableName() < (Chain)ac.getAttrDesc().getTableName() )
598 return true;
599 if ( (Chain)_attrDesc.getTableName() > (Chain)ac.getAttrDesc().getTableName() )
600 return false;
601 if ( (Chain)_attrDesc.getAttrName() < (Chain)ac.getAttrDesc().getAttrName() )
602 return true;
603 if ( (Chain)_attrDesc.getAttrName() > (Chain)ac.getAttrDesc().getAttrName() )
604 return false;
605 if ( (Chain)_attrDesc2.getTableName() < (Chain)ac.getAttrDesc2().getTableName() )
606 return true;
607 if ( (Chain)_attrDesc2.getTableName() > (Chain)ac.getAttrDesc2().getTableName() )
608 return false;
609 if ( (Chain)_attrDesc2.getAttrName() < (Chain)ac.getAttrDesc2().getAttrName() )
610 return true;
611 if ( (Chain)_attrDesc2.getAttrName() > (Chain)ac.getAttrDesc2().getAttrName() )
612 return false;
613 if ( _fv < ac._fv )
614 return true;
615 if ( _fv > ac._fv )
616 return false;
617 return ( _fv2 < ac._fv2 );
618 }
619 }
620 else if ( _compMode == ISLIKE || _compMode == ISNOTLIKE )
621 {
622 return ( _pattern < ac._pattern );
623 }
624 else
625 {
626 if ( _comp < ac._comp )
627 return true;
628 if ( _comp > ac._comp )
629 return false;
630 return ( _fv < ac._fv );
631 }
632 }
633
operator >(const CegoAttrComp & ac) const634 bool CegoAttrComp::operator > ( const CegoAttrComp& ac) const
635 {
636 if ( _pos > ac._pos )
637 return true;
638 if ( _pos < ac._pos )
639 return false;
640
641 if ( _tableName < ac._tableName )
642 return false;
643 if ( _tableName > ac._tableName )
644 return true;
645
646 if ( _attrName < ac._attrName )
647 return false;
648 if ( _attrName > ac._attrName )
649 return true;
650
651 if ( _compMode == BTWN )
652 {
653 if ( _btwnMode == VALUE2VALUE )
654 {
655 if ( _fv > ac._fv )
656 return true;
657 if ( _fv < ac._fv )
658 return false;
659 return ( _fv2 > ac._fv2 );
660 }
661 else if ( _btwnMode == VALUE2ATTR )
662 {
663 if ( (Chain)_attrDesc2.getTableName() > (Chain)ac.getAttrDesc2().getTableName() )
664 return true;
665 if ( (Chain)_attrDesc2.getTableName() < (Chain)ac.getAttrDesc2().getTableName() )
666 return false;
667 if ( (Chain)_attrDesc2.getAttrName() > (Chain)ac.getAttrDesc2().getAttrName() )
668 return true;
669 if ( (Chain)_attrDesc2.getAttrName() < (Chain)ac.getAttrDesc2().getAttrName() )
670 return false;
671 if ( _fv > ac._fv )
672 return true;
673 if ( _fv < ac._fv )
674 return false;
675 return ( _fv2 > ac._fv2 );
676 }
677 else if ( _btwnMode == ATTR2VALUE )
678 {
679 if ( (Chain)_attrDesc.getTableName() > (Chain)ac.getAttrDesc().getTableName() )
680 return true;
681 if ( (Chain)_attrDesc.getTableName() < (Chain)ac.getAttrDesc().getTableName() )
682 return false;
683 if ( (Chain)_attrDesc.getAttrName() > (Chain)ac.getAttrDesc().getAttrName() )
684 return true;
685 if ( (Chain)_attrDesc.getAttrName() < (Chain)ac.getAttrDesc().getAttrName() )
686 return false;
687 if ( _fv > ac._fv )
688 return true;
689 if ( _fv < ac._fv )
690 return false;
691 return ( _fv2 > ac._fv2 );
692 }
693 else // if ( _btwnMode == ATTR2ATTR )
694 {
695 if ( (Chain)_attrDesc.getTableName() > (Chain)ac.getAttrDesc().getTableName() )
696 return true;
697 if ( (Chain)_attrDesc.getTableName() < (Chain)ac.getAttrDesc().getTableName() )
698 return false;
699 if ( (Chain)_attrDesc.getAttrName() > (Chain)ac.getAttrDesc().getAttrName() )
700 return true;
701 if ( (Chain)_attrDesc.getAttrName() < (Chain)ac.getAttrDesc().getAttrName() )
702 return false;
703 if ( (Chain)_attrDesc2.getTableName() > (Chain)ac.getAttrDesc2().getTableName() )
704 return true;
705 if ( (Chain)_attrDesc2.getTableName() < (Chain)ac.getAttrDesc2().getTableName() )
706 return false;
707 if ( (Chain)_attrDesc2.getAttrName() > (Chain)ac.getAttrDesc2().getAttrName() )
708 return true;
709 if ( (Chain)_attrDesc2.getAttrName() < (Chain)ac.getAttrDesc2().getAttrName() )
710 return false;
711 if ( _fv > ac._fv )
712 return true;
713 if ( _fv < ac._fv )
714 return false;
715 return ( _fv2 > ac._fv2 );
716 }
717 }
718 else if ( _compMode == ISLIKE || _compMode == ISNOTLIKE )
719 {
720 return ( _pattern > ac._pattern );
721 }
722 else
723 {
724 if ( _comp < ac._comp )
725 return false;
726 if ( _comp > ac._comp )
727 return true;
728 return ( _fv > ac._fv );
729 }
730 }
731
getId() const732 Chain CegoAttrComp::getId() const
733 {
734 Chain s;
735
736 s = _tableName + Chain(".") + _attrName;
737
738 if ( _compMode == BTWN )
739 {
740 switch ( _btwnMode )
741 {
742 case VALUE2VALUE:
743 s += Chain("#btw#") + _fv.toChain() + Chain("#") + _fv2.toChain();
744 break;
745 case VALUE2ATTR:
746 s += Chain("#btw#") + _fv.toChain() + Chain("#") + _attrDesc2.toChain();
747 break;
748 case ATTR2VALUE:
749 s += Chain("#btw#") + _attrDesc.toChain() + Chain("#") + _fv2.toChain();
750 break;
751 case ATTR2ATTR:
752 s += Chain("#btw#") + _attrDesc.toChain() + Chain("#") + _attrDesc2.toChain();
753 break;
754 }
755 }
756 else if ( _compMode == ISLIKE )
757 {
758 s += Chain("lk'") + _pattern + Chain("'");
759 }
760 else if ( _compMode == ISNOTLIKE )
761 {
762 s += Chain("nlk'") + _pattern + Chain("'");
763 }
764 else
765 {
766 switch ( _comp )
767 {
768 case EQUAL:
769 s += Chain("=");
770 break;
771 case NOT_EQUAL:
772 s += Chain("!=");
773 break;
774 case LESS_THAN:
775 s += Chain("<");
776 break;
777 case MORE_THAN:
778 s += Chain(">");
779 break;
780 case LESS_EQUAL_THAN:
781 s += Chain("<=");
782 break;
783 case MORE_EQUAL_THAN:
784 s += Chain(">=");
785 break;
786 }
787 if ( _compMode == VAL )
788 s += _fv.toChain();
789 else
790 {
791 s += _attrDesc.toChain();
792 if ( _isSetup )
793 s += _fv.toChain();
794 else
795 s += Chain("#not setup#");
796 }
797 }
798 return s;
799 }
800
toChain() const801 Chain CegoAttrComp::toChain() const
802 {
803 Chain s;
804
805 s = _tableName + "." + _attrName; // + "(" + Chain(_pos) + ")";
806
807
808 if ( _compMode == BTWN )
809 {
810 switch ( _btwnMode )
811 {
812 case VALUE2VALUE:
813 s += Chain(" between ") + _fv.toChain() + Chain(" and ") + _fv2.toChain();
814 break;
815 case VALUE2ATTR:
816 s += Chain(" between ") + _fv.toChain() + Chain(" and ") + _attrDesc2.toChain();
817 break;
818 case ATTR2VALUE:
819 s += Chain(" between ") + _attrDesc.toChain() + Chain(" and ") + _fv2.toChain();
820 break;
821 case ATTR2ATTR:
822 s += Chain(" between ") + _attrDesc.toChain() + Chain(" and ") + _attrDesc2.toChain();
823 break;
824 }
825 }
826 else if ( _compMode == ISLIKE )
827 {
828 s += Chain(" like '") + _pattern + Chain("'");
829 }
830 else if ( _compMode == ISNOTLIKE )
831 {
832 s += Chain(" not like '") + _pattern + Chain("'");
833 }
834 else
835 {
836 switch ( _comp )
837 {
838 case EQUAL:
839 s += Chain(" = ");
840 break;
841 case NOT_EQUAL:
842 s += Chain(" != ");
843 break;
844 case LESS_THAN:
845 s += Chain(" < ");
846 break;
847 case MORE_THAN:
848 s += Chain(" > ");
849 break;
850 case LESS_EQUAL_THAN:
851 s += Chain(" <= ");
852 break;
853 case MORE_EQUAL_THAN:
854 s += Chain(" >= ");
855 break;
856 }
857 if ( _compMode == VAL )
858 s += _fv.toChain();
859 else
860 {
861 s += _attrDesc.toChain();
862 if ( _isSetup )
863 s += Chain("(") + _fv.toChain() + Chain(")");
864 else
865 s += Chain(" -> not setup ");
866 }
867 }
868 return s;
869 }
870
operator <<(ostream & s,const CegoAttrComp & ac)871 ostream& operator << (ostream& s, const CegoAttrComp& ac)
872 {
873 s << ac.toChain();
874 return s;
875 }
876