InfiniSQL  v0.1.2-alpha
Massive Scale Transaction Processing
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Ast Class Reference

Abstract Syntax Tree. More...

#include <Asts.h>

Collaboration diagram for Ast:

Public Member Functions

 Ast ()
 
 Ast (class Ast *parentarg, operatortypes_e operatortypearg)
 create abstract syntax tree object More...
 
 Ast (class Ast *parentarg, std::string &operandarg)
 create abstract syntax tree object More...
 
 Ast (const Ast &orig)
 
Astoperator= (const Ast &orig)
 
void cp (const Ast &orig)
 deep copy of Ast More...
 
virtual ~Ast ()
 
bool evaluate (class Ast **nextAstNode, class Statement *statementPtr)
 
void evaluateAssignment (std::vector< fieldValue_s > &fieldValues, class Statement *statementPtr)
 
void normalizeSetAssignmentOperand (vector< fieldValue_s > &fieldValues, class Statement *statementPtr)
 convert More...
 

Static Public Member Functions

static void toFloat (const string &inoperand, fieldValue_s &outField)
 
static void toFloat (const string &inoperand, string &outoperand)
 

Public Attributes

class Astparent
 
class Astrightchild
 
class Astleftchild
 
bool isoperator
 
operatortypes_e operatortype
 
std::string operand
 
boost::unordered_map
< uuRecord_s, returnRow_s
predicateResults
 

Detailed Description

Abstract Syntax Tree.

Definition at line 51 of file Asts.h.

Constructor & Destructor Documentation

Ast::Ast ( )

Definition at line 35 of file Asts.cc.

36 {
37 }
Ast::Ast ( class Ast parentarg,
operatortypes_e  operatortypearg 
)

create abstract syntax tree object

Parameters
parentargparent Ast (NULL if root)
operatortypeargoperator type

Definition at line 39 of file Asts.cc.

References leftchild, OPERATOR_EXISTS, OPERATOR_FALSE, OPERATOR_IN, OPERATOR_ISNOTNULL, OPERATOR_ISNULL, OPERATOR_NEGATION, OPERATOR_NOT, OPERATOR_NOTIN, OPERATOR_TRUE, OPERATOR_UNIQUE, OPERATOR_UNKNOWN, and operatortype.

40  :
41  parent(parentarg), rightchild(NULL), leftchild(NULL), isoperator(true),
42  operatortype(operatortypearg)
43 {
44  // for unary operators, make left appear populated already
51  {
52  leftchild = this;
53  }
54 }
Ast::Ast ( class Ast parentarg,
std::string &  operandarg 
)

create abstract syntax tree object

Parameters
parentargparent Ast (NULL if root)
operandargoperand

Definition at line 56 of file Asts.cc.

56  : parent(parentarg),
57  rightchild(NULL), leftchild(NULL),
58  isoperator(false),
59  operand(operandarg)
60 {
61 }
Ast::Ast ( const Ast orig)

Definition at line 63 of file Asts.cc.

References cp().

64 {
65  cp(orig);
66 }

Here is the call graph for this function:

Ast::~Ast ( )
virtual

Definition at line 103 of file Asts.cc.

References isoperator, leftchild, and rightchild.

104 {
105  if (isoperator==true)
106  {
107  if (leftchild != NULL)
108  {
109  if (leftchild != this)
110  {
111  delete leftchild;
112  }
113  }
114 
115  if (rightchild != NULL)
116  {
117  delete rightchild;
118  }
119  }
120 }

Member Function Documentation

void Ast::cp ( const Ast orig)

deep copy of Ast

Parameters
origsource Ast

Definition at line 74 of file Asts.cc.

References isoperator, leftchild, operand, operatortype, parent, predicateResults, and rightchild.

Referenced by Ast(), and operator=().

75 {
76  parent = orig.parent;
77  isoperator = orig.isoperator;
79  operand = orig.operand;
81 
82  if (orig.leftchild != NULL)
83  {
84  leftchild = new class Ast;
85  *leftchild = *orig.leftchild;
86  }
87  else
88  {
89  leftchild=NULL;
90  }
91 
92  if (orig.rightchild != NULL)
93  {
94  rightchild = new class Ast;
95  *rightchild = *orig.rightchild;
96  }
97  else
98  {
99  rightchild=NULL;
100  }
101 }

Here is the caller graph for this function:

bool Ast::evaluate ( class Ast **  nextAstNode,
class Statement statementPtr 
)

evaluate Ast as part of continuation. returns the next Ast node to evaluate in 1st param, or NULL if finished. if both children (left only for unary operator) are not operators then return false so caller resolves it. Evaluate each child, convert self to resulting operand, return true

Parameters
nextAstNodenext Ast node to evaluate by subsequent call
statementPtrcurrent Ast node to evaluate
Returns

Definition at line 122 of file Asts.cc.

References Statement::andPredicate(), BOOL, fieldInput_u::boolean, CHAR, fieldInput_u::character, CHARX, Statement::currentQuery, Statement::inobject_s::expressionlist, FLOAT, Statement::query_s::inobject, INT, fieldInput_u::integer, Statement::results_s::inValues, fieldValue_s::isnull, isoperator, rowOrField_s::isrow, Statement::inobject_s::issubquery, leftchild, Statement::query_s::locktype, operand, OPERAND_FLOAT, OPERAND_INTEGER, OPERAND_NULL, OPERAND_PARAMETER, OPERAND_STRING, OPERAND_SUBQUERY, OPERATOR_ADDITION, OPERATOR_AND, OPERATOR_BETWEEN, OPERATOR_BETWEENAND, OPERATOR_CONCATENATION, OPERATOR_DIVISION, OPERATOR_EQ, OPERATOR_EXISTS, OPERATOR_FALSE, OPERATOR_GT, OPERATOR_GTE, OPERATOR_IN, OPERATOR_ISNOTNULL, OPERATOR_ISNULL, OPERATOR_LIKE, OPERATOR_LT, OPERATOR_LTE, OPERATOR_MULTIPLICATION, OPERATOR_NE, OPERATOR_NEGATION, OPERATOR_NOT, OPERATOR_NOTBETWEEN, OPERATOR_NOTIN, OPERATOR_NOTLIKE, OPERATOR_OR, OPERATOR_SUBTRACTION, OPERATOR_TRUE, OPERATOR_UNIQUE, OPERATOR_UNKNOWN, operatortype, Statement::parameters, parent, PAYLOADCOMMITROLLBACK, predicateResults, Statement::query_s::results, rightchild, MessageCommitRollback::rofs, ROLLBACKCMD, rowOrField_s::rowid, Statement::schemaPtr, Statement::searchExpression(), Transaction::sendTransaction(), Transaction::sqlPredicate(), Statement::stagedPredicate(), Transaction::stagedRows, fieldValue_s::str, Statement::subqueryExists(), Statement::subqueryIn(), Statement::subqueryScalar(), Statement::subqueryUnique(), Statement::query_s::tableid, rowOrField_s::tableid, Schema::tables, toFloat(), Statement::transactionPtr, UINT, fieldInput_u::uinteger, fieldValue_s::value, and VARCHAR.

Referenced by Statement::searchExpression().

123 {
124  if (isoperator==false)
125  {
126  if (operand[0]==OPERAND_PARAMETER)
127  {
128  int64_t paramnum;
129  memcpy(&paramnum, &operand[1], sizeof(paramnum));
130  operand = statementPtr->parameters[paramnum];
131  }
132 
133  *nextAstNode=parent;
134  return true;
135  }
136 
137  /* do left 1st, particularly for AND optimization */
138 
139  // unary operators ignore leftchild
146  {
147  if (leftchild->isoperator==true)
148  {
149  *nextAstNode=leftchild;
150  return false;
151  }
152 
154  {
155  int64_t paramnum;
156  memcpy(&paramnum, &leftchild->operand[1], sizeof(paramnum));
157  printf("%s %i paramnum %li\n", __FILE__, __LINE__, paramnum);
158  leftchild->operand = statementPtr->parameters[paramnum];
159  }
160  else if (leftchild->operand[0]==OPERAND_SUBQUERY)
161  {
162  statementPtr->subqueryScalar(this);
163  }
164  }
165 
166  if (rightchild->isoperator==true)
167  {
168  *nextAstNode=rightchild;
169  return false;
170  }
171 
173  {
174  int64_t paramnum;
175  memcpy(&paramnum, &rightchild->operand[1], sizeof(paramnum));
176  rightchild->operand = statementPtr->parameters[paramnum];
177  }
178  else if (rightchild->operand[0]==OPERAND_SUBQUERY)
179  {
180  statementPtr->subqueryScalar(this);
181  }
182 
183  // execute!
184  switch (operatortype)
185  {
187  {
188  if (leftchild->operand[0] != OPERAND_STRING ||
190  {
191  printf("%s %i bad operand %c\n", __FILE__, __LINE__, operand[0]);
192  return true;
193  }
194 
196  operand.append(leftchild->operand.substr(1, string::npos));
197  operand.append(rightchild->operand.substr(1, string::npos));
198  isoperator=false;
199  delete leftchild;
200  leftchild=NULL;
201  delete rightchild;
202  rightchild=NULL;
203  }
204  break;
205 
206  case OPERATOR_ADDITION:
207  if (leftchild->operand[0]==OPERAND_FLOAT ||
209  {
212  }
213 
214  switch (leftchild->operand[0])
215  {
216  case OPERAND_INTEGER:
217  {
219  {
220  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
222  return false;
223  }
224 
225  operand.resize(1+sizeof(int64_t), (char)0);
227  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) +
228  *(int64_t *)(rightchild->operand.c_str()+1);
229  memcpy(&operand[1], &val, sizeof(val));
230  isoperator=false;
231  }
232  break;
233 
234  case OPERAND_FLOAT:
235  {
236  if (rightchild->operand[0] != OPERAND_FLOAT)
237  {
238  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
240  return false;
241  }
242 
243  operand.resize(1+sizeof(long double), (char)0);
244  operand[0] = OPERAND_FLOAT;
245  int64_t val = *(long double *)(leftchild->operand.c_str()+1) +
246  *(long double *)(rightchild->operand.c_str()+1);
247  memcpy(&operand[1], &val, sizeof(val));
248  isoperator=false;
249  }
250  break;
251 
252  default:
253  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
254  leftchild->operand[0]);
255  return false;
256  }
257 
258  delete leftchild;
259  leftchild=NULL;
260  delete rightchild;
261  rightchild=NULL;
262  break;
263 
265  if (leftchild->operand[0]==OPERAND_FLOAT ||
267  {
270  }
271 
272  switch (leftchild->operand[0])
273  {
274  case OPERAND_INTEGER:
275  {
277  {
278  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
280  return false;
281  }
282 
283  operand.resize(1+sizeof(int64_t), (char)0);
285  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) -
286  *(int64_t *)(rightchild->operand.c_str()+1);
287  memcpy(&operand[1], &val, sizeof(val));
288  isoperator=false;
289  }
290  break;
291 
292  case OPERAND_FLOAT:
293  {
294  if (rightchild->operand[0] != OPERAND_FLOAT)
295  {
296  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
298  return false;
299  }
300 
301  operand.resize(1+sizeof(long double), (char)0);
302  operand[0] = OPERAND_FLOAT;
303  int64_t val = *(long double *)(leftchild->operand.c_str()+1) -
304  *(long double *)(rightchild->operand.c_str()+1);
305  memcpy(&operand[1], &val, sizeof(val));
306  isoperator=false;
307  }
308  break;
309 
310  default:
311  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
312  leftchild->operand[0]);
313  return false;
314  }
315 
316  delete leftchild;
317  leftchild=NULL;
318  delete rightchild;
319  rightchild=NULL;
320  break;
321 
323  if (leftchild->operand[0]==OPERAND_FLOAT ||
325  {
328  }
329 
330  switch (leftchild->operand[0])
331  {
332  case OPERAND_INTEGER:
333  {
335  {
336  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
338  return false;
339  }
340 
341  operand.resize(1+sizeof(int64_t), (char)0);
343  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) *
344  *(int64_t *)(rightchild->operand.c_str()+1);
345  memcpy(&operand[1], &val, sizeof(val));
346  isoperator=false;
347  }
348  break;
349 
350  case OPERAND_FLOAT:
351  {
352  if (rightchild->operand[0] != OPERAND_FLOAT)
353  {
354  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
356  return false;
357  }
358 
359  operand.resize(1+sizeof(long double), (char)0);
360  operand[0] = OPERAND_FLOAT;
361  int64_t val = *(long double *)(leftchild->operand.c_str()+1) *
362  *(long double *)(rightchild->operand.c_str()+1);
363  memcpy(&operand[1], &val, sizeof(val));
364  isoperator=false;
365  }
366  break;
367 
368  default:
369  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
370  leftchild->operand[0]);
371  return false;
372  }
373 
374  delete leftchild;
375  leftchild=NULL;
376  delete rightchild;
377  rightchild=NULL;
378  break;
379 
380  case OPERATOR_DIVISION:
381  if (leftchild->operand[0]==OPERAND_FLOAT ||
383  {
386  }
387 
388  switch (leftchild->operand[0])
389  {
390  case OPERAND_INTEGER:
391  {
393  {
394  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
396  return false;
397  }
398 
399  operand.resize(1+sizeof(int64_t), (char)0);
401  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) /
402  *(int64_t *)(rightchild->operand.c_str()+1);
403  memcpy(&operand[1], &val, sizeof(val));
404  isoperator=false;
405  }
406  break;
407 
408  case OPERAND_FLOAT:
409  {
410  if (rightchild->operand[0] != OPERAND_FLOAT)
411  {
412  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
414  return false;
415  }
416 
417  operand.resize(1+sizeof(long double), (char)0);
418  operand[0] = OPERAND_FLOAT;
419  int64_t val = *(long double *)(leftchild->operand.c_str()+1) /
420  *(long double *)(rightchild->operand.c_str()+1);
421  memcpy(&operand[1], &val, sizeof(val));
422  isoperator=false;
423  }
424  break;
425 
426  default:
427  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
428  leftchild->operand[0]);
429  return false;
430  }
431 
432  delete leftchild;
433  leftchild=NULL;
434  delete rightchild;
435  rightchild=NULL;
436  break;
437 
438  case OPERATOR_NEGATION:
440  {
442  }
443 
444  switch (rightchild->operand[0])
445  // switch (leftchild->operand[0])
446  {
447  case OPERAND_INTEGER:
448  {
450  {
451  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
453  return false;
454  }
455 
456  operand.resize(1+sizeof(int64_t), (char)0);
458  int64_t val = 0 - *(int64_t *)(rightchild->operand.c_str()+1);
459  memcpy(&operand[1], &val, sizeof(val));
460  isoperator=false;
461  }
462  break;
463 
464  case OPERAND_FLOAT:
465  {
466  if (rightchild->operand[0] != OPERAND_FLOAT)
467  {
468  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
470  return false;
471  }
472 
473  operand.resize(1+sizeof(long double), (char)0);
474  operand[0] = OPERAND_FLOAT;
475  int64_t val = 0 - *(long double *)(rightchild->operand.c_str()+1);
476  memcpy(&operand[1], &val, sizeof(val));
477  isoperator=false;
478  }
479  break;
480 
481  default:
482  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
483  leftchild->operand[0]);
484  return false;
485  }
486 
487  delete rightchild;
488  rightchild=NULL;
489  break;
490 
491  case OPERATOR_AND:
492  {
493  boost::unordered_map< int64_t, vector<int64_t> > enginerowids;
494 
495  boost::unordered_map<uuRecord_s, returnRow_s>::iterator it;
496 
497  for (it = leftchild->predicateResults.begin();
498  it != leftchild->predicateResults.end(); it++)
499  {
500  if (rightchild->predicateResults.count(it->first))
501  {
502  predicateResults[it->first] = it->second;
503  }
504  else
505  {
506  // unlock if it's not already staged in this transaction
507  if (!statementPtr->transactionPtr->stagedRows.count(it->first))
508  {
509  enginerowids[it->first.engineid].push_back(it->first.rowid);
510  }
511  }
512  }
513 
514  // send rollback messages
515  boost::unordered_map< int64_t, vector<int64_t> >::iterator it2;
516  rowOrField_s rowOrField = {};
517  rowOrField.isrow=true;
518  rowOrField.tableid=statementPtr->currentQuery->tableid;
519 
520  for (it2 = enginerowids.begin(); it2 != enginerowids.end(); it2++)
521  {
522  class MessageCommitRollback *msg = new class MessageCommitRollback();
523 
524  for (size_t n=0; n < it2->second.size(); n++)
525  {
526  rowOrField.rowid=it2->second[n];
527  msg->rofs.push_back(rowOrField);
528  }
529 
530  statementPtr->transactionPtr->sendTransaction(ROLLBACKCMD,
532  0, it2->first, msg);
533  }
534 
535  isoperator=false;
536  printf("%s %i this %p deleting leftchild %p rightchild %p\n", __FILE__,
537  __LINE__, this, leftchild, rightchild);
538  delete leftchild;
539  leftchild=NULL;
540  delete rightchild;
541  rightchild=NULL;
542  }
543  break;
544 
545  case OPERATOR_OR:
549  isoperator=false;
550  delete leftchild;
551  leftchild=NULL;
552  delete rightchild;
553  rightchild=NULL;
554  break;
555 
556  case OPERATOR_NOT:
557  /* NOT requires a call to retrieve all rows NOT in the
558  * operand's result set */
559  printf("%s %i operator %i not implemented.\n", __FILE__, __LINE__,
560  operatortype);
561  isoperator=false;
562  delete rightchild;
563  rightchild=NULL;
564  return false;
565 // break;
566 
567  case OPERATOR_TRUE:
568  /* IS TRUE is gratuitous*/
569  printf("%s %i operator %i not implemented.\n", __FILE__, __LINE__,
570  operatortype);
571  isoperator=false;
572  delete rightchild;
573  rightchild=NULL;
574  return false;
575 // break;
576 
577  case OPERATOR_FALSE:
578  /* IS FALSE requires a call to retrieve all rows like NOT, and
579  * all NOT NULL */
580  printf("%s %i operator %i not implemented.\n", __FILE__, __LINE__,
581  operatortype);
582  isoperator=false;
583  delete rightchild;
584  rightchild=NULL;
585  return false;
586 // break;
587 
588  case OPERATOR_UNKNOWN:
589  /* IS UNKNOWN is a variation on ISNULL predicates */
590  printf("%s %i operator %i not implemented.\n", __FILE__, __LINE__,
591  operatortype);
592  isoperator=false;
593  delete rightchild;
594  rightchild=NULL;
595  return false;
596 // break;
597 
598  case OPERATOR_EQ:
599  isoperator=false;
600 
601  if (statementPtr->stagedPredicate(operatortype,
602  statementPtr->currentQuery->tableid,
605  statementPtr->currentQuery->results.inValues,
606  statementPtr->transactionPtr->stagedRows,
607  predicateResults)==false)
608  {
609  /*
610  * if (parent != NULL && parent->operatortype==OPERATOR_AND &&
611  * this==parent->rightchild)
612  */
613  if (0) // revert this back when andPredicate is tested
614  {
615  statementPtr->andPredicate(operatortype,
616  statementPtr->currentQuery->tableid,
619  statementPtr->currentQuery->results.inValues,
621  delete leftchild;
622  leftchild=NULL;
623  delete rightchild;
624  rightchild=NULL;
625  }
626  else
627  {
628  statementPtr->transactionPtr->sqlPredicate(statementPtr,
629  operatortype,
630  statementPtr->currentQuery->tableid,
633  statementPtr->currentQuery->locktype,
634  statementPtr->currentQuery->results.inValues,
635  this,
637  *nextAstNode = NULL;
638  delete leftchild;
639  leftchild=NULL;
640  delete rightchild;
641  rightchild=NULL;
642  return false;
643  }
644  }
645  else
646  {
647  delete leftchild;
648  leftchild=NULL;
649  delete rightchild;
650  rightchild=NULL;
651  }
652  break;
653 
654  case OPERATOR_NE:
655  statementPtr->stagedPredicate(operatortype,
656  statementPtr->currentQuery->tableid,
659  statementPtr->currentQuery->results.inValues,
660  statementPtr->transactionPtr->stagedRows,
662 
663  isoperator=false;
664 
665  /*
666  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
667  this==parent->rightchild)
668  */
669  if (0) // revert this back when andPredicate is tested
670  {
671  statementPtr->andPredicate(operatortype,
672  statementPtr->currentQuery->tableid,
674  statementPtr->currentQuery->results.inValues,
676  delete leftchild;
677  leftchild=NULL;
678  delete rightchild;
679  rightchild=NULL;
680  }
681  else
682  {
683  statementPtr->transactionPtr->sqlPredicate(statementPtr,
684  operatortype,
685  statementPtr->currentQuery->tableid,
688  statementPtr->currentQuery->locktype,
689  statementPtr->currentQuery->results.inValues,
690  this, predicateResults);
691  *nextAstNode = NULL;
692  delete leftchild;
693  leftchild=NULL;
694  delete rightchild;
695  rightchild=NULL;
696  return false;
697  }
698 
699  break;
700 
701  case OPERATOR_LT:
702  statementPtr->stagedPredicate(operatortype,
703  statementPtr->currentQuery->tableid,
706  statementPtr->currentQuery->results.inValues,
707  statementPtr->transactionPtr->stagedRows,
709 
710  isoperator=false;
711 
712  /*
713  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
714  this==parent->rightchild)
715  */
716  if (0) // revert this back when andPredicate is tested
717  {
718  statementPtr->andPredicate(operatortype,
719  statementPtr->currentQuery->tableid,
721  statementPtr->currentQuery->results.inValues,
723  delete leftchild;
724  leftchild=NULL;
725  delete rightchild;
726  rightchild=NULL;
727  }
728  else
729  {
730  statementPtr->transactionPtr->sqlPredicate(statementPtr,
731  operatortype,
732  statementPtr->currentQuery->tableid,
735  statementPtr->currentQuery->locktype,
736  statementPtr->currentQuery->results.inValues,
737  this, predicateResults);
738  *nextAstNode = NULL;
739  delete leftchild;
740  leftchild=NULL;
741  delete rightchild;
742  rightchild=NULL;
743  return false;
744  }
745 
746  break;
747 
748  case OPERATOR_GT:
749  statementPtr->stagedPredicate(operatortype,
750  statementPtr->currentQuery->tableid,
753  statementPtr->currentQuery->results.inValues,
754  statementPtr->transactionPtr->stagedRows,
756 
757  isoperator=false;
758 
759  /*
760  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
761  this==parent->rightchild)
762  */
763  if (0) // revert this back when andPredicate is tested
764  {
765  statementPtr->andPredicate(operatortype,
766  statementPtr->currentQuery->tableid,
768  statementPtr->currentQuery->results.inValues,
771  delete leftchild;
772  leftchild=NULL;
773  delete rightchild;
774  rightchild=NULL;
775  }
776  else
777  {
778  statementPtr->transactionPtr->sqlPredicate(statementPtr,
779  operatortype,
780  statementPtr->currentQuery->tableid,
783  statementPtr->currentQuery->locktype,
784  statementPtr->currentQuery->results.inValues,
785  this, predicateResults);
786  *nextAstNode = NULL;
787  delete leftchild;
788  leftchild=NULL;
789  delete rightchild;
790  rightchild=NULL;
791  return false;
792  }
793 
794  break;
795 
796  case OPERATOR_LTE:
797  statementPtr->stagedPredicate(operatortype,
798  statementPtr->currentQuery->tableid,
801  statementPtr->currentQuery->results.inValues,
802  statementPtr->transactionPtr->stagedRows,
804 
805  isoperator=false;
806 
807  /*
808  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
809  this==parent->rightchild)
810  */
811  if (0) // revert this back when andPredicate is tested
812  {
813  statementPtr->andPredicate(operatortype,
814  statementPtr->currentQuery->tableid,
816  statementPtr->currentQuery->results.inValues,
818  delete leftchild;
819  leftchild=NULL;
820  delete rightchild;
821  rightchild=NULL;
822  }
823  else
824  {
825  statementPtr->transactionPtr->sqlPredicate(statementPtr,
826  operatortype,
827  statementPtr->currentQuery->tableid,
830  statementPtr->currentQuery->locktype,
831  statementPtr->currentQuery->results.inValues,
832  this, predicateResults);
833  *nextAstNode = NULL;
834  delete leftchild;
835  leftchild=NULL;
836  delete rightchild;
837  rightchild=NULL;
838  return false;
839  }
840 
841  break;
842 
843  case OPERATOR_GTE:
844  statementPtr->stagedPredicate(operatortype,
845  statementPtr->currentQuery->tableid,
847  statementPtr->currentQuery->results.inValues,
848  statementPtr->transactionPtr->stagedRows,
850 
851  isoperator=false;
852 
853  /*
854  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
855  this==parent->rightchild)
856  */
857  if (0) // revert this back when andPredicate is tested
858  {
859  statementPtr->andPredicate(operatortype,
860  statementPtr->currentQuery->tableid,
862  statementPtr->currentQuery->results.inValues,
864  delete leftchild;
865  leftchild=NULL;
866  delete rightchild;
867  rightchild=NULL;
868  }
869  else
870  {
871  statementPtr->transactionPtr->sqlPredicate(statementPtr,
872  operatortype,
873  statementPtr->currentQuery->tableid,
876  statementPtr->currentQuery->locktype,
877  statementPtr->currentQuery->results.inValues,
878  this, predicateResults);
879  *nextAstNode = NULL;
880  delete leftchild;
881  leftchild=NULL;
882  delete rightchild;
883  rightchild=NULL;
884  return false;
885  }
886 
887  break;
888 
889  case OPERATOR_BETWEEN:
890  statementPtr->stagedPredicate(operatortype,
891  statementPtr->currentQuery->tableid,
894  statementPtr->currentQuery->results.inValues,
895  statementPtr->transactionPtr->stagedRows,
897 
898  isoperator=false;
899 
900  /*
901  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
902  this==parent->rightchild)
903  */
904  if (0) // revert this back when andPredicate is tested
905  {
906  statementPtr->andPredicate(operatortype,
907  statementPtr->currentQuery->tableid,
909  statementPtr->currentQuery->results.inValues,
912  delete leftchild;
913  leftchild=NULL;
914  delete rightchild;
915  rightchild=NULL;
916  }
917  else
918  {
919  statementPtr->transactionPtr->sqlPredicate(statementPtr,
920  operatortype,
921  statementPtr->currentQuery->tableid,
924  statementPtr->currentQuery->locktype,
925  statementPtr->currentQuery->results.inValues,
926  this, predicateResults);
927  *nextAstNode = NULL;
928  delete leftchild;
929  leftchild=NULL;
930  delete rightchild;
931  rightchild=NULL;
932  return false;
933  }
934 
935  break;
936 
937  case OPERATOR_NOTBETWEEN:
938  statementPtr->stagedPredicate(operatortype,
939  statementPtr->currentQuery->tableid,
942  statementPtr->currentQuery->results.inValues,
943  statementPtr->transactionPtr->stagedRows,
945 
946  isoperator=false;
947 
948  /*
949  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
950  this==parent->rightchild)
951  */
952  if (0) // revert this back when andPredicate is tested
953  {
954  statementPtr->andPredicate(operatortype,
955  statementPtr->currentQuery->tableid,
957  statementPtr->currentQuery->results.inValues,
960  delete leftchild;
961  leftchild=NULL;
962  delete rightchild;
963  rightchild=NULL;
964  }
965  else
966  {
967  statementPtr->transactionPtr->sqlPredicate(statementPtr,
968  operatortype,
969  statementPtr->currentQuery->tableid,
972  statementPtr->currentQuery->locktype,
973  statementPtr->currentQuery->results.inValues,
974  this, predicateResults);
975  *nextAstNode = NULL;
976  delete leftchild;
977  leftchild=NULL;
978  delete rightchild;
979  rightchild=NULL;
980  return false;
981  }
982 
983  break;
984 
985  case OPERATOR_ISNULL: // unary operator
986  statementPtr->stagedPredicate(operatortype,
987  statementPtr->currentQuery->tableid,
990  statementPtr->currentQuery->results.inValues,
991  statementPtr->transactionPtr->stagedRows,
993 
994  isoperator=false;
995 
996  /*
997  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
998  this==parent->rightchild)
999  */
1000  if (0) // revert this back when andPredicate is tested
1001  {
1002  statementPtr->andPredicate(operatortype,
1003  statementPtr->currentQuery->tableid,
1005  statementPtr->currentQuery->results.inValues,
1007  delete rightchild;
1008  rightchild=NULL;
1009  }
1010  else
1011  {
1012  statementPtr->transactionPtr->sqlPredicate(statementPtr,
1013  operatortype,
1014  statementPtr->currentQuery->tableid,
1017  statementPtr->currentQuery->locktype,
1018  statementPtr->currentQuery->results.inValues,
1019  this, predicateResults);
1020  *nextAstNode = NULL;
1021  delete rightchild;
1022  rightchild=NULL;
1023  return false;
1024  }
1025 
1026  break;
1027 
1028  case OPERATOR_ISNOTNULL: // unary operator
1029  statementPtr->stagedPredicate(operatortype,
1030  statementPtr->currentQuery->tableid,
1031  leftchild->operand,
1033  statementPtr->currentQuery->results.inValues,
1034  statementPtr->transactionPtr->stagedRows,
1036 
1037  isoperator=false;
1038 
1039  /*
1040  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
1041  this==parent->rightchild)
1042  */
1043  if (0) // revert this back when andPredicate is tested
1044  {
1045  statementPtr->andPredicate(operatortype,
1046  statementPtr->currentQuery->tableid,
1048  statementPtr->currentQuery->results.inValues,
1050  delete rightchild;
1051  rightchild=NULL;
1052  }
1053  else
1054  {
1055  statementPtr->transactionPtr->sqlPredicate(statementPtr,
1056  operatortype,
1057  statementPtr->currentQuery->tableid,
1060  statementPtr->currentQuery->locktype,
1061  statementPtr->currentQuery->results.inValues,
1062  this, predicateResults);
1063  *nextAstNode = NULL;
1064  delete rightchild;
1065  rightchild=NULL;
1066  return false;
1067  }
1068 
1069  break;
1070 
1071  case OPERATOR_IN: // unary operator
1072  statementPtr->stagedPredicate(operatortype,
1073  statementPtr->currentQuery->tableid,
1074  leftchild->operand,
1076  statementPtr->currentQuery->results.inValues,
1077  statementPtr->transactionPtr->stagedRows,
1079 
1080  isoperator=false;
1081 
1082  // resolve inobject
1083  if (statementPtr->currentQuery->inobject.issubquery==true)
1084  {
1085  statementPtr->subqueryIn(this);
1086  }
1087  else
1088  {
1089  // fieldid is in the rightoperand, then get type
1090  int64_t fieldid;
1091  memcpy(&fieldid, &rightchild->operand[1], sizeof(fieldid));
1092  fieldtype_e fieldtype = statementPtr->schemaPtr->tables[statementPtr->currentQuery->tableid]->fields[fieldid].type;
1093 
1094  for (size_t n=0;
1095  n < statementPtr->currentQuery->inobject.expressionlist.size();
1096  n++)
1097  {
1098  fieldValue_s fieldValue = {};
1099  class Ast &astRef =
1100  *statementPtr->currentQuery->inobject.expressionlist[n];
1101  statementPtr->searchExpression(0, &astRef);
1102 
1103  if (astRef.operand[0]==OPERAND_NULL)
1104  {
1105  fieldValue.isnull=true;
1106  }
1107  else
1108  {
1109  switch (fieldtype)
1110  {
1111  case INT:
1112  memcpy(&fieldValue.value.integer, &astRef.operand[1],
1113  sizeof(int64_t));
1114  break;
1115 
1116  case UINT:
1117  memcpy(&fieldValue.value.uinteger, &astRef.operand[1],
1118  sizeof(int64_t));
1119  break;
1120 
1121  case BOOL:
1122  {
1123  int64_t torf;
1124  memcpy(&torf, &astRef.operand[1], sizeof(torf));
1125  fieldValue.value.boolean = (bool)torf;
1126  }
1127  break;
1128 
1129  case FLOAT:
1130  toFloat(astRef.operand, fieldValue);
1131  /*
1132  memcpy(&fieldValue.value.floating, &astRef.operand[1],
1133  sizeof(long double));
1134  */
1135  break;
1136 
1137  case CHAR:
1138  fieldValue.value.character = astRef.operand[1];
1139  break;
1140 
1141  case CHARX:
1142  fieldValue.str = astRef.operand.substr(1, string::npos);
1143  break;
1144 
1145  case VARCHAR:
1146  fieldValue.str = astRef.operand.substr(1, string::npos);
1147  break;
1148 
1149  default:
1150  printf("%s %i anomaly %i\n", __FILE__, __LINE__,
1151  fieldtype);
1152  }
1153  }
1154 
1155  statementPtr->currentQuery->results.inValues.push_back(fieldValue);
1156  delete &astRef;
1157  }
1158 
1159  statementPtr->currentQuery->inobject.expressionlist.clear();
1160  }
1161 
1162  /*
1163  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
1164  this==parent->rightchild)
1165  */
1166  if (0) // revert this back when andPredicate is tested
1167  {
1168  statementPtr->andPredicate(operatortype,
1169  statementPtr->currentQuery->tableid,
1171  statementPtr->currentQuery->results.inValues,
1174  delete rightchild;
1175  rightchild=NULL;
1176  }
1177  else
1178  {
1179  statementPtr->transactionPtr->sqlPredicate(statementPtr,
1180  operatortype,
1181  statementPtr->currentQuery->tableid,
1184  statementPtr->currentQuery->locktype,
1185  statementPtr->currentQuery->results.inValues,
1186  this, predicateResults);
1187  *nextAstNode = NULL;
1188  delete rightchild;
1189  rightchild=NULL;
1190  return false;
1191  }
1192 
1193  break;
1194 
1195  case OPERATOR_NOTIN: // unary operator
1196  statementPtr->stagedPredicate(operatortype,
1197  statementPtr->currentQuery->tableid,
1198  leftchild->operand,
1200  statementPtr->currentQuery->results.inValues,
1201  statementPtr->transactionPtr->stagedRows,
1203 
1204  isoperator=false;
1205 
1206  // resolve inobject
1207  if (statementPtr->currentQuery->inobject.issubquery==true)
1208  {
1209  statementPtr->subqueryIn(this);
1210  }
1211  else
1212  {
1213  // fieldid is in the rightoperand, then get type
1214  int64_t fieldid;
1215  memcpy(&fieldid, &rightchild->operand[1], sizeof(fieldid));
1216  fieldtype_e fieldtype =
1217  statementPtr->schemaPtr->tables[statementPtr->currentQuery->tableid]->fields[fieldid].type;
1218 
1219  for (size_t n=0;
1220  n < statementPtr->currentQuery->inobject.expressionlist.size();
1221  n++)
1222  {
1223  fieldValue_s fieldValue = {};
1224  class Ast &astRef =
1225  *statementPtr->currentQuery->inobject.expressionlist[n];
1226  statementPtr->searchExpression(0, &astRef);
1227 
1228  if (astRef.operand[0]==OPERAND_NULL)
1229  {
1230  fieldValue.isnull=true;
1231  }
1232  else
1233  {
1234  switch (fieldtype)
1235  {
1236  case INT:
1237  memcpy(&fieldValue.value.integer, &astRef.operand[1],
1238  sizeof(int64_t));
1239  break;
1240 
1241  case UINT:
1242  memcpy(&fieldValue.value.uinteger, &astRef.operand[1],
1243  sizeof(int64_t));
1244  break;
1245 
1246  case BOOL:
1247  {
1248  int64_t torf;
1249  memcpy(&torf, &astRef.operand[1], sizeof(torf));
1250  fieldValue.value.boolean = (bool)torf;
1251  }
1252  break;
1253 
1254  case FLOAT:
1255  toFloat(astRef.operand, fieldValue);
1256  break;
1257 
1258  case CHAR:
1259  fieldValue.value.character = astRef.operand[1];
1260  break;
1261 
1262  case CHARX:
1263  fieldValue.str = astRef.operand.substr(1, string::npos);
1264  break;
1265 
1266  case VARCHAR:
1267  fieldValue.str = astRef.operand.substr(1, string::npos);
1268  break;
1269 
1270  default:
1271  printf("%s %i anomaly %i\n", __FILE__, __LINE__,
1272  fieldtype);
1273  }
1274  }
1275 
1276  statementPtr->currentQuery->results.inValues.push_back(fieldValue);
1277  delete &astRef;
1278  }
1279 
1280  statementPtr->currentQuery->inobject.expressionlist.clear();
1281  }
1282 
1283  if (0) // revert this back when andPredicate is tested
1284  {
1285  statementPtr->andPredicate(operatortype,
1286  statementPtr->currentQuery->tableid,
1288  statementPtr->currentQuery->results.inValues,
1291  delete rightchild;
1292  rightchild=NULL;
1293  }
1294  else
1295  {
1296  statementPtr->transactionPtr->sqlPredicate(statementPtr,
1297  operatortype,
1298  statementPtr->currentQuery->tableid,
1301  statementPtr->currentQuery->locktype,
1302  statementPtr->currentQuery->results.inValues,
1303  this, predicateResults);
1304  *nextAstNode = NULL;
1305  delete rightchild;
1306  rightchild=NULL;
1307  return false;
1308  }
1309 
1310  break;
1311 
1312  case OPERATOR_LIKE:
1313  statementPtr->stagedPredicate(operatortype,
1314  statementPtr->currentQuery->tableid,
1315  leftchild->operand,
1317  statementPtr->currentQuery->results.inValues,
1318  statementPtr->transactionPtr->stagedRows,
1320 
1321  isoperator=false;
1322 
1323  if (0) // revert this back when andPredicate is tested
1324  {
1325  statementPtr->andPredicate(operatortype,
1326  statementPtr->currentQuery->tableid,
1327  leftchild->operand,
1329  statementPtr->currentQuery->results.inValues,
1332  delete leftchild;
1333  leftchild=NULL;
1334  delete rightchild;
1335  rightchild=NULL;
1336  }
1337  else
1338  {
1339  string str=rightchild->operand.substr(1, string::npos);
1340  statementPtr->transactionPtr->sqlPredicate(statementPtr,
1341  operatortype,
1342  statementPtr->currentQuery->tableid,
1343  leftchild->operand,
1345  statementPtr->currentQuery->locktype,
1346  statementPtr->currentQuery->results.inValues,
1347  this, predicateResults);
1348  *nextAstNode = NULL;
1349  delete leftchild;
1350  leftchild=NULL;
1351  delete rightchild;
1352  rightchild=NULL;
1353  return false;
1354  }
1355 
1356  break;
1357 
1358  case OPERATOR_NOTLIKE:
1359  statementPtr->stagedPredicate(operatortype,
1360  statementPtr->currentQuery->tableid,
1361  leftchild->operand,
1363  statementPtr->currentQuery->results.inValues,
1364  statementPtr->transactionPtr->stagedRows,
1366 
1367  isoperator=false;
1368 
1369  /*
1370  if (parent != NULL && parent->operatortype==OPERATOR_AND &&
1371  this==parent->rightchild)
1372  */
1373  if (0) // revert this back when andPredicate is tested
1374  {
1375  statementPtr->andPredicate(operatortype,
1376  statementPtr->currentQuery->tableid,
1378  statementPtr->currentQuery->results.inValues,
1381  delete leftchild;
1382  leftchild=NULL;
1383  delete rightchild;
1384  rightchild=NULL;
1385  }
1386  else
1387  {
1388  statementPtr->transactionPtr->sqlPredicate(statementPtr,
1389  operatortype,
1390  statementPtr->currentQuery->tableid,
1391  leftchild->operand,
1393  statementPtr->currentQuery->locktype,
1394  statementPtr->currentQuery->results.inValues,
1395  this, predicateResults);
1396  *nextAstNode = NULL;
1397  delete leftchild;
1398  leftchild=NULL;
1399  delete rightchild;
1400  rightchild=NULL;
1401  return false;
1402  }
1403 
1404  break;
1405 
1406  case OPERATOR_EXISTS: // unary operator
1407  {
1408  // need to process subqueries first
1409  statementPtr->stagedPredicate(operatortype,
1410  statementPtr->currentQuery->tableid,
1411  leftchild->operand,
1413  statementPtr->currentQuery->results.inValues,
1414  statementPtr->transactionPtr->stagedRows,
1416 
1417  statementPtr->subqueryExists(this);
1418  delete rightchild;
1419  rightchild=NULL;
1420  }
1421  break;
1422 
1423  case OPERATOR_UNIQUE: // unary operator
1424  {
1425  //need to process subqueries first
1426  statementPtr->stagedPredicate(operatortype,
1427  statementPtr->currentQuery->tableid,
1428  leftchild->operand,
1430  statementPtr->currentQuery->results.inValues,
1431  statementPtr->transactionPtr->stagedRows,
1433 
1434  statementPtr->subqueryUnique(this);
1435  delete rightchild;
1436  rightchild=NULL;
1437  }
1438  break;
1439 
1440  case OPERATOR_BETWEENAND:
1441  switch (leftchild->operand[0])
1442  {
1443  case OPERAND_INTEGER:
1444  {
1445  if (rightchild->operand[0] != OPERAND_INTEGER)
1446  {
1447  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1448  leftchild->operand[0], rightchild->operand[0]);
1449  return false;
1450  }
1451 
1452  operand.resize(1+2*sizeof(int64_t), (char)0);
1453  operand[0] = OPERAND_INTEGER;
1454  memcpy(&operand[1], &leftchild->operand[1], sizeof(int64_t));
1455  memcpy(&operand[1+sizeof(int64_t)], &rightchild->operand[1],
1456  sizeof(int64_t));
1457  isoperator=false;
1458  }
1459  break;
1460 
1461  case OPERAND_FLOAT:
1462  {
1463  if (rightchild->operand[0] != OPERAND_FLOAT)
1464  {
1465  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1466  leftchild->operand[0], rightchild->operand[0]);
1467  return false;
1468  }
1469 
1470  operand.resize(1+2*sizeof(long double), (char)0);
1471  operand[0] = OPERAND_FLOAT;
1472  memcpy(&operand[1], &leftchild->operand[1], sizeof(long double));
1473  memcpy(&operand[1+sizeof(long double)], &rightchild->operand[1],
1474  sizeof(long double));
1475  isoperator=false;
1476  }
1477  break;
1478 
1479  case OPERAND_STRING:
1480  {
1481  if (rightchild->operand[0] != OPERAND_STRING)
1482  {
1483  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1484  leftchild->operand[0], rightchild->operand[0]);
1485  return false;
1486  }
1487 
1488  operand.resize(1+sizeof(size_t)+(leftchild->operand.size()-1) +
1489  (rightchild->operand.size()-1), (char)0);
1490  operand[0] = OPERAND_STRING;
1491  size_t len = leftchild->operand.size()-1;
1492  memcpy(&operand[1], &len, sizeof(len));
1493  memcpy(&operand[1+sizeof(len)], &leftchild->operand[1], len);
1494  memcpy(&operand[1+sizeof(len)+len], &rightchild->operand[1],
1495  rightchild->operand.size()-1);
1496  isoperator=false;
1497  }
1498  break;
1499 
1500  default:
1501  printf("%s %i bad type %c\n", __FILE__, __LINE__,
1502  leftchild->operand[0]);
1503  return false;
1504  }
1505 
1506  delete leftchild;
1507  leftchild=NULL;
1508  delete rightchild;
1509  rightchild=NULL;
1510  break;
1511 
1512  default:
1513  printf("%s %i anomaly %i\n", __FILE__, __LINE__, operatortype);
1514  }
1515 
1516  *nextAstNode = parent;
1517  return true;
1518 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Ast::evaluateAssignment ( std::vector< fieldValue_s > &  fieldValues,
class Statement statementPtr 
)

evaluate assignments in UPDATE queries

Parameters
fieldValueslist of values to set each row to
statementPtrassociated statement

Definition at line 1521 of file Asts.cc.

References evaluateAssignment(), isoperator, leftchild, normalizeSetAssignmentOperand(), operand, OPERAND_FLOAT, OPERAND_INTEGER, OPERAND_STRING, OPERATOR_ADDITION, OPERATOR_CONCATENATION, OPERATOR_DIVISION, OPERATOR_MULTIPLICATION, OPERATOR_NEGATION, OPERATOR_SUBTRACTION, operatortype, rightchild, and toFloat().

Referenced by evaluateAssignment().

1523 {
1524  if (isoperator==false)
1525  {
1526  normalizeSetAssignmentOperand(fieldValues, statementPtr);
1527  return;
1528  }
1529 
1530  if (operatortype != OPERATOR_NEGATION) // not unary operator
1531  {
1532  leftchild->evaluateAssignment(fieldValues, statementPtr);
1533  }
1534 
1535  rightchild->evaluateAssignment(fieldValues, statementPtr);
1536 
1537  switch (operatortype)
1538  {
1540  {
1541  if (leftchild->operand[0] != OPERAND_STRING ||
1543  {
1544  printf("%s %i bad operand %c\n", __FILE__, __LINE__, operand[0]);
1545  return;
1546  }
1547 
1549  operand.append(leftchild->operand.substr(1, string::npos));
1550  operand.append(rightchild->operand.substr(1, string::npos));
1551  isoperator=false;
1552  delete leftchild;
1553  leftchild=NULL;
1554  delete rightchild;
1555  rightchild=NULL;
1556  }
1557  break;
1558 
1559  case OPERATOR_ADDITION:
1560  if (leftchild->operand[0]==OPERAND_FLOAT ||
1562  {
1565  }
1566 
1567  switch (leftchild->operand[0])
1568  {
1569  case OPERAND_INTEGER:
1570  {
1571  if (rightchild->operand[0] != OPERAND_INTEGER)
1572  {
1573  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1574  leftchild->operand[0], rightchild->operand[0]);
1575  return;
1576  }
1577 
1578  operand.resize(1+sizeof(int64_t), (char)0);
1579  operand[0] = OPERAND_INTEGER;
1580  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) +
1581  *(int64_t *)(rightchild->operand.c_str()+1);
1582  memcpy(&operand[1], &val, sizeof(val));
1583  isoperator=false;
1584  }
1585  break;
1586 
1587  case OPERAND_FLOAT:
1588  {
1589  if (rightchild->operand[0] != OPERAND_FLOAT)
1590  {
1591  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1592  leftchild->operand[0], rightchild->operand[0]);
1593  return;
1594  }
1595 
1596  operand.resize(1+sizeof(long double), (char)0);
1597  operand[0] = OPERAND_FLOAT;
1598  int64_t val = *(long double *)(leftchild->operand.c_str()+1) +
1599  *(long double *)(rightchild->operand.c_str()+1);
1600  memcpy(&operand[1], &val, sizeof(val));
1601  isoperator=false;
1602  }
1603  break;
1604 
1605  default:
1606  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
1607  leftchild->operand[0]);
1608  return;
1609  }
1610 
1611  delete leftchild;
1612  leftchild=NULL;
1613  delete rightchild;
1614  rightchild=NULL;
1615  break;
1616 
1617  case OPERATOR_SUBTRACTION:
1618  if (leftchild->operand[0]==OPERAND_FLOAT ||
1620  {
1623  }
1624 
1625  switch (leftchild->operand[0])
1626  {
1627  case OPERAND_INTEGER:
1628  {
1629  if (rightchild->operand[0] != OPERAND_INTEGER)
1630  {
1631  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1632  leftchild->operand[0], rightchild->operand[0]);
1633  return;
1634  }
1635 
1636  operand.resize(1+sizeof(int64_t), (char)0);
1637  operand[0] = OPERAND_INTEGER;
1638  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) -
1639  *(int64_t *)(rightchild->operand.c_str()+1);
1640  memcpy(&operand[1], &val, sizeof(val));
1641  isoperator=false;
1642  }
1643  break;
1644 
1645  case OPERAND_FLOAT:
1646  {
1647  if (rightchild->operand[0] != OPERAND_FLOAT)
1648  {
1649  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1650  leftchild->operand[0], rightchild->operand[0]);
1651  return;
1652  }
1653 
1654  operand.resize(1+sizeof(long double), (char)0);
1655  operand[0] = OPERAND_FLOAT;
1656  int64_t val = *(long double *)(leftchild->operand.c_str()+1) -
1657  *(long double *)(rightchild->operand.c_str()+1);
1658  memcpy(&operand[1], &val, sizeof(val));
1659  isoperator=false;
1660  }
1661  break;
1662 
1663  default:
1664  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
1665  leftchild->operand[0]);
1666  return;
1667  }
1668 
1669  delete leftchild;
1670  leftchild=NULL;
1671  delete rightchild;
1672  rightchild=NULL;
1673  break;
1674 
1676  if (leftchild->operand[0]==OPERAND_FLOAT ||
1678  {
1681  }
1682 
1683  switch (leftchild->operand[0])
1684  {
1685  case OPERAND_INTEGER:
1686  {
1687  if (rightchild->operand[0] != OPERAND_INTEGER)
1688  {
1689  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1690  leftchild->operand[0], rightchild->operand[0]);
1691  return;
1692  }
1693 
1694  operand.resize(1+sizeof(int64_t), (char)0);
1695  operand[0] = OPERAND_INTEGER;
1696  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) *
1697  *(int64_t *)(rightchild->operand.c_str()+1);
1698  memcpy(&operand[1], &val, sizeof(val));
1699  isoperator=false;
1700  }
1701  break;
1702 
1703  case OPERAND_FLOAT:
1704  {
1705  if (rightchild->operand[0] != OPERAND_FLOAT)
1706  {
1707  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1708  leftchild->operand[0], rightchild->operand[0]);
1709  return;
1710  }
1711 
1712  operand.resize(1+sizeof(long double), (char)0);
1713  operand[0] = OPERAND_FLOAT;
1714  int64_t val = *(long double *)(leftchild->operand.c_str()+1) *
1715  *(long double *)(rightchild->operand.c_str()+1);
1716  memcpy(&operand[1], &val, sizeof(val));
1717  isoperator=false;
1718  }
1719  break;
1720 
1721  default:
1722  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
1723  leftchild->operand[0]);
1724  return;
1725  }
1726 
1727  delete leftchild;
1728  leftchild=NULL;
1729  delete rightchild;
1730  rightchild=NULL;
1731  break;
1732 
1733  case OPERATOR_DIVISION:
1734  if (leftchild->operand[0]==OPERAND_FLOAT ||
1736  {
1739  }
1740 
1741  switch (leftchild->operand[0])
1742  {
1743  case OPERAND_INTEGER:
1744  {
1745  if (rightchild->operand[0] != OPERAND_INTEGER)
1746  {
1747  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1748  leftchild->operand[0], rightchild->operand[0]);
1749  return;
1750  }
1751 
1752  operand.resize(1+sizeof(int64_t), (char)0);
1753  operand[0] = OPERAND_INTEGER;
1754  int64_t val = *(int64_t *)(leftchild->operand.c_str()+1) /
1755  *(int64_t *)(rightchild->operand.c_str()+1);
1756  memcpy(&operand[1], &val, sizeof(val));
1757  isoperator=false;
1758  }
1759  break;
1760 
1761  case OPERAND_FLOAT:
1762  {
1763  if (rightchild->operand[0] != OPERAND_FLOAT)
1764  {
1765  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1766  leftchild->operand[0], rightchild->operand[0]);
1767  return;
1768  }
1769 
1770  operand.resize(1+sizeof(long double), (char)0);
1771  operand[0] = OPERAND_FLOAT;
1772  int64_t val = *(long double *)(leftchild->operand.c_str()+1) /
1773  *(long double *)(rightchild->operand.c_str()+1);
1774  memcpy(&operand[1], &val, sizeof(val));
1775  isoperator=false;
1776  }
1777  break;
1778 
1779  default:
1780  printf("%s %i not an arithmetic type %c\n", __FILE__, __LINE__,
1781  leftchild->operand[0]);
1782  return;
1783  }
1784 
1785  delete leftchild;
1786  leftchild=NULL;
1787  delete rightchild;
1788  rightchild=NULL;
1789  break;
1790 
1791  case OPERATOR_NEGATION:
1792  if (rightchild->operand[0]==OPERAND_FLOAT)
1793  {
1795  }
1796 
1797  switch (rightchild->operand[0])
1798  {
1799  case OPERAND_INTEGER:
1800  {
1801  if (rightchild->operand[0] != OPERAND_INTEGER)
1802  {
1803  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1804  leftchild->operand[0], rightchild->operand[0]);
1805  return;
1806  }
1807 
1808  operand.resize(1+sizeof(int64_t), (char)0);
1809  operand[0] = OPERAND_INTEGER;
1810  int64_t val = 0 -
1811  *(int64_t *)(rightchild->operand.c_str()+1);
1812  memcpy(&operand[1], &val, sizeof(val));
1813  isoperator=false;
1814  }
1815  break;
1816 
1817  case OPERAND_FLOAT:
1818  {
1819  if (rightchild->operand[0] != OPERAND_FLOAT)
1820  {
1821  printf("%s %i operand mismatch %c %i\n", __FILE__, __LINE__,
1822  leftchild->operand[0], rightchild->operand[0]);
1823  return;
1824  }
1825 
1826  operand.resize(1+sizeof(long double), (char)0);
1827  operand[0] = OPERAND_FLOAT;
1828  int64_t val = 0 -
1829  *(long double *)(rightchild->operand.c_str()+1);
1830  memcpy(&operand[1], &val, sizeof(val));
1831  isoperator=false;
1832  }
1833  break;
1834 
1835  default:
1836  printf("%s %i not an arithmetic type '%c'\n", __FILE__, __LINE__,
1837  leftchild->operand[0]);
1838  return;
1839  }
1840 
1841  delete rightchild;
1842  rightchild=NULL;
1843  break;
1844 
1845  default:
1846  printf("%s %i can't evaluate %i in set assignment\n", __FILE__, __LINE__,
1847  operatortype);
1848  }
1849 }

Here is the call graph for this function:

Here is the caller graph for this function:

void Ast::normalizeSetAssignmentOperand ( vector< fieldValue_s > &  fieldValues,
class Statement statementPtr 
)

convert

Parameters
fieldValues
statementPtr

Definition at line 1851 of file Asts.cc.

References BOOL, CHAR, CHARX, Statement::currentQuery, FLOAT, INT, operand, OPERAND_FIELDID, OPERAND_FLOAT, OPERAND_INTEGER, OPERAND_PARAMETER, OPERAND_STRING, OPERAND_SUBQUERY, Statement::parameters, Statement::schemaPtr, Statement::subqueryScalar(), Statement::query_s::tableid, Schema::tables, UINT, and VARCHAR.

Referenced by evaluateAssignment().

1853 {
1854  switch (operand[0])
1855  {
1856  case OPERAND_FIELDID:
1857  {
1858  int64_t fieldid;
1859  memcpy(&fieldid, &operand[1], sizeof(fieldid));
1860 
1861  switch (statementPtr->schemaPtr->tables[statementPtr->currentQuery->tableid]->fields[fieldid].type)
1862  {
1863  case INT:
1864  operand.resize(1+sizeof(int64_t), (char)0);
1865  operand[0] = OPERAND_INTEGER;
1866  memcpy(&operand[1], &fieldValues[fieldid].value.integer,
1867  sizeof(int64_t));
1868  break;
1869 
1870  case UINT:
1871  operand.resize(1+sizeof(int64_t), (char)0);
1872  operand[0] = OPERAND_INTEGER;
1873  memcpy(&operand[1], &fieldValues[fieldid].value.uinteger,
1874  sizeof(int64_t));
1875  break;
1876 
1877  case BOOL:
1878  operand.resize(1+sizeof(int64_t), (char)0);
1879  operand[0] = OPERAND_INTEGER;
1880  int64_t val;
1881 
1882  if (fieldValues[fieldid].value.boolean==true)
1883  {
1884  val=1;
1885  }
1886  else
1887  {
1888  val=0;
1889  }
1890 
1891  memcpy(&operand[1], &val, sizeof(int64_t));
1892  break;
1893 
1894  case FLOAT:
1895  operand.resize(1+sizeof(long double), (char)0);
1896  operand[0] = OPERAND_FLOAT;
1897  memcpy(&operand[1], &fieldValues[fieldid].value.floating,
1898  sizeof(int64_t));
1899  break;
1900 
1901  case CHAR:
1902  operand.resize(1+sizeof(char), (char)0);
1903  operand[0] = OPERAND_STRING;
1904  operand[1] = fieldValues[fieldid].value.character;
1905  break;
1906 
1907  case CHARX:
1908  operand.assign(1, OPERAND_STRING);
1909  operand.append(fieldValues[fieldid].str);
1910  break;
1911 
1912  case VARCHAR:
1913  operand.assign(1, OPERAND_STRING);
1914  operand.append(fieldValues[fieldid].str);
1915  break;
1916 
1917  default:
1918  printf("%s %i anomaly %i\n", __FILE__, __LINE__,
1919  statementPtr->schemaPtr->tables[statementPtr->currentQuery->tableid]->fields[fieldid].type);
1920  }
1921  }
1922  break;
1923 
1924  case OPERAND_SUBQUERY:
1925  statementPtr->subqueryScalar(this);
1926  break;
1927 
1928  case OPERAND_PARAMETER:
1929  {
1930  int64_t paramnum;
1931  memcpy(&paramnum, &operand[1], sizeof(paramnum));
1932  operand = statementPtr->parameters[paramnum];
1933  }
1934  break;
1935 
1936  default:
1937  return;
1938  }
1939 }

Here is the call graph for this function:

Here is the caller graph for this function:

Ast & Ast::operator= ( const Ast orig)

Definition at line 68 of file Asts.cc.

References cp().

69 {
70  cp(orig);
71  return *this;
72 }

Here is the call graph for this function:

void Ast::toFloat ( const string &  inoperand,
fieldValue_s outField 
)
static

converts INTEGER to FLOAT (or leaves float alone). Supports arithmetic between numbers. Parser doesn't determine type based on context, but on content. So, "35+15.7" is parsed as INTEGER + FLOAT. While "35.0+15.7" is parsed as FLOAT + FLOAT. This function casts INTEGER to FLOAT so math can be performed.

Parameters
inoperandoperand to convert
outFieldconverted to fieldValue_s type

Definition at line 1941 of file Asts.cc.

References fieldInput_u::floating, OPERAND_FLOAT, OPERAND_INTEGER, and fieldValue_s::value.

Referenced by Statement::andPredicate(), Statement::branchtotype(), Statement::continueUpdate(), evaluate(), evaluateAssignment(), and Statement::stagedPredicate().

1942 {
1943  switch (inoperand[0])
1944  {
1945  case OPERAND_INTEGER:
1946  {
1947  int64_t val;
1948  memcpy(&val, &inoperand[1], sizeof(val));
1949  outField.value.floating=(long double)val;
1950  }
1951  break;
1952 
1953  case OPERAND_FLOAT:
1954  memcpy(&outField.value.floating, &inoperand[1], sizeof(long double));
1955  break;
1956 
1957  default:
1958  outField.value.floating=0;
1959  }
1960 }

Here is the caller graph for this function:

void Ast::toFloat ( const string &  inoperand,
string &  outoperand 
)
static

converts INTEGER to FLOAT (or leaves float alone). Supports arithmetic between numbers. Parser doesn't determine type based on context, but on content. So, "35+15.7" is parsed as INTEGER + FLOAT. While "35.0+15.7" is parsed as FLOAT + FLOAT. This function casts INTEGER to FLOAT so math can be performed.

Parameters
inoperandoperand to convert
outoperandoutput operand

Definition at line 1962 of file Asts.cc.

References OPERAND_FLOAT, and OPERAND_INTEGER.

1963 {
1964  string instr=inoperand;
1965 
1966  switch (instr[0])
1967  {
1968  case OPERAND_INTEGER:
1969  {
1970  outoperand.resize(1+sizeof(int64_t), OPERAND_FLOAT);
1971  int64_t val;
1972  memcpy(&val, &instr[1], sizeof(val));
1973  memcpy(&outoperand[1], &val, sizeof(val));
1974  }
1975  break;
1976 
1977  case OPERAND_FLOAT:
1978  outoperand=instr;
1979  break;
1980 
1981  default:
1982  outoperand.resize(1+sizeof(long double), OPERAND_FLOAT);
1983  long double val;
1984  memcpy(&val, &instr[1], sizeof(val));
1985  memcpy(&outoperand[1], &val, sizeof(val));
1986  }
1987 }

Member Data Documentation

bool Ast::isoperator

Definition at line 142 of file Asts.h.

Referenced by cp(), evaluate(), evaluateAssignment(), Statement::resolveFieldNames(), and ~Ast().

class Ast* Ast::leftchild
operatortypes_e Ast::operatortype

Definition at line 143 of file Asts.h.

Referenced by Ast(), cp(), evaluate(), and evaluateAssignment().

class Ast* Ast::parent

Definition at line 138 of file Asts.h.

Referenced by Larxer::consumeExpression(), cp(), evaluate(), and Statement::resolveFieldNames().

boost::unordered_map<uuRecord_s, returnRow_s> Ast::predicateResults

Definition at line 145 of file Asts.h.

Referenced by cp(), evaluate(), and Statement::searchExpression().

class Ast* Ast::rightchild

The documentation for this class was generated from the following files: