CUBRID Engine  latest
fetch.c
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * fetch.c - Object/Tuple value fetch routines
22  */
23 
24 #ident "$Id$"
25 
26 #include "config.h"
27 
28 #include <stdio.h>
29 #include <string.h>
30 #include <time.h>
31 #include <sys/timeb.h>
32 #if !defined(WINDOWS)
33 #include <sys/time.h>
34 #endif
35 
36 #include "fetch.h"
37 
38 #include "error_manager.h"
39 #include "system_parameter.h"
40 #include "storage_common.h"
41 #include "object_primitive.h"
42 #include "object_representation.h"
43 #include "arithmetic.h"
44 #include "serial.h"
45 #include "session.h"
46 #include "string_opfunc.h"
47 #include "server_interface.h"
48 #include "query_opfunc.h"
49 #include "regu_var.hpp"
50 #include "tz_support.h"
51 #include "db_date.h"
52 #include "xasl.h"
53 #include "xasl_predicate.hpp"
54 #include "query_executor.h"
55 #include "thread_entry.hpp"
56 
57 #include "dbtype.h"
58 
59 static int fetch_peek_arith (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr * vd, OID * obj_oid,
60  QFILE_TUPLE tpl, DB_VALUE ** peek_dbval);
61 static int fetch_peek_dbval_pos (REGU_VARIABLE * regu_var, QFILE_TUPLE tpl, int pos, DB_VALUE ** peek_dbval,
62  QFILE_TUPLE * next_tpl);
64  val_descr * vd, OID * obj_oid, QFILE_TUPLE tpl,
65  DB_VALUE ** min, DB_VALUE ** max);
66 
67 static bool is_argument_wrapped_with_cast_op (const REGU_VARIABLE * regu_var);
68 static int get_hour_minute_or_second (const DB_VALUE * datetime, OPERATOR_TYPE op_type, DB_VALUE * db_value);
69 static int get_year_month_or_day (const DB_VALUE * src_date, OPERATOR_TYPE op, DB_VALUE * result);
70 static int get_date_weekday (const DB_VALUE * src_date, OPERATOR_TYPE op, DB_VALUE * result);
71 
72 /*
73  * fetch_peek_arith () -
74  * return: NO_ERROR or ER_code
75  * regu_var(in/out): Regulator Variable of an ARITH node.
76  * vd(in): Value Descriptor
77  * obj_oid(in): Object Identifier
78  * tpl(in): Tuple
79  * peek_dbval(out): Set to the value resulting from the fetch operation
80  */
81 static int
82 fetch_peek_arith (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr * vd, OID * obj_oid, QFILE_TUPLE tpl,
83  DB_VALUE ** peek_dbval)
84 {
85  ARITH_TYPE *arithptr;
86  DB_VALUE *peek_left, *peek_right, *peek_third, *peek_fourth;
87  DB_VALUE tmp_value;
88  TP_DOMAIN *original_domain = NULL;
89  TP_DOMAIN_STATUS dom_status;
90 
91  assert (regu_var != NULL);
92  arithptr = regu_var->value.arithptr;
94  {
95  *peek_dbval = arithptr->value;
96 
97  return NO_ERROR;
98  }
99 
101 
102  peek_left = NULL;
103  peek_right = NULL;
104  peek_third = NULL;
105  peek_fourth = NULL;
106 
108  {
111  return error;
112  }
113  thread_inc_recursion_depth (thread_p);
114 
115  /* fetch values */
116  switch (arithptr->opcode)
117  {
118  case T_SUBSTRING:
119  case T_LPAD:
120  case T_RPAD:
121  case T_REPLACE:
122  case T_TRANSLATE:
123  case T_TO_CHAR:
124  case T_TO_DATE:
125  case T_TO_TIME:
126  case T_TO_TIMESTAMP:
127  case T_TO_DATETIME:
128  case T_TO_NUMBER:
129  case T_INSTR:
130  case T_MID:
131  case T_DATE_ADD:
132  case T_DATE_SUB:
133  case T_NEXT_VALUE:
134  case T_INDEX_PREFIX:
135  case T_TO_DATETIME_TZ:
136  case T_TO_TIMESTAMP_TZ:
137 
138  /* fetch lhs, rhs, and third value */
139  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
140  {
141  goto error;
142  }
143  if (!DB_IS_NULL (peek_left))
144  {
145  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
146  {
147  goto error;
148  }
150  && !arithptr->thirdptr)
151  {
152  break;
153  }
154  if (arithptr->thirdptr != NULL)
155  {
156  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
157  {
158  goto error;
159  }
160  }
161  }
162  break;
163 
164  case T_STR_TO_DATE:
165  case T_DATE_FORMAT:
166  case T_TIME_FORMAT:
167  case T_FORMAT:
168  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
169  {
170  goto error;
171  }
172  /* FALLTHRU */
173 
174  case T_ADD:
175  case T_SUB:
176  case T_MUL:
177  case T_DIV:
178  case T_MOD:
179  case T_POSITION:
180  case T_FINDINSET:
181  case T_ADD_MONTHS:
182  case T_MONTHS_BETWEEN:
183  case T_AES_ENCRYPT:
184  case T_AES_DECRYPT:
185  case T_SHA_TWO:
186  case T_POWER:
187  case T_ROUND:
188  case T_LOG:
189  case T_TRUNC:
190  case T_STRCAT:
191  case T_NULLIF:
192  case T_INCR:
193  case T_DECR:
194  case T_BIT_AND:
195  case T_BIT_OR:
196  case T_BIT_XOR:
197  case T_BITSHIFT_LEFT:
198  case T_BITSHIFT_RIGHT:
199  case T_INTDIV:
200  case T_INTMOD:
201  case T_STRCMP:
202  case T_ATAN2:
203  case T_ADDDATE:
204  case T_SUBDATE:
205  case T_DATEDIFF:
206  case T_TIMEDIFF:
207  case T_CURRENT_VALUE:
208  case T_CHR:
209  /* fetch lhs and rhs value */
210  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
211  {
212  goto error;
213  }
214  if (DB_IS_NULL (peek_left))
215  {
217  && (arithptr->opcode == T_STRCAT || arithptr->opcode == T_ADD))
218  {
219  /* check for result type. */
220  if (TP_DOMAIN_TYPE (regu_var->domain) == DB_TYPE_VARIABLE
221  || QSTR_IS_ANY_CHAR_OR_BIT (TP_DOMAIN_TYPE (regu_var->domain)))
222  {
223  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
224  {
225  goto error;
226  }
227  }
228  }
229  }
230  else
231  {
232  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
233  {
234  goto error;
235  }
236  }
237  break;
238 
239  case T_TRIM:
240  case T_LTRIM:
241  case T_RTRIM:
242  /* fetch lhs and rhs value */
243  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
244  {
245  goto error;
246  }
247  if (arithptr->rightptr != NULL)
248  {
249  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
250  {
251  goto error;
252  }
253  }
254  break;
255 
256  case T_FROM_UNIXTIME:
257 
258  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
259  {
260  goto error;
261  }
262  if (arithptr->rightptr != NULL)
263  {
264  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
265  {
266  goto error;
267  }
268  }
269  if (arithptr->thirdptr != NULL)
270  {
271  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
272  {
273  goto error;
274  }
275  }
276  break;
277 
278  case T_SUBSTRING_INDEX:
279  case T_CONCAT_WS:
280  case T_FIELD:
281  case T_INDEX_CARDINALITY:
282  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
283  {
284  goto error;
285  }
286  if (arithptr->rightptr != NULL)
287  {
288  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
289  {
290  goto error;
291  }
292  }
293  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
294  {
295  goto error;
296  }
297  break;
298 
299  case T_CONV:
300  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
301  {
302  goto error;
303  }
304  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
305  {
306  goto error;
307  }
308  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
309  {
310  goto error;
311  }
312  break;
313 
314  case T_LOCATE:
315  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
316  {
317  goto error;
318  }
319  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
320  {
321  goto error;
322  }
323  if (arithptr->thirdptr != NULL)
324  {
325  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
326  {
327  goto error;
328  }
329  }
330  break;
331 
332  case T_CONCAT:
333  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
334  {
335  goto error;
336  }
337  if (DB_IS_NULL (peek_left))
338  {
340  {
341  if (arithptr->rightptr != NULL)
342  {
343  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
344  {
345  goto error;
346  }
347  }
348  }
349  }
350  else
351  {
352  if (arithptr->rightptr != NULL)
353  {
354  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
355  {
356  goto error;
357  }
358  }
359  }
360  break;
361 
362  case T_REPEAT:
363  case T_LEAST:
364  case T_GREATEST:
366  case T_LEFT:
367  case T_RIGHT:
368  /* fetch both lhs and rhs value */
369  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
370  {
371  goto error;
372  }
373  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
374  {
375  goto error;
376  }
377  break;
378 
379  case T_MAKEDATE:
380  case T_ADDTIME:
381  case T_WEEK:
382  case T_DEFINE_VARIABLE:
383  case T_FROM_TZ:
384  /* fetch both lhs and rhs value */
385  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
386  {
388  {
389  /* cast might have failed: set ER_DATE_CONVERSION */
391  }
392  goto error;
393  }
394  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
395  {
397  {
398  /* cast might have failed: set ER_DATE_CONVERSION */
400  }
401  goto error;
402  }
403  break;
404 
405  case T_MAKETIME:
406  case T_NEW_TIME:
407  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
408  {
410  {
411  /* cast might have failed: set ER_TIME_CONVERSION */
413  }
414  goto error;
415  }
416  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
417  {
419  {
420  /* cast might have failed: set ER_TIME_CONVERSION */
422  }
423  goto error;
424  }
425  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
426  {
428  {
429  /* cast might have failed: set ER_TIME_CONVERSION */
431  }
432  goto error;
433  }
434  break;
435 
436  case T_CASE:
437  case T_DECODE:
438  case T_IF:
439  case T_IFNULL:
440  case T_NVL:
441  case T_PREDICATE:
442  case T_COALESCE:
443  case T_NVL2:
444  /* defer fetch values */
445  break;
446 
447  case T_LAST_DAY:
448 #if defined(ENABLE_UNUSED_FUNCTION)
449  case T_UNPLUS:
450 #endif /* ENABLE_UNUSED_FUNCTION */
451  case T_UNMINUS:
452  case T_OCTET_LENGTH:
453  case T_BIT_LENGTH:
454  case T_CHAR_LENGTH:
455  case T_LOWER:
456  case T_UPPER:
457  case T_HEX:
458  case T_ASCII:
459  case T_SPACE:
460  case T_MD5:
461  case T_SHA_ONE:
462  case T_TO_BASE64:
463  case T_FROM_BASE64:
464  case T_BIN:
465  case T_CAST:
466  case T_CAST_NOFAIL:
467  case T_CAST_WRAP:
468  case T_EXTRACT:
469  case T_FLOOR:
470  case T_CEIL:
471  case T_SIGN:
472  case T_ABS:
473  case T_EXP:
474  case T_SQRT:
475  case T_PRIOR:
476  case T_BIT_NOT:
477  case T_REVERSE:
478  case T_DISK_SIZE:
479  case T_BIT_COUNT:
480  case T_ACOS:
481  case T_ASIN:
482  case T_SIN:
483  case T_COS:
484  case T_TAN:
485  case T_COT:
486  case T_DEGREES:
487  case T_RADIANS:
488  case T_LN:
489  case T_LOG2:
490  case T_LOG10:
491  case T_ATAN:
492  case T_DATE:
493  case T_TIME:
494  case T_ISNULL:
495  case T_RAND:
496  case T_DRAND:
497  case T_RANDOM:
498  case T_DRANDOM:
499  case T_TYPEOF:
500  case T_EXEC_STATS:
501  case T_INET_ATON:
502  case T_INET_NTOA:
503  case T_CHARSET:
504  case T_COLLATION:
505  case T_TZ_OFFSET:
506  case T_SLEEP:
507  case T_CRC32:
508  case T_CONV_TZ:
509  /* fetch rhs value */
510  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
511  {
512  goto error;
513  }
514  break;
515 
516  case T_YEAR:
517  case T_MONTH:
518  case T_DAY:
519  case T_QUARTER:
520  case T_WEEKDAY:
521  case T_DAYOFWEEK:
522  case T_DAYOFYEAR:
523  case T_TODAYS:
524  case T_FROMDAYS:
525  case T_EVALUATE_VARIABLE:
526  /* fetch rhs value */
527  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
528  {
530  {
531  /* cast might have failed: set ER_DATE_CONVERSION */
533  }
534  goto error;
535  }
536  break;
537 
538  case T_HOUR:
539  case T_MINUTE:
540  case T_SECOND:
541  case T_TIMETOSEC:
542  case T_SECTOTIME:
543  /* fetch rhs value */
544  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
545  {
547  {
548  /* if cast failed, set ER_TIME_CONVERSION */
550  }
551  goto error;
552  }
553  break;
554 
555  case T_UNIX_TIMESTAMP:
556  case T_DEFAULT:
557  if (arithptr->rightptr)
558  {
559  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
560  {
561  goto error;
562  }
563  }
564  break;
565 
566  case T_TIMESTAMP:
567  case T_LIKE_LOWER_BOUND:
568  case T_LIKE_UPPER_BOUND:
569  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
570  {
571  goto error;
572  }
573  if (arithptr->rightptr)
574  {
575  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
576  {
577  goto error;
578  }
579  }
580  break;
581 
582  case T_CONNECT_BY_ROOT:
583  case T_QPRIOR:
584  case T_SYS_DATE:
585  case T_SYS_TIME:
586  case T_SYS_TIMESTAMP:
587  case T_SYS_DATETIME:
588  case T_CURRENT_DATE:
589  case T_CURRENT_TIME:
590  case T_CURRENT_TIMESTAMP:
591  case T_CURRENT_DATETIME:
592  case T_UTC_TIME:
593  case T_UTC_DATE:
595  case T_PI:
596  case T_ROW_COUNT:
597  case T_LAST_INSERT_ID:
598  case T_LIST_DBS:
599  case T_TRACE_STATS:
600  case T_DBTIMEZONE:
601  case T_SESSIONTIMEZONE:
602  case T_SYS_GUID:
603  case T_UTC_TIMESTAMP:
604  /* nothing to fetch */
605  break;
606 
607  case T_BLOB_TO_BIT:
608  case T_CLOB_TO_CHAR:
609  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
610  {
611  goto error;
612  }
613  if (!DB_IS_NULL (peek_left) && arithptr->rightptr)
614  {
615  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
616  {
617  goto error;
618  }
619  }
620  break;
621 
622  case T_BIT_TO_BLOB:
623  case T_CHAR_TO_CLOB:
624  case T_LOB_LENGTH:
625  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
626  {
627  goto error;
628  }
629  break;
630 
632  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
633  {
634  goto error;
635  }
636  break;
637 
638  case T_WIDTH_BUCKET:
639  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
640  {
641  goto error;
642  }
643 
644  /* get peek_righ, peed_third we use PT_BETWEEN with PT_BETWEEN_GE_LT to represent the two args. */
645  if (fetch_peek_min_max_value_of_width_bucket_func (thread_p, arithptr->rightptr, vd, obj_oid, tpl, &peek_right,
646  &peek_third) != NO_ERROR)
647  {
648  goto error;
649  }
650 
651  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_fourth) != NO_ERROR)
652  {
653  goto error;
654  }
655  break;
656 
657  default:
659  goto error;
660  }
661 
662  /* evaluate arithmetic expression */
663 
664  /* clear any previous result */
665  pr_clear_value (arithptr->value);
666  if (regu_var->domain != NULL && TP_DOMAIN_TYPE (regu_var->domain) == DB_TYPE_VARIABLE)
667  {
668  original_domain = regu_var->domain;
669  regu_var->domain = NULL;
670  }
671  switch (arithptr->opcode)
672  {
673  case T_ADD:
674  {
675  bool check_empty_string;
676 
677  check_empty_string = (prm_get_bool_value (PRM_ID_ORACLE_STYLE_EMPTY_STRING) ? true : false);
678 
679  /* check for result type. */
680  if (check_empty_string && regu_var->domain != NULL
681  && QSTR_IS_ANY_CHAR_OR_BIT (TP_DOMAIN_TYPE (regu_var->domain)))
682  {
683  /* at here, T_ADD is really T_STRCAT */
684  if (qdata_strcat_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
685  {
686  goto error;
687  }
688  }
689  else
690  {
691  if (qdata_add_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
692  {
693  goto error;
694  }
695  }
696  }
697  break;
698 
699  case T_BIT_NOT:
700  if (qdata_bit_not_dbval (peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
701  {
702  goto error;
703  }
704  break;
705 
706  case T_BIT_AND:
707  if (qdata_bit_and_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
708  {
709  goto error;
710  }
711  break;
712 
713  case T_BIT_OR:
714  if (qdata_bit_or_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
715  {
716  goto error;
717  }
718  break;
719 
720  case T_BIT_XOR:
721  if (qdata_bit_xor_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
722  {
723  goto error;
724  }
725  break;
726 
727  case T_BITSHIFT_LEFT:
728  case T_BITSHIFT_RIGHT:
729  if (qdata_bit_shift_dbval (peek_left, peek_right, arithptr->opcode, arithptr->value, regu_var->domain) !=
730  NO_ERROR)
731  {
732  goto error;
733  }
734  break;
735 
736  case T_INTDIV:
737  case T_INTMOD:
738  if (qdata_divmod_dbval (peek_left, peek_right, arithptr->opcode, arithptr->value, regu_var->domain) != NO_ERROR)
739  {
740  goto error;
741  }
742  break;
743 
744  case T_BIT_COUNT:
745  if (db_bit_count_dbval (arithptr->value, peek_right) != NO_ERROR)
746  {
747  goto error;
748  }
749  break;
750 
751  case T_SUB:
752  if (qdata_subtract_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
753  {
754  goto error;
755  }
756  break;
757 
758  case T_MUL:
759  if (qdata_multiply_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
760  {
761  goto error;
762  }
763  break;
764 
765  case T_DIV:
766  if (qdata_divide_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
767  {
768  goto error;
769  }
770  break;
771 
772 #if defined(ENABLE_UNUSED_FUNCTION)
773  case T_UNPLUS:
774  if (!qdata_copy_db_value (arithptr->value, peek_right))
775  {
776  goto error;
777  }
778  break;
779 #endif
780  case T_UNPLUS:
781  break;
782 
783 
784  case T_UNMINUS:
785  if (qdata_unary_minus_dbval (arithptr->value, peek_right) != NO_ERROR)
786  {
787  goto error;
788  }
789  break;
790 
791  case T_PRIOR:
792  if (!qdata_copy_db_value (arithptr->value, peek_right))
793  {
794  goto error;
795  }
796  break;
797 
798  case T_CONNECT_BY_ROOT:
799  if (!qdata_evaluate_connect_by_root (thread_p, (void *) arithptr->thirdptr->xasl, arithptr->rightptr,
800  arithptr->value, vd))
801  {
802  goto error;
803  }
804  break;
805 
806  case T_QPRIOR:
807  if (!qdata_evaluate_qprior (thread_p, (void *) arithptr->thirdptr->xasl, arithptr->rightptr, arithptr->value, vd))
808  {
809  goto error;
810  }
811  break;
812 
813  case T_MOD:
814  if (db_mod_dbval (arithptr->value, peek_left, peek_right) != NO_ERROR)
815  {
816  goto error;
817  }
818  break;
819 
820  case T_FLOOR:
821  if (DB_IS_NULL (peek_right))
822  {
823  PRIM_SET_NULL (arithptr->value);
824  }
825  else if (db_floor_dbval (arithptr->value, peek_right) != NO_ERROR)
826  {
827  goto error;
828  }
829  break;
830 
831  case T_CEIL:
832  if (DB_IS_NULL (peek_right))
833  {
834  PRIM_SET_NULL (arithptr->value);
835  }
836  else if (db_ceil_dbval (arithptr->value, peek_right) != NO_ERROR)
837  {
838  goto error;
839  }
840  break;
841 
842  case T_SIGN:
843  if (DB_IS_NULL (peek_right))
844  {
845  PRIM_SET_NULL (arithptr->value);
846  }
847  else if (db_sign_dbval (arithptr->value, peek_right) != NO_ERROR)
848  {
849  goto error;
850  }
851  break;
852 
853  case T_ABS:
854  if (DB_IS_NULL (peek_right))
855  {
856  PRIM_SET_NULL (arithptr->value);
857  }
858  else if (db_abs_dbval (arithptr->value, peek_right) != NO_ERROR)
859  {
860  goto error;
861  }
862  break;
863 
864  case T_EXP:
865  if (DB_IS_NULL (peek_right))
866  {
867  PRIM_SET_NULL (arithptr->value);
868  }
869  else if (db_exp_dbval (arithptr->value, peek_right) != NO_ERROR)
870  {
871  goto error;
872  }
873  break;
874 
875  case T_SQRT:
876  if (DB_IS_NULL (peek_right))
877  {
878  PRIM_SET_NULL (arithptr->value);
879  }
880  else if (db_sqrt_dbval (arithptr->value, peek_right) != NO_ERROR)
881  {
882  goto error;
883  }
884  break;
885 
886  case T_SIN:
887  if (DB_IS_NULL (peek_right))
888  {
889  PRIM_SET_NULL (arithptr->value);
890  }
891  else if (db_sin_dbval (arithptr->value, peek_right) != NO_ERROR)
892  {
893  goto error;
894  }
895  break;
896 
897  case T_COS:
898  if (DB_IS_NULL (peek_right))
899  {
900  PRIM_SET_NULL (arithptr->value);
901  }
902  else if (db_cos_dbval (arithptr->value, peek_right) != NO_ERROR)
903  {
904  goto error;
905  }
906  break;
907 
908  case T_TAN:
909  if (DB_IS_NULL (peek_right))
910  {
911  PRIM_SET_NULL (arithptr->value);
912  }
913  else if (db_tan_dbval (arithptr->value, peek_right) != NO_ERROR)
914  {
915  goto error;
916  }
917  break;
918 
919  case T_COT:
920  if (DB_IS_NULL (peek_right))
921  {
922  PRIM_SET_NULL (arithptr->value);
923  }
924  else if (db_cot_dbval (arithptr->value, peek_right) != NO_ERROR)
925  {
926  goto error;
927  }
928  break;
929 
930  case T_LN:
931  if (DB_IS_NULL (peek_right))
932  {
933  PRIM_SET_NULL (arithptr->value);
934  }
935  else if (db_log_generic_dbval (arithptr->value, peek_right, -1 /* convention for e base */ ) !=
936  NO_ERROR)
937  {
938  goto error;
939  }
940  break;
941 
942  case T_LOG2:
943  if (DB_IS_NULL (peek_right))
944  {
945  PRIM_SET_NULL (arithptr->value);
946  }
947  else if (db_log_generic_dbval (arithptr->value, peek_right, 2) != NO_ERROR)
948  {
949  goto error;
950  }
951  break;
952 
953  case T_LOG10:
954  if (DB_IS_NULL (peek_right))
955  {
956  PRIM_SET_NULL (arithptr->value);
957  }
958  else if (db_log_generic_dbval (arithptr->value, peek_right, 10) != NO_ERROR)
959  {
960  goto error;
961  }
962  break;
963 
964  case T_ACOS:
965  if (DB_IS_NULL (peek_right))
966  {
967  PRIM_SET_NULL (arithptr->value);
968  }
969  else if (db_acos_dbval (arithptr->value, peek_right) != NO_ERROR)
970  {
971  goto error;
972  }
973  break;
974 
975  case T_ASIN:
976  if (DB_IS_NULL (peek_right))
977  {
978  PRIM_SET_NULL (arithptr->value);
979  }
980  else if (db_asin_dbval (arithptr->value, peek_right) != NO_ERROR)
981  {
982  goto error;
983  }
984  break;
985 
986  case T_DEGREES:
987  if (DB_IS_NULL (peek_right))
988  {
989  PRIM_SET_NULL (arithptr->value);
990  }
991  else if (db_degrees_dbval (arithptr->value, peek_right) != NO_ERROR)
992  {
993  goto error;
994  }
995  break;
996 
997  case T_DATE:
998  if (DB_IS_NULL (peek_right))
999  {
1000  PRIM_SET_NULL (arithptr->value);
1001  }
1002  else if (db_date_dbval (arithptr->value, peek_right, arithptr->domain) != NO_ERROR)
1003  {
1004  goto error;
1005  }
1006  break;
1007 
1008  case T_TIME:
1009  if (DB_IS_NULL (peek_right))
1010  {
1011  PRIM_SET_NULL (arithptr->value);
1012  }
1013  else if (db_time_dbval (arithptr->value, peek_right, arithptr->domain) != NO_ERROR)
1014  {
1015  goto error;
1016  }
1017  break;
1018 
1019  case T_DEFAULT:
1020  qdata_copy_db_value (arithptr->value, peek_right);
1021  break;
1022 
1023  case T_RADIANS:
1024  if (DB_IS_NULL (peek_right))
1025  {
1026  PRIM_SET_NULL (arithptr->value);
1027  }
1028  else if (db_radians_dbval (arithptr->value, peek_right) != NO_ERROR)
1029  {
1030  goto error;
1031  }
1032  break;
1033 
1034  case T_POWER:
1035  if (db_power_dbval (arithptr->value, peek_left, peek_right) != NO_ERROR)
1036  {
1037  goto error;
1038  }
1039  break;
1040 
1041  case T_ROUND:
1042  if (db_round_dbval (arithptr->value, peek_left, peek_right) != NO_ERROR)
1043  {
1044  goto error;
1045  }
1046  break;
1047 
1048  case T_LOG:
1049  if (db_log_dbval (arithptr->value, peek_left, peek_right) != NO_ERROR)
1050  {
1051  goto error;
1052  }
1053  break;
1054 
1055  case T_INCR:
1056  case T_DECR:
1057  /* incr/decr is not constant */
1060  if (DB_IS_NULL (peek_right))
1061  {
1062  /* an instance does not exist to do increment */
1063  PRIM_SET_NULL (arithptr->value);
1064  }
1065  else
1066  {
1067  /*
1068  * right argument is used at end of scan,
1069  * so keep it in the expr until that.
1070  */
1071  (void) pr_clone_value (peek_right, arithptr->value);
1072  *peek_dbval = peek_left;
1073 
1074  goto fetch_peek_arith_end;
1075  }
1076  break;
1077 
1078  case T_TRUNC:
1079  if (db_trunc_dbval (arithptr->value, peek_left, peek_right) != NO_ERROR)
1080  {
1081  goto error;
1082  }
1083  break;
1084 
1085  case T_CHR:
1086  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1087  {
1088  PRIM_SET_NULL (arithptr->value);
1089  }
1090  else if (db_string_chr (arithptr->value, peek_left, peek_right) != NO_ERROR)
1091  {
1092  goto error;
1093  }
1094  break;
1095 
1096  case T_INSTR:
1097  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1098  {
1099  PRIM_SET_NULL (arithptr->value);
1100  }
1101  else if (db_string_instr (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
1102  {
1103  goto error;
1104  }
1105  break;
1106 
1107  case T_POSITION:
1108  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1109  {
1110  PRIM_SET_NULL (arithptr->value);
1111  }
1112  else if (db_string_position (peek_left, peek_right, arithptr->value) != NO_ERROR)
1113  {
1114  goto error;
1115  }
1116  break;
1117 
1118  case T_FINDINSET:
1119  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1120  {
1121  PRIM_SET_NULL (arithptr->value);
1122  }
1123  else if (db_find_string_in_in_set (peek_left, peek_right, arithptr->value) != NO_ERROR)
1124  {
1125  goto error;
1126  }
1127  break;
1128 
1129  case T_SUBSTRING:
1130  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || (arithptr->thirdptr && DB_IS_NULL (peek_third)))
1131  {
1132  PRIM_SET_NULL (arithptr->value);
1133  }
1135  {
1136  DB_VALUE tmp_len, tmp_arg2, tmp_arg3;
1137  int pos, len;
1138 
1139  pos = db_get_int (peek_right);
1140  if (pos < 0)
1141  {
1142  if (QSTR_IS_BIT (TP_DOMAIN_TYPE (arithptr->leftptr->domain)))
1143  {
1144  if (db_string_bit_length (peek_left, &tmp_len) != NO_ERROR)
1145  {
1146  goto error;
1147  }
1148  }
1149  else
1150  {
1151  if (db_string_char_length (peek_left, &tmp_len) != NO_ERROR)
1152  {
1153  goto error;
1154  }
1155  }
1156  if (DB_IS_NULL (&tmp_len))
1157  {
1158  goto error;
1159  }
1160  pos = pos + db_get_int (&tmp_len) + 1;
1161  }
1162 
1163  if (pos < 1)
1164  {
1165  db_make_int (&tmp_arg2, 1);
1166  }
1167  else
1168  {
1169  db_make_int (&tmp_arg2, pos);
1170  }
1171 
1172  if (arithptr->thirdptr)
1173  {
1174  len = db_get_int (peek_third);
1175  if (len < 1)
1176  {
1177  db_make_int (&tmp_arg3, 0);
1178  }
1179  else
1180  {
1181  db_make_int (&tmp_arg3, len);
1182  }
1183  }
1184  else
1185  {
1186  db_make_null (&tmp_arg3);
1187  }
1188 
1189  if (db_string_substring (arithptr->misc_operand, peek_left, &tmp_arg2, &tmp_arg3, arithptr->value) !=
1190  NO_ERROR)
1191  {
1192  goto error;
1193  }
1194  }
1195  else
1196  {
1197  if (db_string_substring (arithptr->misc_operand, peek_left, peek_right, peek_third, arithptr->value) !=
1198  NO_ERROR)
1199  {
1200  goto error;
1201  }
1202  }
1203  break;
1204 
1205  case T_OCTET_LENGTH:
1206  if (DB_IS_NULL (peek_right))
1207  {
1208  PRIM_SET_NULL (arithptr->value);
1209  }
1210  else
1211  {
1212  db_make_int (arithptr->value, db_get_string_size (peek_right));
1213  }
1214  break;
1215 
1216  case T_BIT_LENGTH:
1217  if (DB_IS_NULL (peek_right))
1218  {
1219  PRIM_SET_NULL (arithptr->value);
1220  }
1221  else if (DB_VALUE_DOMAIN_TYPE (peek_right) == DB_TYPE_BIT || DB_VALUE_DOMAIN_TYPE (peek_right) == DB_TYPE_VARBIT)
1222  {
1223  int len = 0;
1224 
1225  db_get_bit (peek_right, &len);
1226  db_make_int (arithptr->value, len);
1227  }
1228  else
1229  {
1230  /* must be a char string type */
1231  db_make_int (arithptr->value, 8 * db_get_string_size (peek_right));
1232  }
1233  break;
1234 
1235  case T_CHAR_LENGTH:
1236  if (DB_IS_NULL (peek_right))
1237  {
1238  PRIM_SET_NULL (arithptr->value);
1239  }
1240  else
1241  {
1242  db_make_int (arithptr->value, db_get_string_length (peek_right));
1243  }
1244  break;
1245 
1246  case T_LOWER:
1247  if (DB_IS_NULL (peek_right))
1248  {
1249  PRIM_SET_NULL (arithptr->value);
1250  }
1251  else if (db_string_lower (peek_right, arithptr->value) != NO_ERROR)
1252  {
1253  goto error;
1254  }
1255  break;
1256 
1257  case T_UPPER:
1258  if (DB_IS_NULL (peek_right))
1259  {
1260  PRIM_SET_NULL (arithptr->value);
1261  }
1262  else if (db_string_upper (peek_right, arithptr->value) != NO_ERROR)
1263  {
1264  goto error;
1265  }
1266  break;
1267 
1268  case T_HEX:
1269  if (DB_IS_NULL (peek_right))
1270  {
1271  PRIM_SET_NULL (arithptr->value);
1272  }
1273  else if (db_hex (peek_right, arithptr->value) != NO_ERROR)
1274  {
1275  goto error;
1276  }
1277  break;
1278 
1279  case T_ASCII:
1280  if (DB_IS_NULL (peek_right))
1281  {
1282  PRIM_SET_NULL (arithptr->value);
1283  }
1284  else if (db_ascii (peek_right, arithptr->value) != NO_ERROR)
1285  {
1286  goto error;
1287  }
1288  break;
1289 
1290  case T_CONV:
1291  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
1292  {
1293  PRIM_SET_NULL (arithptr->value);
1294  }
1295  else
1296  {
1297  if (db_conv (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
1298  {
1299  goto error;
1300  }
1301  }
1302  break;
1303 
1304  case T_BIN:
1305  if (DB_IS_NULL (peek_right))
1306  {
1307  PRIM_SET_NULL (arithptr->value);
1308  }
1309  else if (db_bigint_to_binary_string (peek_right, arithptr->value) != NO_ERROR)
1310  {
1311  goto error;
1312  }
1313  break;
1314 
1315  case T_MD5:
1316  if (DB_IS_NULL (peek_right))
1317  {
1318  PRIM_SET_NULL (arithptr->value);
1319  }
1320  else if (db_string_md5 (peek_right, arithptr->value) != NO_ERROR)
1321  {
1322  goto error;
1323  }
1324  break;
1325 
1326  case T_SHA_ONE:
1327  if (DB_IS_NULL (peek_right))
1328  {
1329  PRIM_SET_NULL (arithptr->value);
1330  }
1331  else if (db_string_sha_one (peek_right, arithptr->value) != NO_ERROR)
1332  {
1333  goto error;
1334  }
1335  break;
1336 
1337  case T_AES_ENCRYPT:
1338  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1339  {
1340  PRIM_SET_NULL (arithptr->value);
1341  }
1342  else if (db_string_aes_encrypt (peek_left, peek_right, arithptr->value) != NO_ERROR)
1343  {
1344  goto error;
1345  }
1346  break;
1347 
1348  case T_AES_DECRYPT:
1349  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1350  {
1351  PRIM_SET_NULL (arithptr->value);
1352  }
1353  else if (db_string_aes_decrypt (peek_left, peek_right, arithptr->value) != NO_ERROR)
1354  {
1355  goto error;
1356  }
1357  break;
1358 
1359  case T_SHA_TWO:
1360  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1361  {
1362  PRIM_SET_NULL (arithptr->value);
1363  }
1364  else if (db_string_sha_two (peek_left, peek_right, arithptr->value) != NO_ERROR)
1365  {
1366  goto error;
1367  }
1368  break;
1369 
1370  case T_TO_BASE64:
1371  if (DB_IS_NULL (peek_right))
1372  {
1373  PRIM_SET_NULL (arithptr->value);
1374  }
1375  else if (db_string_to_base64 (peek_right, arithptr->value) != NO_ERROR)
1376  {
1377  goto error;
1378  }
1379  break;
1380 
1381  case T_FROM_BASE64:
1382  if (DB_IS_NULL (peek_right))
1383  {
1384  PRIM_SET_NULL (arithptr->value);
1385  }
1386  else if (db_string_from_base64 (peek_right, arithptr->value) != NO_ERROR)
1387  {
1388  goto error;
1389  }
1390  break;
1391 
1392  case T_SPACE:
1393  if (DB_IS_NULL (peek_right))
1394  {
1395  PRIM_SET_NULL (arithptr->value);
1396  }
1397  else if (db_string_space (peek_right, arithptr->value) != NO_ERROR)
1398  {
1399  goto error;
1400  }
1401  break;
1402 
1403  case T_TRIM:
1404  if (REGU_VARIABLE_IS_FLAGED (regu_var, REGU_VARIABLE_INFER_COLLATION) && !DB_IS_NULL (peek_left) && peek_right
1405  && !DB_IS_NULL (peek_right))
1406  {
1407  TP_DOMAIN_STATUS status = tp_value_change_coll_and_codeset (peek_right, peek_right,
1408  db_get_string_collation (peek_left),
1409  db_get_string_codeset (peek_left));
1410 
1411  if (status != DOMAIN_COMPATIBLE)
1412  {
1414  pr_type_name (DB_VALUE_TYPE (peek_left)));
1415  goto error;
1416  }
1417  }
1418  if (DB_IS_NULL (peek_left) || (peek_right && DB_IS_NULL (peek_right)))
1419  {
1420  PRIM_SET_NULL (arithptr->value);
1421  }
1422  else if (db_string_trim (arithptr->misc_operand, peek_right, peek_left, arithptr->value) != NO_ERROR)
1423  {
1424  goto error;
1425  }
1426  break;
1427 
1428  case T_LTRIM:
1429  if (REGU_VARIABLE_IS_FLAGED (regu_var, REGU_VARIABLE_INFER_COLLATION) && !DB_IS_NULL (peek_left) && peek_right
1430  && !DB_IS_NULL (peek_right))
1431  {
1432  TP_DOMAIN_STATUS status = tp_value_change_coll_and_codeset (peek_right, peek_right,
1433  db_get_string_collation (peek_left),
1434  db_get_string_codeset (peek_left));
1435 
1436  if (status != DOMAIN_COMPATIBLE)
1437  {
1439  pr_type_name (DB_VALUE_TYPE (peek_left)));
1440  goto error;
1441  }
1442  }
1443  if (DB_IS_NULL (peek_left) || (peek_right && DB_IS_NULL (peek_right)))
1444  {
1445  PRIM_SET_NULL (arithptr->value);
1446  }
1447  else if (db_string_trim (LEADING, peek_right, peek_left, arithptr->value) != NO_ERROR)
1448  {
1449  goto error;
1450  }
1451  break;
1452 
1453  case T_RTRIM:
1454  if (REGU_VARIABLE_IS_FLAGED (regu_var, REGU_VARIABLE_INFER_COLLATION) && !DB_IS_NULL (peek_left) && peek_right
1455  && !DB_IS_NULL (peek_right))
1456  {
1457  TP_DOMAIN_STATUS status = tp_value_change_coll_and_codeset (peek_right, peek_right,
1458  db_get_string_collation (peek_left),
1459  db_get_string_codeset (peek_left));
1460 
1461  if (status != DOMAIN_COMPATIBLE)
1462  {
1464  pr_type_name (DB_VALUE_TYPE (peek_left)));
1465  goto error;
1466  }
1467  }
1468  if (DB_IS_NULL (peek_left) || (peek_right && DB_IS_NULL (peek_right)))
1469  {
1470  PRIM_SET_NULL (arithptr->value);
1471  }
1472  else if (db_string_trim (TRAILING, peek_right, peek_left, arithptr->value) != NO_ERROR)
1473  {
1474  goto error;
1475  }
1476  break;
1477 
1478  case T_FROM_UNIXTIME:
1479  if (DB_IS_NULL (peek_left))
1480  {
1481  PRIM_SET_NULL (arithptr->value);
1482  }
1483  else if (db_from_unixtime (peek_left, peek_right, peek_third, arithptr->value, arithptr->domain) != NO_ERROR)
1484  {
1485  goto error;
1486  }
1487  break;
1488 
1489  case T_LPAD:
1490  if (REGU_VARIABLE_IS_FLAGED (regu_var, REGU_VARIABLE_INFER_COLLATION) && !DB_IS_NULL (peek_left) && peek_third
1491  && !DB_IS_NULL (peek_third))
1492  {
1493  TP_DOMAIN_STATUS status = tp_value_change_coll_and_codeset (peek_third, peek_third,
1494  db_get_string_collation (peek_left),
1495  db_get_string_codeset (peek_left));
1496 
1497  if (status != DOMAIN_COMPATIBLE)
1498  {
1500  pr_type_name (DB_VALUE_TYPE (peek_left)));
1501  goto error;
1502  }
1503  }
1504  if (DB_IS_NULL (peek_left) || (peek_third && DB_IS_NULL (peek_third)))
1505  {
1506  PRIM_SET_NULL (arithptr->value);
1507  }
1508  else if (db_string_pad (LEADING, peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
1509  {
1510  goto error;
1511  }
1512  break;
1513 
1514  case T_RPAD:
1515  if (REGU_VARIABLE_IS_FLAGED (regu_var, REGU_VARIABLE_INFER_COLLATION) && !DB_IS_NULL (peek_left) && peek_third
1516  && !DB_IS_NULL (peek_third))
1517  {
1518  TP_DOMAIN_STATUS status = tp_value_change_coll_and_codeset (peek_third, peek_third,
1519  db_get_string_collation (peek_left),
1520  db_get_string_codeset (peek_left));
1521 
1522  if (status != DOMAIN_COMPATIBLE)
1523  {
1525  pr_type_name (DB_VALUE_TYPE (peek_left)));
1526  goto error;
1527  }
1528  }
1529  if (DB_IS_NULL (peek_left) || (peek_third && DB_IS_NULL (peek_third)))
1530  {
1531  PRIM_SET_NULL (arithptr->value);
1532  }
1533  else if (db_string_pad (TRAILING, peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
1534  {
1535  goto error;
1536  }
1537  break;
1538 
1539  case T_REPLACE:
1540  if (REGU_VARIABLE_IS_FLAGED (regu_var, REGU_VARIABLE_INFER_COLLATION) && !DB_IS_NULL (peek_left) && peek_third
1541  && !DB_IS_NULL (peek_third))
1542  {
1543  TP_DOMAIN_STATUS status = tp_value_change_coll_and_codeset (peek_third, peek_third,
1544  db_get_string_collation (peek_left),
1545  db_get_string_codeset (peek_left));
1546 
1547  if (status != DOMAIN_COMPATIBLE)
1548  {
1550  pr_type_name (DB_VALUE_TYPE (peek_left)));
1551  goto error;
1552  }
1553  }
1554  if (DB_IS_NULL (peek_left) || (peek_third && DB_IS_NULL (peek_third)))
1555  {
1556  PRIM_SET_NULL (arithptr->value);
1557  }
1558  else if (db_string_replace (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
1559  {
1560  goto error;
1561  }
1562  break;
1563 
1564  case T_TRANSLATE:
1565  if (REGU_VARIABLE_IS_FLAGED (regu_var, REGU_VARIABLE_INFER_COLLATION) && !DB_IS_NULL (peek_left))
1566  {
1567  TP_DOMAIN_STATUS status = tp_value_change_coll_and_codeset (peek_third, peek_third,
1568  db_get_string_collation (peek_left),
1569  db_get_string_codeset (peek_left));
1570 
1571  if (status != DOMAIN_COMPATIBLE)
1572  {
1574  pr_type_name (DB_VALUE_TYPE (peek_left)));
1575  goto error;
1576  }
1577  }
1578  if (DB_IS_NULL (peek_left))
1579  {
1580  PRIM_SET_NULL (arithptr->value);
1581  }
1582  else if (db_string_translate (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
1583  {
1584  goto error;
1585  }
1586  break;
1587 
1588  case T_ADD_MONTHS:
1589  if (DB_IS_NULL (peek_left))
1590  {
1591  PRIM_SET_NULL (arithptr->value);
1592  }
1593  else if (db_add_months (peek_left, peek_right, arithptr->value) != NO_ERROR)
1594  {
1595  goto error;
1596  }
1597  break;
1598 
1599  case T_LAST_DAY:
1600  if (DB_IS_NULL (peek_right))
1601  {
1602  PRIM_SET_NULL (arithptr->value);
1603  }
1604  else if (db_last_day (peek_right, arithptr->value) != NO_ERROR)
1605  {
1606  goto error;
1607  }
1608  break;
1609 
1610  case T_TIME_FORMAT:
1611  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1612  {
1613  PRIM_SET_NULL (arithptr->value);
1614  }
1615  else if (db_time_format (peek_left, peek_right, peek_third, arithptr->value, arithptr->domain) != NO_ERROR)
1616  {
1617  goto error;
1618  }
1619  break;
1620 
1621  case T_YEAR:
1622  case T_MONTH:
1623  case T_DAY:
1624  if (DB_IS_NULL (peek_right))
1625  {
1626  PRIM_SET_NULL (arithptr->value);
1627  }
1628  else if (get_year_month_or_day (peek_right, arithptr->opcode, arithptr->value) != NO_ERROR)
1629  {
1630  goto error;
1631  }
1632  break;
1633 
1634  case T_HOUR:
1635  case T_MINUTE:
1636  case T_SECOND:
1637  {
1638  /* T_HOUR, T_MINUTE and T_SECOND must be kept consecutive in OPERATOR_TYPE enum */
1639  if (get_hour_minute_or_second (peek_right, arithptr->opcode, arithptr->value) != NO_ERROR)
1640  {
1641  goto error;
1642  }
1643  }
1644  break;
1645 
1646  case T_QUARTER:
1647  if (DB_IS_NULL (peek_right))
1648  {
1649  PRIM_SET_NULL (arithptr->value);
1650  }
1651  else if (db_get_date_quarter (peek_right, arithptr->value) != NO_ERROR)
1652  {
1653  goto error;
1654  }
1655  break;
1656 
1657  case T_WEEKDAY:
1658  case T_DAYOFWEEK:
1659  if (DB_IS_NULL (peek_right))
1660  {
1661  PRIM_SET_NULL (arithptr->value);
1662  }
1663  else if (get_date_weekday (peek_right, arithptr->opcode, arithptr->value) != NO_ERROR)
1664  {
1665  goto error;
1666  }
1667  break;
1668 
1669  case T_DAYOFYEAR:
1670  if (DB_IS_NULL (peek_right))
1671  {
1672  PRIM_SET_NULL (arithptr->value);
1673  }
1674  else if (db_get_date_dayofyear (peek_right, arithptr->value) != NO_ERROR)
1675  {
1676  goto error;
1677  }
1678  break;
1679 
1680  case T_TODAYS:
1681  if (DB_IS_NULL (peek_right))
1682  {
1683  PRIM_SET_NULL (arithptr->value);
1684  }
1685  else if (db_get_date_totaldays (peek_right, arithptr->value) != NO_ERROR)
1686  {
1687  goto error;
1688  }
1689  break;
1690 
1691  case T_FROMDAYS:
1692  if (DB_IS_NULL (peek_right))
1693  {
1694  PRIM_SET_NULL (arithptr->value);
1695  }
1696  else if (db_get_date_from_days (peek_right, arithptr->value) != NO_ERROR)
1697  {
1698  goto error;
1699  }
1700  break;
1701 
1702  case T_TIMETOSEC:
1703  if (DB_IS_NULL (peek_right))
1704  {
1705  PRIM_SET_NULL (arithptr->value);
1706  }
1707  else if (db_convert_time_to_sec (peek_right, arithptr->value) != NO_ERROR)
1708  {
1709  goto error;
1710  }
1711  break;
1712 
1713  case T_SECTOTIME:
1714  if (DB_IS_NULL (peek_right))
1715  {
1716  PRIM_SET_NULL (arithptr->value);
1717  }
1718  else if (db_convert_sec_to_time (peek_right, arithptr->value) != NO_ERROR)
1719  {
1720  goto error;
1721  }
1722  break;
1723 
1724  case T_TIMESTAMP:
1725  if (DB_IS_NULL (peek_left) || (peek_right != NULL && DB_IS_NULL (peek_right)))
1726  {
1727  PRIM_SET_NULL (arithptr->value);
1728  }
1729  else
1730  {
1731  if (db_timestamp (peek_left, peek_right, arithptr->value) != NO_ERROR)
1732  {
1733  goto error;
1734  }
1735  }
1736  break;
1737 
1738  case T_LIKE_LOWER_BOUND:
1739  case T_LIKE_UPPER_BOUND:
1740  if (DB_IS_NULL (peek_left))
1741  {
1742  PRIM_SET_NULL (arithptr->value);
1743  }
1744  else
1745  {
1746  const bool compute_lower_bound = (arithptr->opcode == T_LIKE_LOWER_BOUND);
1747 
1748  if (db_like_bound (peek_left, peek_right, arithptr->value, compute_lower_bound) != NO_ERROR)
1749  {
1750  goto error;
1751  }
1752  }
1753  break;
1754 
1755  case T_MAKEDATE:
1756  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1757  {
1758  PRIM_SET_NULL (arithptr->value);
1759  }
1760  else
1761  {
1762  if (db_add_days_to_year (peek_left, peek_right, arithptr->value) != NO_ERROR)
1763  {
1764  goto error;
1765  }
1766  }
1767  break;
1768 
1769  case T_ADDTIME:
1770  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1771  {
1772  PRIM_SET_NULL (arithptr->value);
1773  }
1774  else
1775  {
1776  if (db_add_time (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
1777  {
1778  goto error;
1779  }
1780  }
1781  break;
1782 
1783  case T_MAKETIME:
1784  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
1785  {
1786  PRIM_SET_NULL (arithptr->value);
1787  }
1788  else
1789  {
1790  if (db_convert_to_time (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
1791  {
1792  goto error;
1793  }
1794  }
1795  break;
1796 
1797  case T_WEEK:
1798  if (DB_IS_NULL (peek_left))
1799  {
1800  PRIM_SET_NULL (arithptr->value);
1801  }
1802  else
1803  {
1804  if (db_get_date_week (peek_left, peek_right, arithptr->value) != NO_ERROR)
1805  {
1806  goto error;
1807  }
1808  }
1809  break;
1810 
1811  case T_UNIX_TIMESTAMP:
1812  if (arithptr->rightptr)
1813  {
1814  if (DB_IS_NULL (peek_right))
1815  {
1816  PRIM_SET_NULL (arithptr->value);
1817  }
1818  else if (db_unix_timestamp (peek_right, arithptr->value) != NO_ERROR)
1819  {
1820  goto error;
1821  }
1822  }
1823  else
1824  {
1826  DB_DATETIME sys_datetime;
1827  DB_TIME db_time;
1828  time_t sec;
1829  int millisec;
1830  struct tm *c_time_struct, tm_val;
1831 
1832  /* get the local time of the system */
1833  util_get_second_and_ms_since_epoch (&sec, &millisec);
1834  c_time_struct = localtime_r (&sec, &tm_val);
1835 
1836  if (c_time_struct != NULL)
1837  {
1838  db_datetime_encode (&sys_datetime, c_time_struct->tm_mon + 1, c_time_struct->tm_mday,
1839  c_time_struct->tm_year + 1900, c_time_struct->tm_hour, c_time_struct->tm_min,
1840  c_time_struct->tm_sec, millisec);
1841  }
1842 
1843  db_time = sys_datetime.time / 1000;
1844 
1845  /* convert to timestamp (this takes into account leap second) */
1846  db_timestamp_encode_sys (&sys_datetime.date, &db_time, &db_timestamp, NULL);
1847 
1848  db_make_int (arithptr->value, db_timestamp);
1849  }
1850  break;
1851 
1852  case T_MONTHS_BETWEEN:
1853  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1854  {
1855  PRIM_SET_NULL (arithptr->value);
1856  }
1857  else if (db_months_between (peek_left, peek_right, arithptr->value) != NO_ERROR)
1858  {
1859  goto error;
1860  }
1861  break;
1862 
1863  case T_ATAN2:
1864  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1865  {
1866  PRIM_SET_NULL (arithptr->value);
1867  }
1868  else if (db_atan2_dbval (arithptr->value, peek_left, peek_right) != NO_ERROR)
1869  {
1870  goto error;
1871  }
1872  break;
1873 
1874  case T_ATAN:
1875  if (DB_IS_NULL (peek_right))
1876  {
1877  PRIM_SET_NULL (arithptr->value);
1878  }
1879  else if (db_atan_dbval (arithptr->value, peek_right) != NO_ERROR)
1880  {
1881  goto error;
1882  }
1883  break;
1884 
1885  case T_FORMAT:
1886  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1887  {
1888  PRIM_SET_NULL (arithptr->value);
1889  }
1890  else if (db_format (peek_left, peek_right, peek_third, arithptr->value, arithptr->domain) != NO_ERROR)
1891  {
1892  goto error;
1893  }
1894  break;
1895 
1896  case T_DATE_FORMAT:
1897  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1898  {
1899  PRIM_SET_NULL (arithptr->value);
1900  }
1901  else if (db_date_format (peek_left, peek_right, peek_third, arithptr->value, arithptr->domain) != NO_ERROR)
1902  {
1903  goto error;
1904  }
1905 
1906  break;
1907 
1908  case T_STR_TO_DATE:
1909  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
1910  {
1911  PRIM_SET_NULL (arithptr->value);
1912  }
1913  else if (db_str_to_date (peek_left, peek_right, peek_third, arithptr->value, regu_var->domain) != NO_ERROR)
1914  {
1915  goto error;
1916  }
1917  break;
1918 
1919  case T_ADDDATE:
1920  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1921  {
1922  PRIM_SET_NULL (arithptr->value);
1923  }
1924  else if (db_date_add_interval_days (arithptr->value, peek_left, peek_right) != NO_ERROR)
1925  {
1926  goto error;
1927  }
1928  break;
1929 
1930  case T_DATE_ADD:
1931  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1932  {
1933  PRIM_SET_NULL (arithptr->value);
1934  }
1935  else
1936  {
1937  int unit = db_get_int (peek_third);
1938  if (db_date_add_interval_expr (arithptr->value, peek_left, peek_right, unit) != NO_ERROR)
1939  {
1940  goto error;
1941  }
1942  }
1943  break;
1944 
1945  case T_SUBDATE:
1946  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1947  {
1948  PRIM_SET_NULL (arithptr->value);
1949  }
1950  else if (db_date_sub_interval_days (arithptr->value, peek_left, peek_right) != NO_ERROR)
1951  {
1952  goto error;
1953  }
1954  break;
1955 
1956  case T_DATEDIFF:
1957  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1958  {
1959  PRIM_SET_NULL (arithptr->value);
1960  }
1961  else if (db_date_diff (peek_left, peek_right, arithptr->value) != NO_ERROR)
1962  {
1963  goto error;
1964  }
1965  break;
1966 
1967  case T_TIMEDIFF:
1968  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
1969  {
1970  PRIM_SET_NULL (arithptr->value);
1971  }
1972  else if (db_time_diff (peek_left, peek_right, arithptr->value) != NO_ERROR)
1973  {
1974  goto error;
1975  }
1976  break;
1977 
1978  case T_DATE_SUB:
1979  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
1980  {
1981  PRIM_SET_NULL (arithptr->value);
1982  }
1983  else
1984  {
1985  int unit = db_get_int (peek_third);
1986 
1987  if (db_date_sub_interval_expr (arithptr->value, peek_left, peek_right, unit) != NO_ERROR)
1988  {
1989  goto error;
1990  }
1991  }
1992  break;
1993 
1994  case T_SYS_DATE:
1996  break;
1997 
1998  case T_SYS_TIME:
1999  {
2000  DB_TIME db_time;
2001 
2002  db_time = vd->sys_datetime.time / 1000;
2003  db_value_put_encoded_time (arithptr->value, &db_time);
2004  break;
2005  }
2006 
2007  case T_SYS_DATETIME:
2008  {
2009  db_make_datetime (arithptr->value, &vd->sys_datetime);
2010  }
2011  break;
2012 
2013  case T_SYS_TIMESTAMP:
2014  {
2016  DB_TIME db_time;
2017 
2018  db_time = vd->sys_datetime.time / 1000;
2019 
2020  db_timestamp_encode_ses (&vd->sys_datetime.date, &db_time, &db_timestamp, NULL);
2021  db_make_timestamp (arithptr->value, db_timestamp);
2022  }
2023  break;
2024 
2025  case T_CURRENT_DATE:
2026  {
2027  TZ_REGION system_tz_region, session_tz_region;
2028  DB_DATETIME dest_dt;
2029  int err_status = 0;
2030 
2031  tz_get_system_tz_region (&system_tz_region);
2032  tz_get_session_tz_region (&session_tz_region);
2033  dest_dt = vd->sys_datetime;
2034  err_status =
2035  tz_conv_tz_datetime_w_region (&vd->sys_datetime, &system_tz_region, &session_tz_region, &dest_dt, NULL, NULL);
2036  if (err_status != NO_ERROR)
2037  {
2038  return err_status;
2039  }
2040  db_value_put_encoded_date (arithptr->value, &dest_dt.date);
2041  break;
2042  }
2043 
2044  case T_CURRENT_TIME:
2045  {
2046  DB_TIME cur_time, db_time;
2047  const char *t_source, *t_dest;
2048  int err_status = 0, len_source, len_dest;
2049 
2050  t_source = tz_get_system_timezone ();
2051  t_dest = tz_get_session_local_timezone ();
2052  len_source = (int) strlen (t_source);
2053  len_dest = (int) strlen (t_dest);
2054  db_time = vd->sys_datetime.time / 1000;
2055 
2056  err_status = tz_conv_tz_time_w_zone_name (&db_time, t_source, len_source, t_dest, len_dest, &cur_time);
2057  if (err_status != NO_ERROR)
2058  {
2059  return err_status;
2060  }
2061  db_value_put_encoded_time (arithptr->value, &cur_time);
2062  break;
2063  }
2064 
2065  case T_CURRENT_TIMESTAMP:
2066  {
2068  DB_TIME db_time;
2069 
2070  db_time = vd->sys_datetime.time / 1000;
2071 
2072  db_timestamp_encode_sys (&vd->sys_datetime.date, &db_time, &db_timestamp, NULL);
2073 
2074  db_make_timestamp (arithptr->value, db_timestamp);
2075  }
2076  break;
2077 
2078  case T_CURRENT_DATETIME:
2079  {
2080  TZ_REGION system_tz_region, session_tz_region;
2081  DB_DATETIME dest_dt;
2082  int err_status = 0;
2083 
2084  tz_get_system_tz_region (&system_tz_region);
2085  tz_get_session_tz_region (&session_tz_region);
2086  err_status =
2087  tz_conv_tz_datetime_w_region (&vd->sys_datetime, &system_tz_region, &session_tz_region, &dest_dt, NULL, NULL);
2088  if (err_status != NO_ERROR)
2089  {
2090  return err_status;
2091  }
2092  db_make_datetime (arithptr->value, &dest_dt);
2093  }
2094  break;
2095 
2096  case T_UTC_TIME:
2097  {
2098  DB_TIME db_time;
2099  db_time = (DB_TIME) (vd->sys_epochtime % SECONDS_OF_ONE_DAY);
2100  db_value_put_encoded_time (arithptr->value, &db_time);
2101  break;
2102  }
2103 
2104  case T_UTC_DATE:
2105  {
2106  DB_DATE date;
2107  int year, month, day, hour, minute, second;
2108 
2109  tz_timestamp_decode_no_leap_sec (vd->sys_epochtime, &year, &month, &day, &hour, &minute, &second);
2110  date = julian_encode (month + 1, day, year);
2111  db_value_put_encoded_date (arithptr->value, &date);
2112  break;
2113  }
2114 
2116  db_make_int (arithptr->value, logtb_find_current_tranid (thread_p));
2117  break;
2118 
2119  case T_TO_CHAR:
2120  if (DB_IS_NULL (peek_left))
2121  {
2122  PRIM_SET_NULL (arithptr->value);
2123  }
2124  else if (db_to_char (peek_left, peek_right, peek_third, arithptr->value, arithptr->domain) != NO_ERROR)
2125  {
2126  goto error;
2127  }
2128 
2129  break;
2130 
2131  case T_BLOB_TO_BIT:
2132  if (DB_IS_NULL (peek_left))
2133  {
2134  PRIM_SET_NULL (arithptr->value);
2135  }
2136  else if (db_blob_to_bit (peek_left, peek_right, arithptr->value) != NO_ERROR)
2137  {
2138  goto error;
2139  }
2140 
2141  break;
2142 
2143  case T_CLOB_TO_CHAR:
2144  if (DB_IS_NULL (peek_left))
2145  {
2146  PRIM_SET_NULL (arithptr->value);
2147  }
2148  else if (db_clob_to_char (peek_left, peek_right, arithptr->value) != NO_ERROR)
2149  {
2150  goto error;
2151  }
2152 
2153  break;
2154 
2155  case T_BIT_TO_BLOB:
2156  if (DB_IS_NULL (peek_left))
2157  {
2158  PRIM_SET_NULL (arithptr->value);
2159  }
2160  else if (DB_VALUE_DOMAIN_TYPE (peek_left) == DB_TYPE_BIT || DB_VALUE_DOMAIN_TYPE (peek_left) == DB_TYPE_VARBIT)
2161  {
2162  if (db_bit_to_blob (peek_left, arithptr->value) != NO_ERROR)
2163  {
2164  goto error;
2165  }
2166  }
2167  else /* (DB_VALUE_DOMAIN_TYPE (peek_left) == DB_TYPE_CHAR || DB_TYPE_VARCHAR) */
2168  {
2169  if (db_char_to_blob (peek_left, arithptr->value) != NO_ERROR)
2170  {
2171  goto error;
2172  }
2173  }
2174 
2175  break;
2176 
2177  case T_CHAR_TO_CLOB:
2178  if (DB_IS_NULL (peek_left))
2179  {
2180  PRIM_SET_NULL (arithptr->value);
2181  }
2182  else if (db_char_to_clob (peek_left, arithptr->value) != NO_ERROR)
2183  {
2184  goto error;
2185  }
2186 
2187  break;
2188 
2189  case T_LOB_LENGTH:
2190  if (DB_IS_NULL (peek_left))
2191  {
2192  PRIM_SET_NULL (arithptr->value);
2193  }
2194  else if (DB_VALUE_DOMAIN_TYPE (peek_left) == DB_TYPE_BLOB)
2195  {
2196 
2197  if (db_blob_length (peek_left, arithptr->value) != NO_ERROR)
2198  {
2199  goto error;
2200  }
2201  }
2202  else /* (DB_VALUE_DOMAIN_TYPE (peek_left) == DB_TYPE_BLOB) */
2203  {
2204  if (db_clob_length (peek_left, arithptr->value) != NO_ERROR)
2205  {
2206  goto error;
2207  }
2208  }
2209 
2210  break;
2211 
2212  case T_TO_DATE:
2213  if (DB_IS_NULL (peek_left))
2214  {
2215  PRIM_SET_NULL (arithptr->value);
2216  }
2217  else if (db_to_date (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
2218  {
2219  goto error;
2220  }
2221  break;
2222 
2223  case T_TO_TIME:
2224  if (DB_IS_NULL (peek_left))
2225  {
2226  PRIM_SET_NULL (arithptr->value);
2227  }
2228  else if (db_to_time (peek_left, peek_right, peek_third, DB_TYPE_TIME, arithptr->value) != NO_ERROR)
2229  {
2230  goto error;
2231  }
2232  break;
2233 
2234  case T_TO_TIMESTAMP:
2235  if (DB_IS_NULL (peek_left))
2236  {
2237  PRIM_SET_NULL (arithptr->value);
2238  }
2239  else if (db_to_timestamp (peek_left, peek_right, peek_third, DB_TYPE_TIMESTAMP, arithptr->value) != NO_ERROR)
2240  {
2241  goto error;
2242  }
2243  break;
2244 
2245  case T_TO_DATETIME:
2246  if (DB_IS_NULL (peek_left))
2247  {
2248  PRIM_SET_NULL (arithptr->value);
2249  }
2250  else if (db_to_datetime (peek_left, peek_right, peek_third, DB_TYPE_DATETIME, arithptr->value) != NO_ERROR)
2251  {
2252  goto error;
2253  }
2254  break;
2255 
2256  case T_TO_NUMBER:
2257  if (DB_IS_NULL (peek_left))
2258  {
2259  PRIM_SET_NULL (arithptr->value);
2260  }
2261  else
2262  {
2263  if (db_to_number (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
2264  {
2265  goto error;
2266  }
2267  regu_var->domain->precision = arithptr->value->domain.numeric_info.precision;
2268  regu_var->domain->scale = arithptr->value->domain.numeric_info.scale;
2269  }
2270  break;
2271 
2272  case T_CURRENT_VALUE:
2273  /* serial.current_value() is not constant */
2276  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
2277  {
2278  PRIM_SET_NULL (arithptr->value);
2279  }
2280  else
2281  {
2282  OID *serial_oid;
2283  int cached_num;
2284 
2285  serial_oid = db_get_oid (peek_left);
2286  cached_num = db_get_int (peek_right);
2287 
2288  if (xserial_get_current_value (thread_p, arithptr->value, serial_oid, cached_num) != NO_ERROR)
2289  {
2290  goto error;
2291  }
2292  }
2293  break;
2294 
2295  case T_NEXT_VALUE:
2296  /* serial.next_value() is not constant */
2299  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
2300  {
2301  PRIM_SET_NULL (arithptr->value);
2302  }
2303  else
2304  {
2305  OID *serial_oid;
2306  int cached_num;
2307  int num_alloc;
2308 
2309  serial_oid = db_get_oid (peek_left);
2310  cached_num = db_get_int (peek_right);
2311  num_alloc = db_get_int (peek_third);
2312 
2313  if (xserial_get_next_value (thread_p, arithptr->value, serial_oid, cached_num, num_alloc, GENERATE_SERIAL,
2314  false) != NO_ERROR)
2315  {
2316  goto error;
2317  }
2318  }
2319  break;
2320 
2321  case T_CAST:
2322  case T_CAST_WRAP:
2324  {
2325  pr_clone_value (peek_right, arithptr->value);
2326 
2327  if (TP_IS_CHAR_TYPE (TP_DOMAIN_TYPE (regu_var->domain)))
2328  {
2329  if (!DB_IS_NULL (arithptr->value))
2330  {
2331  assert (TP_IS_CHAR_TYPE (DB_VALUE_TYPE (arithptr->value)));
2332  assert (regu_var->domain->codeset == db_get_string_codeset (arithptr->value));
2333  }
2334  db_string_put_cs_and_collation (arithptr->value, regu_var->domain->codeset,
2335  regu_var->domain->collation_id);
2336  }
2337  else
2338  {
2339  assert (TP_DOMAIN_TYPE (regu_var->domain) == DB_TYPE_ENUMERATION);
2340 
2341  if (!DB_IS_NULL (arithptr->value))
2342  {
2344  assert (regu_var->domain->codeset == db_get_enum_codeset (arithptr->value));
2345  }
2346  db_enum_put_cs_and_collation (arithptr->value, regu_var->domain->codeset, regu_var->domain->collation_id);
2347 
2348  }
2349  }
2350  else
2351  {
2353  {
2354  dom_status = tp_value_cast (peek_right, arithptr->value, arithptr->domain, false);
2355  }
2356  else
2357  {
2358  dom_status = tp_value_cast_force (peek_right, arithptr->value, arithptr->domain, false);
2359  }
2360 
2361  if (dom_status != DOMAIN_COMPATIBLE)
2362  {
2363  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, arithptr->domain);
2364  goto error;
2365  }
2366  }
2367  break;
2368 
2369  case T_CAST_NOFAIL:
2371  {
2372  pr_clone_value (peek_right, arithptr->value);
2373 
2374  if (TP_IS_CHAR_TYPE (TP_DOMAIN_TYPE (regu_var->domain)))
2375  {
2376  if (!DB_IS_NULL (arithptr->value))
2377  {
2378  assert (TP_IS_CHAR_TYPE (DB_VALUE_TYPE (arithptr->value)));
2379  assert (regu_var->domain->codeset == db_get_string_codeset (arithptr->value));
2380  }
2381  db_string_put_cs_and_collation (arithptr->value, regu_var->domain->codeset,
2382  regu_var->domain->collation_id);
2383  }
2384  else
2385  {
2386  assert (TP_DOMAIN_TYPE (regu_var->domain) == DB_TYPE_ENUMERATION);
2387 
2388  if (!DB_IS_NULL (arithptr->value))
2389  {
2391  assert (regu_var->domain->codeset == db_get_enum_codeset (arithptr->value));
2392  }
2393  db_enum_put_cs_and_collation (arithptr->value, regu_var->domain->codeset, regu_var->domain->collation_id);
2394 
2395  }
2396  }
2397  else
2398  {
2399  TP_DOMAIN_STATUS status;
2400 
2401  status = tp_value_cast (peek_right, arithptr->value, arithptr->domain, false);
2402  if (status != NO_ERROR)
2403  {
2404  PRIM_SET_NULL (arithptr->value);
2405  }
2406  }
2407  break;
2408 
2409  case T_CASE:
2410  case T_DECODE:
2411  case T_IF:
2412  /* set pred is not constant */
2415  /* fetch values */
2416  switch (eval_pred (thread_p, arithptr->pred, vd, obj_oid))
2417  {
2418  case V_FALSE:
2419  case V_UNKNOWN: /* unknown pred result, including cases of NULL pred operands */
2420  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
2421  {
2422  goto error;
2423  }
2424  break;
2425 
2426  case V_TRUE:
2427  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
2428  {
2429  goto error;
2430  }
2431  break;
2432 
2433  default:
2434  goto error;
2435  }
2436 
2437  dom_status = tp_value_auto_cast (peek_left, arithptr->value, regu_var->domain);
2438  if (dom_status != DOMAIN_COMPATIBLE)
2439  {
2440  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_left, regu_var->domain);
2441  goto error;
2442  }
2443  break;
2444 
2445  case T_PREDICATE:
2446  /* set pred is not constant */
2449  /* return 0,1 or NULL accordingly */
2450  peek_left = &tmp_value;
2451 
2452  switch (eval_pred (thread_p, arithptr->pred, vd, obj_oid))
2453  {
2454  case V_UNKNOWN:
2455  db_make_null (peek_left);
2456  break;
2457  case V_FALSE:
2458  db_make_int (peek_left, 0);
2459  break;
2460  case V_TRUE:
2461  db_make_int (peek_left, 1);
2462  break;
2463  default:
2464  goto error;
2465  }
2466 
2467  dom_status = tp_value_auto_cast (peek_left, arithptr->value, regu_var->domain);
2468  if (dom_status != DOMAIN_COMPATIBLE)
2469  {
2470  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_left, regu_var->domain);
2471  goto error;
2472  }
2473  break;
2474 
2475  case T_NVL:
2476  case T_IFNULL:
2477  case T_COALESCE:
2478  {
2479  DB_VALUE *src;
2480  TP_DOMAIN *target_domain;
2481 
2482  target_domain = regu_var->domain;
2483 
2484  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
2485  {
2486  goto error;
2487  }
2488 
2489  if (DB_IS_NULL (peek_left) || target_domain == NULL)
2490  {
2491  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
2492  {
2493  goto error;
2494  }
2495  }
2496 
2497  if (target_domain == NULL)
2498  {
2499  TP_DOMAIN *arg1, *arg2, tmp_arg1, tmp_arg2;
2500 
2501  arg1 = tp_domain_resolve_value (peek_left, &tmp_arg1);
2502  arg2 = tp_domain_resolve_value (peek_right, &tmp_arg2);
2503 
2504  target_domain = tp_infer_common_domain (arg1, arg2);
2505  }
2506 
2507  src = DB_IS_NULL (peek_left) ? peek_right : peek_left;
2508  dom_status = tp_value_cast (src, arithptr->value, target_domain, false);
2509  if (dom_status != DOMAIN_COMPATIBLE)
2510  {
2511  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, src, target_domain);
2512  goto error;
2513  }
2514  }
2515  break;
2516  case T_NVL2:
2517  {
2518  DB_VALUE *src;
2519  TP_DOMAIN *target_domain;
2520 
2521  target_domain = regu_var->domain;
2522 
2523  if (fetch_peek_dbval (thread_p, arithptr->leftptr, vd, NULL, obj_oid, tpl, &peek_left) != NO_ERROR)
2524  {
2525  goto error;
2526  }
2527 
2528  if (target_domain == NULL)
2529  {
2530  TP_DOMAIN *arg1, *arg2, *arg3, tmp_arg1, tmp_arg2, tmp_arg3;
2531 
2532  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
2533  {
2534  goto error;
2535  }
2536 
2537  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
2538  {
2539  goto error;
2540  }
2541 
2542  arg1 = tp_domain_resolve_value (peek_left, &tmp_arg1);
2543  arg2 = tp_domain_resolve_value (peek_right, &tmp_arg2);
2544 
2545  target_domain = tp_infer_common_domain (arg1, arg2);
2546 
2547  arg3 = NULL;
2548  if (peek_third)
2549  {
2550  TP_DOMAIN *tmp_domain;
2551 
2552  arg3 = tp_domain_resolve_value (peek_third, &tmp_arg3);
2553  tmp_domain = tp_infer_common_domain (target_domain, arg3);
2554 
2555  target_domain = tmp_domain;
2556  }
2557  }
2558 
2559  if (DB_IS_NULL (peek_left))
2560  {
2561  if (peek_third == NULL)
2562  {
2563  if (fetch_peek_dbval (thread_p, arithptr->thirdptr, vd, NULL, obj_oid, tpl, &peek_third) != NO_ERROR)
2564  {
2565  goto error;
2566  }
2567  }
2568  src = peek_third;
2569  }
2570  else
2571  {
2572  if (peek_right == NULL)
2573  {
2574  if (fetch_peek_dbval (thread_p, arithptr->rightptr, vd, NULL, obj_oid, tpl, &peek_right) != NO_ERROR)
2575  {
2576  goto error;
2577  }
2578  }
2579 
2580  src = peek_right;
2581  }
2582 
2583  dom_status = tp_value_cast (src, arithptr->value, target_domain, false);
2584  if (dom_status != DOMAIN_COMPATIBLE)
2585  {
2586  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, src, target_domain);
2587 
2588  goto error;
2589  }
2590  }
2591  break;
2592 
2593  case T_ISNULL:
2594  if (DB_IS_NULL (peek_right))
2595  {
2596  db_make_int (arithptr->value, 1);
2597  }
2598  else
2599  {
2600  db_make_int (arithptr->value, 0);
2601  }
2602  break;
2603 
2604  case T_CONCAT:
2605  if (arithptr->rightptr != NULL)
2606  {
2607  if (qdata_strcat_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
2608  {
2609  goto error;
2610  }
2611  }
2612  else
2613  {
2614  dom_status = tp_value_auto_cast (peek_left, arithptr->value, regu_var->domain);
2615  if (dom_status != DOMAIN_COMPATIBLE)
2616  {
2617  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_left, regu_var->domain);
2618  goto error;
2619  }
2620  }
2621  break;
2622 
2623  case T_CONCAT_WS:
2624  if (DB_IS_NULL (peek_third))
2625  {
2626  PRIM_SET_NULL (arithptr->value);
2627  break;
2628  }
2629  if (arithptr->rightptr != NULL)
2630  {
2631  if (DB_IS_NULL (peek_left) && DB_IS_NULL (peek_right))
2632  {
2633  PRIM_SET_NULL (arithptr->value);
2634  }
2635  else if (DB_IS_NULL (peek_left))
2636  {
2637  dom_status = tp_value_auto_cast (peek_right, arithptr->value, regu_var->domain);
2638  if (dom_status != DOMAIN_COMPATIBLE)
2639  {
2640  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, regu_var->domain);
2641  goto error;
2642  }
2643  }
2644  else if (DB_IS_NULL (peek_right))
2645  {
2646  dom_status = tp_value_auto_cast (peek_left, arithptr->value, regu_var->domain);
2647  if (dom_status != DOMAIN_COMPATIBLE)
2648  {
2649  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_left, regu_var->domain);
2650  goto error;
2651  }
2652  }
2653  else
2654  {
2655  DB_VALUE tmp_val;
2656 
2657  db_make_null (&tmp_val);
2658  if (qdata_strcat_dbval (peek_left, peek_third, &tmp_val, regu_var->domain) != NO_ERROR)
2659  {
2660  goto error;
2661  }
2662  if (qdata_strcat_dbval (&tmp_val, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
2663  {
2664  (void) pr_clear_value (&tmp_val);
2665  goto error;
2666  }
2667  (void) pr_clear_value (&tmp_val);
2668  }
2669  }
2670  else
2671  {
2672  if (DB_IS_NULL (peek_left))
2673  {
2674  PRIM_SET_NULL (arithptr->value);
2675  }
2676  else
2677  {
2678  dom_status = tp_value_auto_cast (peek_left, arithptr->value, regu_var->domain);
2679  if (dom_status != DOMAIN_COMPATIBLE)
2680  {
2681  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_left, regu_var->domain);
2682  goto error;
2683  }
2684  }
2685  }
2686  break;
2687 
2688  case T_FIELD:
2689  if (DB_IS_NULL (peek_third))
2690  {
2691  db_make_int (arithptr->value, 0);
2692  break;
2693  }
2695  {
2696  bool can_compare = false;
2697  int cmp_res = DB_UNK;
2698 
2699  cmp_res = tp_value_compare_with_error (peek_third, peek_left, 1, 0, &can_compare);
2700  if (cmp_res == DB_EQ)
2701  {
2702  db_make_int (arithptr->value, 1);
2703  break;
2704  }
2705  else if (cmp_res == DB_UNK && can_compare == false)
2706  {
2707  goto error;
2708  }
2709 
2710 
2711  cmp_res = tp_value_compare_with_error (peek_third, peek_right, 1, 0, &can_compare);
2712  if (cmp_res == DB_EQ)
2713  {
2714  db_make_int (arithptr->value, 2);
2715  break;
2716  }
2717  else if (cmp_res == DB_UNK && can_compare == false)
2718  {
2719  goto error;
2720  }
2721 
2723  {
2724  /* we have a T_FIELD parent, return level */
2725  db_make_int (arithptr->value, -3);
2726  }
2727  else
2728  {
2729  /* no parent and no match */
2730  db_make_int (arithptr->value, 0);
2731  }
2732  }
2733  else
2734  {
2735  int i = db_get_int (peek_left);
2736  if (i > 0)
2737  {
2738  db_make_int (arithptr->value, i);
2739  }
2740  else
2741  {
2742  bool can_compare = false;
2743  int cmp_res = DB_UNK;
2744 
2745  cmp_res = tp_value_compare_with_error (peek_third, peek_right, 1, 0, &can_compare);
2746  if (cmp_res == DB_EQ)
2747  {
2748  /* match */
2749  db_make_int (arithptr->value, -i);
2750  }
2751  else if (cmp_res == DB_UNK && can_compare == false)
2752  {
2753  goto error;
2754  }
2755  else
2756  {
2758  {
2759  /* we have a T_FIELD parent, return level */
2760  db_make_int (arithptr->value, i - 1);
2761  }
2762  else
2763  {
2764  /* no parent and no match */
2765  db_make_int (arithptr->value, 0);
2766  }
2767  }
2768  }
2769  }
2770  break;
2771 
2772  case T_REPEAT:
2773  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
2774  {
2775  PRIM_SET_NULL (arithptr->value);
2776  }
2777  else
2778  {
2779  if (db_string_repeat (peek_left, peek_right, arithptr->value) != NO_ERROR)
2780  {
2781  goto error;
2782  }
2783  }
2784  break;
2785 
2786  case T_LEFT:
2787  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
2788  {
2789  PRIM_SET_NULL (arithptr->value);
2790  }
2791  else
2792  {
2793  DB_VALUE tmp_val, tmp_val2;
2794 
2795  dom_status = tp_value_auto_cast (peek_right, &tmp_val2, &tp_Integer_domain);
2796  if (dom_status != DOMAIN_COMPATIBLE)
2797  {
2798  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, &tp_Integer_domain);
2799  goto error;
2800  }
2801 
2802  db_make_int (&tmp_val, 0);
2803  if (db_string_substring (SUBSTRING, peek_left, &tmp_val, &tmp_val2, arithptr->value) != NO_ERROR)
2804  {
2805  goto error;
2806  }
2807  }
2808  break;
2809 
2810  case T_RIGHT:
2811  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
2812  {
2813  PRIM_SET_NULL (arithptr->value);
2814  }
2815  else
2816  {
2817  DB_VALUE tmp_val, tmp_val2;
2818 
2819  if (QSTR_IS_BIT (TP_DOMAIN_TYPE (arithptr->leftptr->domain)))
2820  {
2821  if (db_string_bit_length (peek_left, &tmp_val) != NO_ERROR)
2822  {
2823  goto error;
2824  }
2825  }
2826  else
2827  {
2828  if (db_string_char_length (peek_left, &tmp_val) != NO_ERROR)
2829  {
2830  goto error;
2831  }
2832  }
2833  if (DB_IS_NULL (&tmp_val))
2834  {
2835  PRIM_SET_NULL (arithptr->value);
2836  break;
2837  }
2838 
2839  dom_status = tp_value_auto_cast (peek_right, &tmp_val2, &tp_Integer_domain);
2840  if (dom_status != DOMAIN_COMPATIBLE)
2841  {
2842  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, &tp_Integer_domain);
2843  goto error;
2844  }
2845  /* If len, defined as second argument, is negative value, RIGHT function returns the entire string. It's same
2846  * behavior with LEFT and SUBSTRING. */
2847  if (db_get_int (&tmp_val2) < 0)
2848  {
2849  db_make_int (&tmp_val, 0);
2850  }
2851  else
2852  {
2853  db_make_int (&tmp_val, db_get_int (&tmp_val) - db_get_int (&tmp_val2) + 1);
2854  }
2855  if (db_string_substring (SUBSTRING, peek_left, &tmp_val, &tmp_val2, arithptr->value) != NO_ERROR)
2856  {
2857  goto error;
2858  }
2859  }
2860  break;
2861 
2862  case T_LOCATE:
2863  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || (arithptr->thirdptr && DB_IS_NULL (peek_third)))
2864  {
2865  PRIM_SET_NULL (arithptr->value);
2866  }
2867  else
2868  {
2869  if (!arithptr->thirdptr)
2870  {
2871  if (db_string_position (peek_left, peek_right, arithptr->value) != NO_ERROR)
2872  {
2873  goto error;
2874  }
2875  }
2876  else
2877  {
2878  DB_VALUE tmp_len, tmp_val, tmp_arg3;
2879  int tmp;
2880 
2881  db_make_null (&tmp_val);
2882 
2883  tmp = db_get_int (peek_third);
2884  if (tmp < 1)
2885  {
2886  db_make_int (&tmp_arg3, 1);
2887  }
2888  else
2889  {
2890  db_make_int (&tmp_arg3, tmp);
2891  }
2892 
2893  if (db_string_char_length (peek_right, &tmp_len) != NO_ERROR)
2894  {
2895  goto error;
2896  }
2897  if (DB_IS_NULL (&tmp_len))
2898  {
2899  goto error;
2900  }
2901 
2902  db_make_int (&tmp_len, db_get_int (&tmp_len) - db_get_int (&tmp_arg3) + 1);
2903 
2904  if (db_string_substring (SUBSTRING, peek_right, &tmp_arg3, &tmp_len, &tmp_val) != NO_ERROR)
2905  {
2906  goto error;
2907  }
2908 
2909  if (db_string_position (peek_left, &tmp_val, arithptr->value) != NO_ERROR)
2910  {
2911  (void) pr_clear_value (&tmp_val);
2912  goto error;
2913  }
2914  if (db_get_int (arithptr->value) > 0)
2915  {
2916  db_make_int (arithptr->value, db_get_int (arithptr->value) + db_get_int (&tmp_arg3) - 1);
2917  }
2918 
2919  (void) pr_clear_value (&tmp_val);
2920  }
2921  }
2922  break;
2923 
2924  case T_SUBSTRING_INDEX:
2925  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
2926  {
2927  PRIM_SET_NULL (arithptr->value);
2928  }
2929  else
2930  {
2931  if (db_string_substring_index (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
2932  {
2933  goto error;
2934  }
2935  }
2936  break;
2937 
2938  case T_MID:
2939  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
2940  {
2941  PRIM_SET_NULL (arithptr->value);
2942  }
2943  else
2944  {
2945  DB_VALUE tmp_len, tmp_arg2, tmp_arg3;
2946  int pos, len;
2947 
2948  pos = db_get_int (peek_right);
2949  len = db_get_int (peek_third);
2950 
2951  if (pos < 0)
2952  {
2953  if (QSTR_IS_BIT (TP_DOMAIN_TYPE (arithptr->leftptr->domain)))
2954  {
2955  if (db_string_bit_length (peek_left, &tmp_len) != NO_ERROR)
2956  {
2957  goto error;
2958  }
2959  }
2960  else
2961  {
2962  if (db_string_char_length (peek_left, &tmp_len) != NO_ERROR)
2963  {
2964  goto error;
2965  }
2966  }
2967  if (DB_IS_NULL (&tmp_len))
2968  {
2969  goto error;
2970  }
2971  pos = pos + db_get_int (&tmp_len) + 1;
2972  }
2973 
2974  if (pos < 1)
2975  {
2976  db_make_int (&tmp_arg2, 1);
2977  }
2978  else
2979  {
2980  db_make_int (&tmp_arg2, pos);
2981  }
2982 
2983  if (len < 1)
2984  {
2985  db_make_int (&tmp_arg3, 0);
2986  }
2987  else
2988  {
2989  db_make_int (&tmp_arg3, len);
2990  }
2991 
2992  if (db_string_substring (SUBSTRING, peek_left, &tmp_arg2, &tmp_arg3, arithptr->value) != NO_ERROR)
2993  {
2994  goto error;
2995  }
2996  }
2997  break;
2998 
2999  case T_STRCMP:
3000  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
3001  {
3002  PRIM_SET_NULL (arithptr->value);
3003  }
3004  else
3005  {
3006  int cmp;
3007 
3008  if (db_string_compare (peek_left, peek_right, arithptr->value) != NO_ERROR)
3009  {
3010  goto error;
3011  }
3012  cmp = db_get_int (arithptr->value);
3013  if (cmp < 0)
3014  {
3015  cmp = -1;
3016  }
3017  else if (cmp > 0)
3018  {
3019  cmp = 1;
3020  }
3021  db_make_int (arithptr->value, cmp);
3022  }
3023  break;
3024 
3025  case T_REVERSE:
3026  if (DB_IS_NULL (peek_right))
3027  {
3028  PRIM_SET_NULL (arithptr->value);
3029  }
3030  else
3031  {
3032  if (db_string_reverse (peek_right, arithptr->value) != NO_ERROR)
3033  {
3034  goto error;
3035  }
3036  }
3037  break;
3038 
3039  case T_DISK_SIZE:
3040  if (DB_IS_NULL (peek_right))
3041  {
3042  db_make_int (arithptr->value, 0);
3043  }
3044  else
3045  {
3046  db_make_int (arithptr->value, pr_data_writeval_disk_size (peek_right));
3047  /* call pr_data_writeval_disk_size function to return the size on disk */
3048  }
3049  break;
3050 
3051  case T_NULLIF: /* when a = b then null else a end */
3052  {
3053  TP_DOMAIN *target_domain;
3054  bool can_compare = false;
3055  int cmp_res = DB_UNK;
3056 
3057  target_domain = regu_var->domain;
3058  if (DB_IS_NULL (peek_left))
3059  {
3060  PRIM_SET_NULL (arithptr->value);
3061  break;
3062  }
3063  else if (target_domain == NULL)
3064  {
3065  TP_DOMAIN *arg1, *arg2, tmp_arg1, tmp_arg2;
3066 
3067  arg1 = tp_domain_resolve_value (peek_left, &tmp_arg1);
3068  arg2 = tp_domain_resolve_value (peek_right, &tmp_arg2);
3069 
3070  target_domain = tp_infer_common_domain (arg1, arg2);
3071  }
3072 
3073  cmp_res = tp_value_compare_with_error (peek_left, peek_right, 1, 0, &can_compare);
3074  if (cmp_res == DB_EQ)
3075  {
3076  PRIM_SET_NULL (arithptr->value);
3077  }
3078  else if (cmp_res == DB_UNK && can_compare == false)
3079  {
3080  goto error;
3081  }
3082  else
3083  {
3084  dom_status = tp_value_cast (peek_left, arithptr->value, target_domain, false);
3085  if (dom_status != DOMAIN_COMPATIBLE)
3086  {
3087  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_left, target_domain);
3088  goto error;
3089  }
3090  }
3091  }
3092  break;
3093 
3094  case T_EXTRACT:
3095  if (qdata_extract_dbval (arithptr->misc_operand, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
3096  {
3097  goto error;
3098  }
3099  break;
3100 
3101  case T_LEAST:
3102  {
3103  int error;
3104  TP_DOMAIN *target_domain;
3105 
3106  error = db_least_or_greatest (peek_left, peek_right, arithptr->value, true);
3107  if (error != NO_ERROR)
3108  {
3109  goto error;
3110  }
3111 
3112  target_domain = regu_var->domain;
3113  if (target_domain == NULL)
3114  {
3115  TP_DOMAIN *arg1, *arg2, tmp_arg1, tmp_arg2;
3116 
3117  arg1 = tp_domain_resolve_value (peek_left, &tmp_arg1);
3118  arg2 = tp_domain_resolve_value (peek_right, &tmp_arg2);
3119 
3120  target_domain = tp_infer_common_domain (arg1, arg2);
3121  }
3122 
3123  dom_status = tp_value_cast (arithptr->value, arithptr->value, target_domain, false);
3124  if (dom_status != DOMAIN_COMPATIBLE)
3125  {
3126  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, arithptr->value, target_domain);
3127  goto error;
3128  }
3129  break;
3130  }
3131 
3132  case T_GREATEST:
3133  {
3134  int error;
3135  TP_DOMAIN *target_domain;
3136 
3137  error = db_least_or_greatest (peek_left, peek_right, arithptr->value, false);
3138  if (error != NO_ERROR)
3139  {
3140  goto error;
3141  }
3142 
3143  target_domain = regu_var->domain;
3144  if (target_domain == NULL)
3145  {
3146  TP_DOMAIN *arg1, *arg2, tmp_arg1, tmp_arg2;
3147 
3148  arg1 = tp_domain_resolve_value (peek_left, &tmp_arg1);
3149  arg2 = tp_domain_resolve_value (peek_right, &tmp_arg2);
3150 
3151  target_domain = tp_infer_common_domain (arg1, arg2);
3152  }
3153 
3154  dom_status = tp_value_cast (arithptr->value, arithptr->value, target_domain, false);
3155  if (dom_status != DOMAIN_COMPATIBLE)
3156  {
3157  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, arithptr->value, target_domain);
3158  goto error;
3159  }
3160  break;
3161  }
3162 
3163  case T_SYS_CONNECT_BY_PATH:
3164  {
3165  if (!qdata_evaluate_sys_connect_by_path (thread_p, (void *) arithptr->thirdptr->xasl, arithptr->leftptr,
3166  peek_right, arithptr->value, vd))
3167  {
3168  goto error;
3169  }
3170 
3171  dom_status = tp_value_auto_cast (arithptr->value, arithptr->value, regu_var->domain);
3172  if (dom_status != DOMAIN_COMPATIBLE)
3173  {
3174  (void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, arithptr->value, regu_var->domain);
3175  goto error;
3176  }
3177  break;
3178  }
3179 
3180  case T_STRCAT:
3181  if (qdata_strcat_dbval (peek_left, peek_right, arithptr->value, regu_var->domain) != NO_ERROR)
3182  {
3183  goto error;
3184  }
3185  break;
3186 
3187  case T_PI:
3188  db_make_double (arithptr->value, PI);
3189  break;
3190 
3191  case T_ROW_COUNT:
3192  /* session info is not constant */
3195  {
3196  int row_count = -1;
3197  if (session_get_row_count (thread_p, &row_count) != NO_ERROR)
3198  {
3199  goto error;
3200  }
3201  db_make_int (arithptr->value, row_count);
3202  }
3203  break;
3204 
3205  case T_LAST_INSERT_ID:
3206  /* session info is not constant */
3209  if (session_get_last_insert_id (thread_p, arithptr->value, true) != NO_ERROR)
3210  {
3211  goto error;
3212  }
3213  break;
3214 
3215  case T_EVALUATE_VARIABLE:
3216  /* session info is not constant */
3219  if (session_get_variable (thread_p, peek_right, arithptr->value) != NO_ERROR)
3220  {
3221  goto error;
3222  }
3223  break;
3224 
3225  case T_DEFINE_VARIABLE:
3226  /* session info is not constant */
3229  if (session_define_variable (thread_p, peek_left, peek_right, arithptr->value) != NO_ERROR)
3230  {
3231  goto error;
3232  }
3233  break;
3234 
3235  case T_RAND:
3236  case T_RANDOM:
3237  /* random(), drandom() is not constant */
3240  if (DB_IS_NULL (peek_right))
3241  {
3242  /* When random functions are called without a seed, peek_right is null. In this case, rand() or drand() uses
3243  * a random value stored on value descriptor to generate the same number during executing one SELECT
3244  * statement. But, each random() or drandom() picks up a seed value to generate different numbers at every
3245  * call. */
3246  if (arithptr->opcode == T_RAND)
3247  {
3248  db_make_int (arithptr->value, (int) vd->lrand);
3249  }
3250  else
3251  {
3252  long int r;
3253  struct drand48_data *rand_buf_p;
3254 
3255  rand_buf_p = qmgr_get_rand_buf (thread_p);
3256  lrand48_r (rand_buf_p, &r);
3257  db_make_int (arithptr->value, r);
3258  }
3259  }
3260  else
3261  {
3262  /* There are two types of seed: 1) given by user (rightptr's type is TYPE_DBVAL) e.g, select rand(1) from
3263  * table; 2) fetched from tuple (rightptr's type is TYPE_CONSTANT) e.g, select rand(i) from table; Regarding
3264  * the former case, rand(1) will generate a sequence of pseudo-random values up to the number of rows.
3265  * However, on the latter case, rand(i) generates values depending on the column i's value. If, for example,
3266  * there are three tuples which include column i of 1 in a table, results of the above statements are as
3267  * follows. rand(1) rand(i) ============= ============= 89400484 89400484 976015093 89400484 1792756325
3268  * 89400484 */
3269  if (arithptr->rightptr->type == TYPE_CONSTANT || arithptr->rightptr->type == TYPE_ATTR_ID)
3270  {
3271  struct drand48_data buf;
3272  long int r;
3273 
3274  srand48_r ((long) db_get_int (peek_right), &buf);
3275  lrand48_r (&buf, &r);
3276  db_make_int (arithptr->value, r);
3277  }
3278  else
3279  {
3280  long int r;
3281 
3282  if (arithptr->rand_seed == NULL)
3283  {
3284  arithptr->rand_seed = (struct drand48_data *) malloc (sizeof (struct drand48_data));
3285 
3286  if (arithptr->rand_seed == NULL)
3287  {
3288  goto error;
3289  }
3290 
3291  srand48_r ((long) db_get_int (peek_right), arithptr->rand_seed);
3292  }
3293 
3294  lrand48_r (arithptr->rand_seed, &r);
3295  db_make_int (arithptr->value, r);
3296  }
3297  }
3298  break;
3299 
3300  case T_DRAND:
3301  case T_DRANDOM:
3302  /* random(), drandom() is not constant */
3305  if (DB_IS_NULL (peek_right))
3306  {
3307  if (arithptr->opcode == T_DRAND)
3308  {
3309  db_make_double (arithptr->value, (double) vd->drand);
3310  }
3311  else
3312  {
3313  double r;
3314  struct drand48_data *rand_buf_p;
3315 
3316  rand_buf_p = qmgr_get_rand_buf (thread_p);
3317  drand48_r (rand_buf_p, &r);
3318  db_make_double (arithptr->value, r);
3319  }
3320  }
3321  else
3322  {
3323  if (arithptr->rightptr->type == TYPE_CONSTANT || arithptr->rightptr->type == TYPE_ATTR_ID)
3324  {
3325  struct drand48_data buf;
3326  double r;
3327 
3328  srand48_r ((long) db_get_int (peek_right), &buf);
3329  drand48_r (&buf, &r);
3330  db_make_double (arithptr->value, r);
3331  }
3332  else
3333  {
3334  double r;
3335 
3336  if (arithptr->rand_seed == NULL)
3337  {
3338  arithptr->rand_seed = (struct drand48_data *) malloc (sizeof (struct drand48_data));
3339 
3340  if (arithptr->rand_seed == NULL)
3341  {
3342  goto error;
3343  }
3344 
3345  srand48_r ((long) db_get_int (peek_right), arithptr->rand_seed);
3346  }
3347 
3348  drand48_r (arithptr->rand_seed, &r);
3349  db_make_double (arithptr->value, r);
3350  }
3351  }
3352  break;
3353 
3354  case T_LIST_DBS:
3355  if (qdata_list_dbs (thread_p, arithptr->value, arithptr->domain) != NO_ERROR)
3356  {
3357  goto error;
3358  }
3359  break;
3360 
3361  case T_SYS_GUID:
3362  /* sys_guid() is not constant */
3365  if (db_guid (thread_p, arithptr->value) != NO_ERROR)
3366  {
3367  goto error;
3368  }
3369  break;
3370 
3371  case T_TYPEOF:
3372  if (db_typeof_dbval (arithptr->value, peek_right) != NO_ERROR)
3373  {
3374  goto error;
3375  }
3376  break;
3377 
3378  case T_INDEX_CARDINALITY:
3379  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
3380  {
3381  PRIM_SET_NULL (arithptr->value);
3382  }
3383  else
3384  {
3385  if (qdata_get_cardinality (thread_p, peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
3386  {
3387  goto error;
3388  }
3389  }
3390  break;
3391 
3392  case T_EXEC_STATS:
3393  /* session info is not constant */
3396  if (session_get_exec_stats_and_clear (thread_p, peek_right, arithptr->value) != NO_ERROR)
3397  {
3398  goto error;
3399  }
3400  break;
3401 
3403  if (db_value_to_enumeration_value (peek_right, arithptr->value, arithptr->domain) != NO_ERROR)
3404  {
3405  goto error;
3406  }
3407  break;
3408 
3409  case T_INET_ATON:
3410  if (DB_IS_NULL (peek_right))
3411  {
3412  PRIM_SET_NULL (arithptr->value);
3413  }
3414  else if (db_inet_aton (arithptr->value, peek_right) != NO_ERROR)
3415  {
3416  goto error;
3417  }
3418  break;
3419 
3420  case T_INET_NTOA:
3421  if (DB_IS_NULL (peek_right))
3422  {
3423  PRIM_SET_NULL (arithptr->value);
3424  }
3425  else if (db_inet_ntoa (arithptr->value, peek_right) != NO_ERROR)
3426  {
3427  goto error;
3428  }
3429  break;
3430 
3431  case T_CHARSET:
3432  case T_COLLATION:
3433  if (db_get_cs_coll_info (arithptr->value, peek_right, (arithptr->opcode == T_COLLATION) ? 1 : 0) != NO_ERROR)
3434  {
3435  goto error;
3436  }
3437  break;
3438 
3439  case T_TRACE_STATS:
3440  /* session info is not constant */
3443  if (session_get_trace_stats (thread_p, arithptr->value) != NO_ERROR)
3444  {
3445  goto error;
3446  }
3447  break;
3448 
3449  case T_WIDTH_BUCKET:
3450  if (db_width_bucket (arithptr->value, peek_left, peek_right, peek_third, peek_fourth) != NO_ERROR)
3451  {
3452  goto error;
3453  }
3454  break;
3455 
3456  case T_INDEX_PREFIX:
3457  if (db_string_index_prefix (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
3458  {
3459  goto error;
3460  }
3461  break;
3462 
3463  case T_SLEEP:
3464  /* sleep() is not constant */
3467  if (db_sleep (arithptr->value, peek_right) != NO_ERROR)
3468  {
3469  goto error;
3470  }
3471  break;
3472 
3473  case T_DBTIMEZONE:
3474  case T_SESSIONTIMEZONE:
3475  {
3476  char *source_str;
3477 
3478  if (arithptr->opcode == T_DBTIMEZONE)
3479  {
3480  source_str = (char *) tz_get_system_timezone ();
3481  }
3482  else
3483  {
3484  source_str = (char *) tz_get_session_local_timezone ();
3485  }
3486  db_make_string (arithptr->value, source_str);
3487  arithptr->value->need_clear = false;
3488  break;
3489  }
3490 
3491  case T_TZ_OFFSET:
3492  {
3493  DB_DATETIME tmp_datetime, utc_datetime;
3494  DB_VALUE timezone;
3495  int timezone_milis;
3496 
3497  /* extract the timezone part */
3498  if (db_sys_timezone (&timezone) != NO_ERROR)
3499  {
3500  goto error;
3501  }
3502  timezone_milis = db_get_int (&timezone) * 60000;
3503  tmp_datetime = vd->sys_datetime;
3504  db_add_int_to_datetime (&tmp_datetime, timezone_milis, &utc_datetime);
3505 
3506  if (DB_IS_NULL (peek_right))
3507  {
3508  PRIM_SET_NULL (arithptr->value);
3509  }
3510  else
3511  {
3512  if (db_tz_offset (peek_right, arithptr->value, &utc_datetime) != NO_ERROR)
3513  {
3514  goto error;
3515  }
3516  }
3517  }
3518  break;
3519 
3520  case T_NEW_TIME:
3521  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right) || DB_IS_NULL (peek_third))
3522  {
3523  PRIM_SET_NULL (arithptr->value);
3524  }
3525  else
3526  {
3527  if (db_new_time (peek_left, peek_right, peek_third, arithptr->value) != NO_ERROR)
3528  {
3529  goto error;
3530  }
3531  }
3532  break;
3533 
3534  case T_FROM_TZ:
3535  if (DB_IS_NULL (peek_left) || DB_IS_NULL (peek_right))
3536  {
3537  PRIM_SET_NULL (arithptr->value);
3538  }
3539  else
3540  {
3541  if (db_from_tz (peek_left, peek_right, arithptr->value) != NO_ERROR)
3542  {
3543  goto error;
3544  }
3545  }
3546  break;
3547 
3548  case T_CONV_TZ:
3549  if (DB_IS_NULL (peek_right))
3550  {
3551  PRIM_SET_NULL (arithptr->value);
3552  }
3553  else
3554  {
3555  if (db_conv_tz (peek_right, arithptr->value) != NO_ERROR)
3556  {
3557  goto error;
3558  }
3559  }
3560  break;
3561 
3562  case T_TO_DATETIME_TZ:
3563  if (DB_IS_NULL (peek_left))
3564  {
3565  PRIM_SET_NULL (arithptr->value);
3566  }
3567  else if (db_to_datetime (peek_left, peek_right, peek_third, DB_TYPE_DATETIMETZ, arithptr->value) != NO_ERROR)
3568  {
3569  goto error;
3570  }
3571  break;
3572 
3573  case T_TO_TIMESTAMP_TZ:
3574  if (DB_IS_NULL (peek_left))
3575  {
3576  PRIM_SET_NULL (arithptr->value);
3577  }
3578  else if (db_to_timestamp (peek_left, peek_right, peek_third, DB_TYPE_TIMESTAMPTZ, arithptr->value) != NO_ERROR)
3579  {
3580  goto error;
3581  }
3582  break;
3583 
3584  case T_UTC_TIMESTAMP:
3585  {
3586  DB_DATE date;
3587  DB_TIME time;
3588  int year, month, day, hour, minute, second;
3589  DB_TIMESTAMP timestamp;
3590 
3591  tz_timestamp_decode_no_leap_sec (vd->sys_epochtime, &year, &month, &day, &hour, &minute, &second);
3592  date = julian_encode (month + 1, day, year);
3593  db_time_encode (&time, hour, minute, second);
3594  db_timestamp_encode_ses (&date, &time, &timestamp, NULL);
3595  db_make_timestamp (arithptr->value, timestamp);
3596  break;
3597  }
3598 
3599  case T_CRC32:
3600  if (DB_IS_NULL (peek_right))
3601  {
3602  PRIM_SET_NULL (arithptr->value);
3603  }
3604  else if (db_crc32_dbval (arithptr->value, peek_right) != NO_ERROR)
3605  {
3606  goto error;
3607  }
3608  break;
3609 
3610  default:
3611  break;
3612  }
3613 
3614  *peek_dbval = arithptr->value;
3615 
3616  if (original_domain != NULL && TP_DOMAIN_TYPE (original_domain) == DB_TYPE_VARIABLE)
3617  {
3618  TP_DOMAIN *resolved_dom = tp_domain_resolve_value (arithptr->value, NULL);
3619 
3620  /* keep DB_TYPE_VARIABLE if resolved domain is NULL */
3621  if (TP_DOMAIN_TYPE (resolved_dom) != DB_TYPE_NULL)
3622  {
3623  regu_var->domain = arithptr->domain = resolved_dom;
3624  }
3625  else
3626  {
3627  regu_var->domain = arithptr->domain = original_domain;
3628  }
3629  }
3630 
3631  if (arithptr->domain != NULL && arithptr->domain->collation_flag != TP_DOMAIN_COLL_NORMAL
3632  && !DB_IS_NULL (arithptr->value))
3633  {
3634  TP_DOMAIN *resolved_dom;
3635 
3636  assert (TP_TYPE_HAS_COLLATION (arithptr->domain->type->id));
3637 
3638  resolved_dom = tp_domain_resolve_value (arithptr->value, NULL);
3639 
3640  /* keep DB_TYPE_VARIABLE if resolved domain is NULL */
3641  if (TP_DOMAIN_TYPE (resolved_dom) != DB_TYPE_NULL)
3642  {
3643  regu_var->domain = resolved_dom;
3644  }
3645  }
3646 
3647  /* check for the first time */
3650  {
3651  int not_const = 0;
3652 
3653  assert (arithptr->pred == NULL);
3654 
3656  {
3657  ; /* is_const, go ahead */
3658  }
3659  else
3660  {
3661  not_const++;
3662  }
3663 
3665  {
3666  ; /* is_const, go ahead */
3667  }
3668  else
3669  {
3670  not_const++;
3671  }
3672 
3674  {
3675  ; /* is_const, go ahead */
3676  }
3677  else
3678  {
3679  not_const++;
3680  }
3681 
3682  if (not_const == 0)
3683  {
3686  }
3687  else
3688  {
3691  }
3692  }
3693 
3694 fetch_peek_arith_end:
3695 
3698 
3699 #if !defined(NDEBUG)
3700  switch (arithptr->opcode)
3701  {
3702  /* incr/decr is not constant */
3703  case T_INCR:
3704  case T_DECR:
3705  /* serial.current_value(), serial.next_value() is not constant */
3706  case T_CURRENT_VALUE:
3707  case T_NEXT_VALUE:
3708  /* set pred is not constant */
3709  case T_CASE:
3710  case T_DECODE:
3711  case T_IF:
3712  case T_PREDICATE:
3713  /* session info is not constant */
3714  case T_ROW_COUNT:
3715  case T_LAST_INSERT_ID:
3716  case T_EVALUATE_VARIABLE:
3717  case T_DEFINE_VARIABLE:
3718  case T_EXEC_STATS:
3719  case T_TRACE_STATS:
3720  /* random(), drandom() is not constant */
3721  case T_RAND:
3722  case T_RANDOM:
3723  case T_DRAND:
3724  case T_DRANDOM:
3725  /* sys_guid() is not constant */
3726  case T_SYS_GUID:
3727  /* sleep() is not constant */
3728  case T_SLEEP:
3729 
3732  break;
3733  default:
3734  break;
3735  }
3736 
3737  /* set pred is not constant */
3738  if (arithptr->pred != NULL)
3739  {
3742  }
3743 #endif
3744 
3745  thread_dec_recursion_depth (thread_p);
3746 
3747  return NO_ERROR;
3748 
3749 error:
3750  thread_dec_recursion_depth (thread_p);
3751 
3752  if (original_domain)
3753  {
3754  /* restores regu variable domain */
3755  regu_var->domain = original_domain;
3756  }
3757 
3758  return ER_FAILED;
3759 }
3760 
3761 /*
3762  * fetch_peek_dbval () - returns a POINTER to an existing db_value
3763  * return: NO_ERROR or ER_code
3764  * regu_var(in/out): Regulator Variable
3765  * vd(in): Value Descriptor
3766  * cls_oid(in): Class Identifier
3767  * obj_oid(in): Object Identifier
3768  * tpl(in): Tuple
3769  * peek_dbval(out): Set to the value ref resulting from the fetch operation
3770  *
3771  */
3772 int
3773 fetch_peek_dbval (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr * vd, OID * class_oid, OID * obj_oid,
3774  QFILE_TUPLE tpl, DB_VALUE ** peek_dbval)
3775 {
3776  int length;
3777  PR_TYPE *pr_type;
3778  OR_BUF buf;
3780  char *ptr;
3781  REGU_VARIABLE *head_regu = NULL, *regu = NULL;
3782  int error = NO_ERROR;
3783  REGU_VALUE_LIST *reguval_list = NULL;
3784  DB_TYPE head_type, cur_type;
3785  FUNCTION_TYPE *funcp = NULL;
3786 
3787  switch (regu_var->type)
3788  {
3789  case TYPE_ATTR_ID: /* fetch object attribute value */
3790  case TYPE_SHARED_ATTR_ID:
3791  case TYPE_CLASS_ATTR_ID:
3792  /* is not constant */
3795  *peek_dbval = regu_var->value.attr_descr.cache_dbvalp;
3796  if (*peek_dbval != NULL)
3797  {
3798  /* we have a cached pointer already */
3799  break;
3800  }
3801  else
3802  {
3803  *peek_dbval = heap_attrinfo_access (regu_var->value.attr_descr.id, regu_var->value.attr_descr.cache_attrinfo);
3804  if (*peek_dbval == NULL)
3805  {
3806  goto exit_on_error;
3807  }
3808  }
3809  regu_var->value.attr_descr.cache_dbvalp = *peek_dbval; /* cache */
3810  break;
3811 
3812  case TYPE_OID: /* fetch object identifier value */
3815  *peek_dbval = &regu_var->value.dbval;
3816  db_make_oid (*peek_dbval, obj_oid);
3817  break;
3818 
3819  case TYPE_CLASSOID: /* fetch class identifier value */
3822  *peek_dbval = &regu_var->value.dbval;
3823  db_make_oid (*peek_dbval, class_oid);
3824  break;
3825 
3826  case TYPE_POSITION: /* fetch list file tuple value */
3827  /* is not constant */
3830 
3831  pr_clear_value (regu_var->vfetch_to);
3832 
3833  *peek_dbval = regu_var->vfetch_to;
3834 
3835  flag = (QFILE_TUPLE_VALUE_FLAG) qfile_locate_tuple_value (tpl, regu_var->value.pos_descr.pos_no, &ptr, &length);
3836  if (flag == V_BOUND)
3837  {
3838  pr_type = regu_var->value.pos_descr.dom->type;
3839  if (pr_type == NULL)
3840  {
3841  goto exit_on_error;
3842  }
3843 
3844  OR_BUF_INIT (buf, ptr, length);
3845 
3846  if (pr_type->data_readval (&buf, *peek_dbval, regu_var->value.pos_descr.dom, -1, false /* Don't copy */ ,
3847  NULL, 0) != NO_ERROR)
3848  {
3849  goto exit_on_error;
3850  }
3851  }
3852  break;
3853 
3854  case TYPE_POS_VALUE: /* fetch positional value */
3855 #if defined(QP_DEBUG)
3856  if (regu_var->value.val_pos < 0 || regu_var->value.val_pos > (vd->dbval_cnt - 1))
3857  {
3858  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_QPROC_INVALID_VALLIST_INDEX, 1, regu_var->value.val_pos);
3859  goto exit_on_error;
3860  }
3861 #endif
3862 
3865  *peek_dbval = (DB_VALUE *) vd->dbval_ptr + regu_var->value.val_pos;
3866  break;
3867 
3868  case TYPE_CONSTANT: /* fetch constant-column value */
3869  /* is not constant */
3872 
3873  /* execute linked query */
3874  EXECUTE_REGU_VARIABLE_XASL (thread_p, regu_var, vd);
3875  if (CHECK_REGU_VARIABLE_XASL_STATUS (regu_var) != XASL_SUCCESS)
3876  {
3877  goto exit_on_error;
3878  }
3879  *peek_dbval = regu_var->value.dbvalptr;
3880  break;
3881 
3882  case TYPE_ORDERBY_NUM:
3883  /* is not constant */
3886  *peek_dbval = regu_var->value.dbvalptr;
3887  break;
3888 
3889  case TYPE_DBVAL: /* fetch db_value */
3892  *peek_dbval = &regu_var->value.dbval;
3893  break;
3894 
3895  case TYPE_REGUVAL_LIST:
3896  /* is not constant */
3899  reguval_list = regu_var->value.reguval_list;
3900  assert (reguval_list != NULL);
3901  assert (reguval_list->current_value != NULL);
3902 
3903  regu = reguval_list->current_value->value;
3904  assert (regu != NULL);
3905 
3906  if (regu->type != TYPE_DBVAL && regu->type != TYPE_INARITH && regu->type != TYPE_POS_VALUE)
3907  {
3909  goto exit_on_error;
3910  }
3911 
3912  error = fetch_peek_dbval (thread_p, regu, vd, class_oid, obj_oid, tpl, peek_dbval);
3913  if (error != NO_ERROR)
3914  {
3915  goto exit_on_error;
3916  }
3917  break;
3918 
3919  case TYPE_INARITH: /* compute and fetch arithmetic expr. value */
3920  case TYPE_OUTARITH:
3921  error = fetch_peek_arith (thread_p, regu_var, vd, obj_oid, tpl, peek_dbval);
3922  if (error != NO_ERROR)
3923  {
3924  goto exit_on_error;
3925  }
3926 
3929  break;
3930 
3931  case TYPE_FUNC: /* fetch function value */
3933  {
3934  funcp = regu_var->value.funcp;
3935  assert (funcp != NULL);
3936 
3937  *peek_dbval = funcp->value;
3938 
3939  return NO_ERROR;
3940  }
3941 
3943 
3944  error = qdata_evaluate_function (thread_p, regu_var, vd, obj_oid, tpl);
3945  if (error != NO_ERROR)
3946  {
3947  goto exit_on_error;
3948  }
3949 
3950  funcp = regu_var->value.funcp;
3951  assert (funcp != NULL);
3952 
3953  *peek_dbval = funcp->value;
3954 
3955  /* check for the first time */
3958  {
3959  int not_const = 0;
3960 
3961  switch (funcp->ftype)
3962  {
3963  case F_JSON_ARRAY:
3964  case F_JSON_ARRAY_APPEND:
3965  case F_JSON_ARRAY_INSERT:
3966  case F_JSON_CONTAINS:
3967  case F_JSON_CONTAINS_PATH:
3968  case F_JSON_DEPTH:
3969  case F_JSON_EXTRACT:
3970  case F_JSON_GET_ALL_PATHS:
3971  case F_JSON_KEYS:
3972  case F_JSON_INSERT:
3973  case F_JSON_LENGTH:
3974  case F_JSON_MERGE:
3975  case F_JSON_MERGE_PATCH:
3976  case F_JSON_OBJECT:
3977  case F_JSON_PRETTY:
3978  case F_JSON_QUOTE:
3979  case F_JSON_REMOVE:
3980  case F_JSON_REPLACE:
3981  case F_JSON_SEARCH:
3982  case F_JSON_SET:
3983  case F_JSON_TYPE:
3984  case F_JSON_UNQUOTE:
3985  case F_JSON_VALID:
3986  case F_REGEXP_COUNT:
3987  case F_REGEXP_INSTR:
3988  case F_REGEXP_LIKE:
3989  case F_REGEXP_REPLACE:
3990  case F_REGEXP_SUBSTR:
3991  {
3992  regu_variable_list_node *operand;
3993 
3994  operand = funcp->operand;
3995 
3996  while (operand != NULL)
3997  {
3999  {
4000  not_const++;
4001  break;
4002  }
4003  operand = operand->next;
4004  }
4005  }
4006  break;
4007 
4008  case F_INSERT_SUBSTRING:
4009  /* should sync with qdata_insert_substring_function () */
4010  {
4012  int i;
4013  int num_regu = 0;
4014 
4015  /* initialize the argument array */
4016  for (i = 0; i < NUM_F_INSERT_SUBSTRING_ARGS; i++)
4017  {
4018  regu_array[i] = NULL;
4019  }
4020 
4021  error = qdata_regu_list_to_regu_array (funcp, NUM_F_INSERT_SUBSTRING_ARGS, regu_array, &num_regu);
4022  if (num_regu != NUM_F_INSERT_SUBSTRING_ARGS)
4023  {
4024  assert (false);
4026  goto exit_on_error;
4027  }
4028  if (error != NO_ERROR)
4029  {
4030  goto exit_on_error;
4031  }
4032 
4033  for (i = 0; i < NUM_F_INSERT_SUBSTRING_ARGS; i++)
4034  {
4036  {
4037  not_const++;
4038  break; /* exit for-loop */
4039  }
4040  } /* for (i = 0; ...) */
4041  }
4042  break;
4043 
4044  case F_ELT:
4045  /* should sync with qdata_elt () */
4046  {
4047  regu_variable_list_node *operand;
4048  DB_VALUE *index = NULL;
4049  DB_TYPE index_type;
4050  DB_BIGINT idx = 0;
4051  bool is_null_elt = false;
4052 
4053  assert (funcp->operand != NULL);
4055  {
4056  not_const++;
4057  }
4058  else
4059  {
4060  error = fetch_peek_dbval (thread_p, &funcp->operand->value, vd, NULL, obj_oid, tpl, &index);
4061  if (error != NO_ERROR)
4062  {
4063  goto exit_on_error;
4064  }
4065 
4066  index_type = DB_VALUE_DOMAIN_TYPE (index);
4067 
4068  switch (index_type)
4069  {
4070  case DB_TYPE_SMALLINT:
4071  idx = db_get_short (index);
4072  break;
4073  case DB_TYPE_INTEGER:
4074  idx = db_get_int (index);
4075  break;
4076  case DB_TYPE_BIGINT:
4077  idx = db_get_bigint (index);
4078  break;
4079  case DB_TYPE_NULL:
4080  is_null_elt = true;
4081  break;
4082  default:
4083  assert (false); /* is impossible */
4084  error = ER_QPROC_INVALID_DATATYPE;
4085  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error, 0);
4086  if (index != NULL && index->need_clear == true)
4087  {
4088  pr_clear_value (index);
4089  }
4090  goto exit_on_error;
4091  }
4092 
4093  if (!is_null_elt)
4094  {
4095  if (idx <= 0)
4096  {
4097  /* index is 0 or is negative */
4098  is_null_elt = true;
4099  }
4100  else
4101  {
4102  idx--;
4103  operand = funcp->operand->next;
4104 
4105  while (idx > 0 && operand != NULL)
4106  {
4107  operand = operand->next;
4108  idx--;
4109  }
4110 
4111  if (operand == NULL)
4112  {
4113  /* index greater than number of arguments */
4114  is_null_elt = true;
4115  }
4116  else
4117  {
4118  assert (operand != NULL);
4120  {
4121  not_const++;
4122  }
4123  } /* operand != NULL */
4124  }
4125  } /* if (!is_null_elt) */
4126  } /* else */
4127 
4128 #if !defined(NDEBUG)
4129  if (is_null_elt)
4130  {
4131  assert (not_const == 0);
4132  }
4133 #endif
4134  }
4135  break;
4136 
4137  default:
4138  not_const++; /* is not constant */
4139  break;
4140  }
4141 
4142  if (not_const == 0)
4143  {
4146  }
4147  else
4148  {
4151  }
4152  }
4153 
4154 #if !defined(NDEBUG)
4155  switch (funcp->ftype)
4156  {
4157  case F_SET:
4158  case F_MULTISET:
4159  case F_SEQUENCE:
4160  case F_VID:
4161  case F_TABLE_SET:
4162  case F_TABLE_MULTISET:
4163  case F_TABLE_SEQUENCE:
4164  case F_GENERIC:
4165  case F_CLASS_OF:
4166  case F_BENCHMARK:
4167  /* is not constant */
4170  break;
4171 
4172  case F_INSERT_SUBSTRING:
4173  case F_ELT:
4174  case F_JSON_ARRAY:
4175  case F_JSON_ARRAY_APPEND:
4176  case F_JSON_ARRAY_INSERT:
4177  case F_JSON_CONTAINS:
4178  case F_JSON_CONTAINS_PATH:
4179  case F_JSON_DEPTH:
4180  case F_JSON_EXTRACT:
4181  case F_JSON_GET_ALL_PATHS:
4182  case F_JSON_KEYS:
4183  case F_JSON_INSERT:
4184  case F_JSON_LENGTH:
4185  case F_JSON_MERGE:
4186  case F_JSON_MERGE_PATCH:
4187  case F_JSON_OBJECT:
4188  case F_JSON_PRETTY:
4189  case F_JSON_QUOTE:
4190  case F_JSON_REMOVE:
4191  case F_JSON_REPLACE:
4192  case F_JSON_SEARCH:
4193  case F_JSON_SET:
4194  case F_JSON_TYPE:
4195  case F_JSON_UNQUOTE:
4196  case F_JSON_VALID:
4197  case F_REGEXP_COUNT:
4198  case F_REGEXP_INSTR:
4199  case F_REGEXP_LIKE:
4200  case F_REGEXP_REPLACE:
4201  case F_REGEXP_SUBSTR:
4202  break;
4203 
4204  default:
4205  assert (false); /* is impossible */
4206  break;
4207  }
4208 #endif
4209  break;
4210 
4211  default:
4213  goto exit_on_error;
4214  }
4215 
4218 
4220  {
4221  if (TP_IS_CHAR_TYPE (TP_DOMAIN_TYPE (regu_var->domain)))
4222  {
4223  if (!DB_IS_NULL (*peek_dbval))
4224  {
4225  assert (TP_IS_CHAR_TYPE (DB_VALUE_TYPE (*peek_dbval)));
4226  assert (regu_var->domain->codeset == db_get_string_codeset (*peek_dbval));
4227  }
4228  db_string_put_cs_and_collation (*peek_dbval, regu_var->domain->codeset, regu_var->domain->collation_id);
4229  }
4230  else
4231  {
4232  assert (TP_DOMAIN_TYPE (regu_var->domain) == DB_TYPE_ENUMERATION);
4233 
4234  if (!DB_IS_NULL (*peek_dbval))
4235  {
4236  assert (DB_VALUE_DOMAIN_TYPE (*peek_dbval) == DB_TYPE_ENUMERATION);
4237  assert (regu_var->domain->codeset == db_get_enum_codeset (*peek_dbval));
4238  }
4239  db_enum_put_cs_and_collation (*peek_dbval, regu_var->domain->codeset, regu_var->domain->collation_id);
4240 
4241  }
4242  }
4243 
4244  if (*peek_dbval != NULL && !DB_IS_NULL (*peek_dbval))
4245  {
4246  if (TP_DOMAIN_TYPE (regu_var->domain) == DB_TYPE_VARIABLE
4247  || TP_DOMAIN_COLLATION_FLAG (regu_var->domain) != TP_DOMAIN_COLL_NORMAL)
4248  {
4249  regu_var->domain = tp_domain_resolve_value (*peek_dbval, NULL);
4250  }
4251 
4252  /* for REGUVAL_LIST compare type with the corresponding column of first row if not compatible, raise an error
4253  * This is the same behavior as "union" */
4254  if (regu_var->type == TYPE_REGUVAL_LIST)
4255  {
4256  head_regu = reguval_list->regu_list->value;
4257  regu = reguval_list->current_value->value;
4258 
4259  if (regu->domain == NULL || TP_DOMAIN_TYPE (regu->domain) == DB_TYPE_VARIABLE
4260  || TP_DOMAIN_COLLATION_FLAG (regu->domain) != TP_DOMAIN_COLL_NORMAL)
4261  {
4262  regu->domain = tp_domain_resolve_value (*peek_dbval, NULL);
4263  }
4264  head_type = TP_DOMAIN_TYPE (head_regu->domain);
4265  cur_type = TP_DOMAIN_TYPE (regu->domain);
4266 
4267  /* compare the type */
4268  if (head_type != DB_TYPE_NULL && cur_type != DB_TYPE_NULL && head_regu->domain != regu->domain)
4269  {
4270  if (head_type != cur_type || !pr_is_string_type (head_type) || !pr_is_variable_type (head_type))
4271  {
4273  goto exit_on_error;
4274  }
4275  else if (TP_DOMAIN_COLLATION (head_regu->domain) != TP_DOMAIN_COLLATION (regu->domain))
4276  {
4278  goto exit_on_error;
4279  }
4280  }
4281  }
4282  }
4283 
4286 
4287  return NO_ERROR;
4288 
4289 exit_on_error:
4290 
4291  return ER_FAILED;
4292 }
4293 
4294 /*
4295  * fetch_peek_dbval_pos () -
4296  * return: NO_ERROR or ER_code
4297  * regu_var(in/out): Regulator Variable
4298  * tpl(in): Tuple
4299  * pos(in):
4300  * peek_dbval(out): Set to the value ref resulting from the fetch operation
4301  * next_tpl(out): Set to the next tuple ref
4302  */
4303 static int
4304 fetch_peek_dbval_pos (REGU_VARIABLE * regu_var, QFILE_TUPLE tpl, int pos, DB_VALUE ** peek_dbval,
4305  QFILE_TUPLE * next_tpl)
4306 {
4307  int length;
4308  PR_TYPE *pr_type;
4309  OR_BUF buf;
4310  char *ptr;
4311  QFILE_TUPLE_VALUE_POSITION *pos_descr;
4312 
4313  /* assume regu_var->type == TYPE_POSITION */
4314  pos_descr = &regu_var->value.pos_descr;
4315  pr_clear_value (regu_var->vfetch_to);
4316  *peek_dbval = regu_var->vfetch_to;
4317 
4318  /* locate value position in the tuple */
4319  if (qfile_locate_tuple_value_r (tpl, pos, &ptr, &length) == V_BOUND)
4320  {
4321  pr_type = pos_descr->dom->type;
4322  if (pr_type == NULL)
4323  {
4324  return ER_FAILED;
4325  }
4326 
4327  OR_BUF_INIT (buf, ptr, length);
4328  /* read value from the tuple */
4329  if (pr_type->data_readval (&buf, *peek_dbval, pos_descr->dom, -1, false /* Don't copy */ , NULL, 0) != NO_ERROR)
4330  {
4331  return ER_FAILED;
4332  }
4333  }
4334 
4335  /* next position pointer */
4336  *next_tpl = ptr + length;
4337 
4338  return NO_ERROR;
4339 }
4340 
4341 /*
4342  * fetch_peek_min_max_value_of_width_bucket_func () -
4343  * return: NO_ERROR or ER_code
4344  * regu_var(in): Regulator Variable of an ARITH node.
4345  * vd(in): Value Descriptor
4346  * obj_oid(in): Object Identifier
4347  * tpl(in): Tuple
4348  * min(out): the lower bound of width_bucket
4349  * max(out): the upper bound of width_bucket
4350  */
4351 static int
4353  OID * obj_oid, QFILE_TUPLE tpl, DB_VALUE ** min, DB_VALUE ** max)
4354 {
4355  int er_status = NO_ERROR;
4356  PRED_EXPR *pred_expr;
4357  PRED *pred;
4358  EVAL_TERM *eval_term1, *eval_term2;
4359 
4360  assert (min != NULL && max != NULL);
4361 
4362  if (regu_var == NULL || regu_var->type != TYPE_INARITH)
4363  {
4364  er_status = ER_QPROC_INVALID_XASLNODE;
4365  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
4366 
4367  goto error;
4368  }
4369 
4370  pred_expr = regu_var->value.arithptr->pred;
4371  if (pred_expr == NULL || pred_expr->type != T_PRED)
4372  {
4373  er_status = ER_QPROC_INVALID_XASLNODE;
4374  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
4375 
4376  goto error;
4377  }
4378 
4379  pred = &pred_expr->pe.m_pred;
4380  if (pred->lhs == NULL || pred->lhs->type != T_EVAL_TERM)
4381  {
4382  er_status = ER_QPROC_INVALID_XASLNODE;
4383  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
4384 
4385  goto error;
4386  }
4387 
4388  eval_term1 = &pred->lhs->pe.m_eval_term;
4389  if (eval_term1->et_type != T_COMP_EVAL_TERM)
4390  {
4391  er_status = ER_QPROC_INVALID_XASLNODE;
4392  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
4393 
4394  goto error;
4395  }
4396 
4397  /* lower bound, error info is already set in fetch_peek_dbval */
4398  er_status = fetch_peek_dbval (thread_p, eval_term1->et.et_comp.rhs, vd, NULL, obj_oid, tpl, min);
4399  if (er_status != NO_ERROR)
4400  {
4401  if (er_errid () == NO_ERROR)
4402  {
4403  er_status = ER_QPROC_INVALID_XASLNODE;
4404  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
4405  }
4406 
4407  goto error;
4408  }
4409 
4410  eval_term2 = &pred->rhs->pe.m_eval_term;
4411  if (eval_term2->et_type != T_COMP_EVAL_TERM)
4412  {
4413  er_status = ER_QPROC_INVALID_XASLNODE;
4414  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
4415 
4416  goto error;
4417  }
4418 
4419  /* upper bound, error info is already set in fetch_peek_dbval */
4420  er_status = fetch_peek_dbval (thread_p, eval_term2->et.et_comp.rhs, vd, NULL, obj_oid, tpl, max);
4421  if (er_status != NO_ERROR)
4422  {
4423  if (er_errid () == NO_ERROR)
4424  {
4425  er_status = ER_QPROC_INVALID_XASLNODE;
4426  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
4427  }
4428 
4429  goto error;
4430  }
4431 
4432 error:
4433 
4434  return er_status;
4435 }
4436 
4437 /*
4438  * fetch_copy_dbval () - returns a COPY of a db_value which the caller
4439  * must clear
4440  * return: NO_ERROR or ER_code
4441  * regu_var(in/out): Regulator Variable
4442  * vd(in): Value Descriptor
4443  * cls_oid(in): Class Identifier
4444  * obj_oid(in): Object Identifier
4445  * tpl(in): Tuple
4446  * dbval(out): Set to the value resulting from the fetch operation
4447  *
4448  * This routine uses the value description indicated by the regulator variable
4449  * to fetch the indicated value and store it in the dbval parameter.
4450  * The value may be fetched from either a heap file object instance,
4451  * or from a list file tuple, or from an all constants regulator variable
4452  * content. If the value is fetched from a heap file object instance,
4453  * then tpl parameter should be given NULL. Likewise, if the value is fetched
4454  * from a list file tuple, then obj_oid parameter should be given NULL.
4455  * If the value is fetched from all constant values referred to
4456  * by the regulator variable, then all of the parameters obj_oid,
4457  * tpl should be given NULL values.
4458  *
4459  * If the value description in the regulator variable refers other cases
4460  * such as constant value, arithmetic expression, the resultant value
4461  * is computed and stored in the db_value.
4462  *
4463  * see fetch_peek_dbval().
4464  */
4465 int
4466 fetch_copy_dbval (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr * vd, OID * class_oid, OID * obj_oid,
4467  QFILE_TUPLE tpl, DB_VALUE * dbval)
4468 {
4469  int result;
4470  DB_VALUE *readonly_val, copy_val, *tmp;
4471 
4472  db_make_null (&copy_val);
4473 
4474  result = fetch_peek_dbval (thread_p, regu_var, vd, class_oid, obj_oid, tpl, &readonly_val);
4475  if (result != NO_ERROR)
4476  {
4477  return result;
4478  }
4479 
4480  /*
4481  * This routine needs to ensure that a copy happens. If readonly_val
4482  * points to the same db_value as dbval, qdata_copy_db_value() won't copy.
4483  * This can happen with scans that are PEEKING and routines that
4484  * are sending the COPY flag to fetch_val_list() like the group by
4485  * code. If this happens we use a stack variable for the copy and
4486  * then transfer ownership to the returned dbval
4487  */
4488  if (dbval == readonly_val)
4489  {
4490  tmp = &copy_val;
4491  }
4492  else
4493  {
4494  tmp = dbval;
4495  }
4496 
4497  if (!qdata_copy_db_value (tmp, readonly_val))
4498  {
4499  result = ER_FAILED;
4500  }
4501 
4502  if (tmp == &copy_val)
4503  {
4504  /*
4505  * transfer ownership to the real db_value via a
4506  * structure copy. Make sure you clear the previous value.
4507  */
4508  pr_clear_value (dbval);
4509  *dbval = *tmp;
4510  }
4511 
4512  return result;
4513 }
4514 
4515 /*
4516  * fetch_val_list () - fetches all the values for the given regu variable list
4517  * return: NO_ERROR or ER_code
4518  * regu_list(in/out): Regulator Variable list
4519  * vd(in): Value Descriptor
4520  * class_oid(in): Class Identifier
4521  * obj_oid(in): Object Identifier
4522  * tpl(in): Tuple
4523  * peek(int):
4524  */
4525 int
4526 fetch_val_list (THREAD_ENTRY * thread_p, regu_variable_list_node * regu_list, val_descr * vd, OID * class_oid,
4527  OID * obj_oid, QFILE_TUPLE tpl, int peek)
4528 {
4529  regu_variable_list_node *regup;
4530  QFILE_TUPLE next_tpl;
4531  int rc, pos, next_pos;
4532  DB_VALUE *tmp;
4533 
4534  if (peek)
4535  {
4536  next_tpl = tpl + QFILE_TUPLE_LENGTH_SIZE;
4537  next_pos = 0;
4538 
4539  for (regup = regu_list; regup != NULL; regup = regup->next)
4540  {
4541  if (regup->value.type == TYPE_POSITION)
4542  {
4543  pos = regup->value.value.pos_descr.pos_no;
4544  if (pos >= next_pos)
4545  {
4546  pos -= next_pos;
4547  next_pos = regup->value.value.pos_descr.pos_no + 1;
4548  }
4549  else
4550  {
4551  next_tpl = tpl + QFILE_TUPLE_LENGTH_SIZE;
4552  next_pos = 0;
4553  }
4554 
4555  /* at fetch_peek_dbval_pos(), regup->value.vfetch_to is cleared */
4556  rc = fetch_peek_dbval_pos (&regup->value, next_tpl, pos, &tmp, &next_tpl);
4557  }
4558  else
4559  {
4560  if (pr_is_set_type (DB_VALUE_DOMAIN_TYPE (regup->value.vfetch_to)))
4561  {
4562  pr_clear_value (regup->value.vfetch_to);
4563  }
4564  rc = fetch_peek_dbval (thread_p, &regup->value, vd, class_oid, obj_oid, tpl, &tmp);
4565  }
4566 
4567  if (rc != NO_ERROR)
4568  {
4569  pr_clear_value (regup->value.vfetch_to);
4570  return ER_FAILED;
4571  }
4572 
4573  pr_share_value (tmp, regup->value.vfetch_to);
4574  }
4575  }
4576  else
4577  {
4578  /*
4579  * These DB_VALUES must persist across object fetches, so we must
4580  * use fetch_copy_dbval and NOT peek here.
4581  */
4582  for (regup = regu_list; regup != NULL; regup = regup->next)
4583  {
4584  if (pr_is_set_type (DB_VALUE_DOMAIN_TYPE (regup->value.vfetch_to)))
4585  {
4586  pr_clear_value (regup->value.vfetch_to);
4587  }
4588  if (fetch_copy_dbval (thread_p, &regup->value, vd, class_oid, obj_oid, tpl, regup->value.vfetch_to) !=
4589  NO_ERROR)
4590  {
4591  return ER_FAILED;
4592  }
4593  }
4594  }
4595 
4596  return NO_ERROR;
4597 }
4598 
4599 /*
4600  * fetch_init_val_list () -
4601  * return:
4602  * regu_list(in/out): Regulator Variable list
4603  */
4604 void
4606 {
4607  regu_variable_list_node *regu_p;
4608  REGU_VARIABLE *regu_var;
4609 
4610  for (regu_p = regu_list; regu_p; regu_p = regu_p->next)
4611  {
4612  regu_var = &regu_p->value;
4613  regu_var->value.attr_descr.cache_dbvalp = NULL;
4614  }
4615 }
4616 
4617 /*
4618  * is_argument_wrapped_with_cast_op () - check if regu_var is a cast
4619  * expression
4620  * return: true/false
4621  * regu_list(in/out): Regulator Variable list
4622  * vd(in): Value Descriptor
4623  * class_oid(in): Class Identifier
4624  * obj_oid(in): Object Identifier
4625  * tpl(in): Tuple
4626  * peek(int):
4627  */
4628 static bool
4630 {
4631  if (regu_var == NULL)
4632  {
4633  return false;
4634  }
4635 
4636  if (regu_var->type == TYPE_INARITH || regu_var->type == TYPE_OUTARITH)
4637  {
4638  return (regu_var->value.arithptr->opcode == T_CAST || regu_var->value.arithptr->opcode == T_CAST_WRAP);
4639  }
4640 
4641  return false;
4642 }
4643 
4644 /* TODO: next functions are duplicate from string op func that get as argument PT_OP_TYPE. Please try to merge
4645  * PT_OP_TYPE and OPERATOR_TYPE.
4646  */
4647 
4648 /*
4649  * get_hour_minute_or_second () - extract hour, minute or second
4650  * information from datetime depending on
4651  * the value of the op_type variable
4652  * return: error or no error
4653  * datetime(in): datetime value
4654  * op_type(in): operation type
4655  * db_value(out): output of the operation
4656  */
4657 static int
4659 {
4660  int error = NO_ERROR;
4661  int hour, minute, second, millisecond;
4662 
4663  if (DB_IS_NULL (datetime))
4664  {
4665  PRIM_SET_NULL (db_value);
4666  return NO_ERROR;
4667  }
4668 
4669  if (DB_VALUE_DOMAIN_TYPE (datetime) == DB_TYPE_DATE)
4670  {
4672  {
4673  db_make_null (db_value);
4674  }
4675  else
4676  {
4678  error = ER_TIME_CONVERSION;
4679  }
4680  return error;
4681  }
4682 
4683  error = db_get_time_from_dbvalue (datetime, &hour, &minute, &second, &millisecond);
4684  if (error != NO_ERROR)
4685  {
4687  {
4688  db_make_null (db_value);
4689  error = NO_ERROR;
4690  }
4691  else
4692  {
4694  error = ER_TIME_CONVERSION;
4695  }
4696  return error;
4697  }
4698  switch (op_type)
4699  {
4700  case T_HOUR:
4701  db_make_int (db_value, hour);
4702  break;
4703  case T_MINUTE:
4704  db_make_int (db_value, minute);
4705  break;
4706  case T_SECOND:
4707  db_make_int (db_value, second);
4708  break;
4709  default:
4710  assert (false);
4711  db_make_null (db_value);
4712  error = ER_FAILED;
4713  break;
4714  }
4715 
4716  return error;
4717 }
4718 
4719 /*
4720  * get_year_month_or_day () - get year or month or day from value
4721  *
4722  * return : error code
4723  * src_date (in) : input value
4724  * op (in) : operation type - year, month or day
4725  * result (out) : value with year, month or day
4726  */
4727 static int
4728 get_year_month_or_day (const DB_VALUE * src_date, OPERATOR_TYPE op, DB_VALUE * result)
4729 {
4730  int month = 0, day = 0, year = 0;
4731  int second = 0, minute = 0, hour = 0;
4732  int ms = 0;
4733 
4734  assert (op == T_YEAR || op == T_MONTH || op == T_DAY);
4735 
4736  if (DB_IS_NULL (src_date))
4737  {
4738  db_make_null (result);
4739  return NO_ERROR;
4740  }
4741 
4742  /* get the date/time information from src_date */
4743  if (db_get_datetime_from_dbvalue (src_date, &year, &month, &day, &hour, &minute, &second, &ms, NULL) != NO_ERROR)
4744  {
4745  /* This function should return NULL if src_date is an invalid parameter. Clear the error generated by the
4746  * function call and return null. */
4747  er_clear ();
4748  db_make_null (result);
4750  {
4751  return NO_ERROR;
4752  }
4753  /* set ER_DATE_CONVERSION */
4755  return ER_DATE_CONVERSION;
4756  }
4757 
4758  switch (op)
4759  {
4760  case T_YEAR:
4761  db_make_int (result, year);
4762  break;
4763  case T_MONTH:
4764  db_make_int (result, month);
4765  break;
4766  case T_DAY:
4767  db_make_int (result, day);
4768  break;
4769  default:
4770  assert (false);
4771  db_make_null (result);
4772  return ER_FAILED;
4773  }
4774 
4775  return NO_ERROR;
4776 }
4777 
4778 int
4779 get_date_weekday (const DB_VALUE * src_date, OPERATOR_TYPE op, DB_VALUE * result)
4780 {
4781  int error_status = NO_ERROR;
4782  int month = 0, day = 0, year = 0;
4783  int second = 0, minute = 0, hour = 0;
4784  int ms = 0;
4785  int day_of_week = 0;
4786 
4787  if (DB_IS_NULL (src_date))
4788  {
4789  db_make_null (result);
4790  return NO_ERROR;
4791  }
4792 
4793  /* get the date/time information from src_date */
4794  error_status = db_get_datetime_from_dbvalue (src_date, &year, &month, &day, &hour, &minute, &second, &ms, NULL);
4795  if (error_status != NO_ERROR)
4796  {
4797  error_status = ER_DATE_CONVERSION;
4798  goto error_exit;
4799  }
4800 
4801  if (year == 0 && month == 0 && day == 0 && hour == 0 && minute == 0 && second == 0 && ms == 0)
4802  {
4803  error_status = ER_ATTEMPT_TO_USE_ZERODATE;
4804  goto error_exit;
4805  }
4806 
4807  /* 0 = Sunday, 1 = Monday, etc */
4808  day_of_week = db_get_day_of_week (year, month, day);
4809 
4810  switch (op)
4811  {
4812  case T_WEEKDAY:
4813  /* 0 = Monday, 1 = Tuesday, ..., 6 = Sunday */
4814  if (day_of_week == 0)
4815  {
4816  day_of_week = 6;
4817  }
4818  else
4819  {
4820  day_of_week--;
4821  }
4822  db_make_int (result, day_of_week);
4823  break;
4824 
4825  case T_DAYOFWEEK:
4826  /* 1 = Sunday, 2 = Monday, ..., 7 = Saturday */
4827  day_of_week++;
4828  db_make_int (result, day_of_week);
4829  break;
4830 
4831  default:
4832  assert (false);
4833  db_make_null (result);
4834  break;
4835  }
4836 
4837  return NO_ERROR;
4838 
4839 error_exit:
4840  /* This function should return NULL if src_date is an invalid parameter or zero date. Clear the error generated by
4841  * the function call and return null. */
4842  er_clear ();
4843  db_make_null (result);
4845  {
4846  return NO_ERROR;
4847  }
4848 
4849  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error_status, 0);
4850  return error_status;
4851 }
4852 
4853 // *INDENT-OFF*
4854 // C++ implementation stuff
4855 void
4857 {
4858  auto map_func = [&] (regu_variable_node &regu, bool & stop)
4859  {
4860  switch (regu.type)
4861  {
4862  case TYPE_INARITH:
4863  case TYPE_OUTARITH:
4864  case TYPE_FUNC:
4866  break;
4867  default:
4868  break;
4869  }
4870  };
4871  reguvar.map_regu (map_func);
4872 }
4873 // *INDENT-ON*
void REGU_VARIABLE_SET_FLAG(regu_variable_node *regu, int flag)
Definition: regu_var.hpp:259
int julian_encode(int m, int d, int y)
Definition: db_date.c:113
pred_expr * lhs
int db_inet_ntoa(DB_VALUE *result_ip_string, const DB_VALUE *number)
int qdata_list_dbs(THREAD_ENTRY *thread_p, DB_VALUE *result_p, tp_domain *domain_p)
TRANID logtb_find_current_tranid(THREAD_ENTRY *thread_p)
int db_sin_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:3769
int data_readval(struct or_buf *buf, DB_VALUE *value, const tp_domain *domain, int size, bool copy, char *copy_buf, int copy_buf_len) const
int db_date_format(const DB_VALUE *date_value, const DB_VALUE *format, const DB_VALUE *date_lang, DB_VALUE *result, const TP_DOMAIN *domain)
DB_VALUE * heap_attrinfo_access(ATTR_ID attrid, HEAP_CACHE_ATTRINFO *attr_info)
Definition: heap_file.c:10665
int db_time_format(const DB_VALUE *src_value, const DB_VALUE *format, const DB_VALUE *date_lang, DB_VALUE *result, const TP_DOMAIN *domain)
bool qdata_evaluate_qprior(THREAD_ENTRY *thread_p, void *xasl_p, regu_variable_node *regu_p, DB_VALUE *result_val_p, val_descr *vd)
REGU_VALUE_ITEM * regu_list
Definition: regu_var.hpp:105
int db_make_datetime(DB_VALUE *value, const DB_DATETIME *datetime)
#define ER_TP_CANT_COERCE
Definition: error_code.h:250
int db_find_string_in_in_set(const DB_VALUE *needle, const DB_VALUE *stack, DB_VALUE *result)
static int get_hour_minute_or_second(const DB_VALUE *datetime, OPERATOR_TYPE op_type, DB_VALUE *db_value)
Definition: fetch.c:4658
#define NO_ERROR
Definition: error_code.h:46
TP_DOMAIN_STATUS tp_value_change_coll_and_codeset(DB_VALUE *src, DB_VALUE *dest, int coll_id, int codeset)
int db_get_date_quarter(const DB_VALUE *src_date, DB_VALUE *result)
static int get_year_month_or_day(const DB_VALUE *src_date, OPERATOR_TYPE op, DB_VALUE *result)
Definition: fetch.c:4728
int db_get_date_totaldays(const DB_VALUE *src_date, DB_VALUE *result)
int pr_data_writeval_disk_size(DB_VALUE *value)
int db_string_space(DB_VALUE const *count, DB_VALUE *result)
REGU_VARIABLE_LIST operand
Definition: regu_var.hpp:143
int session_get_exec_stats_and_clear(THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE *result)
Definition: session.c:2187
int qdata_divmod_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, OPERATOR_TYPE op, DB_VALUE *result_p, tp_domain *domain_p)
int session_get_last_insert_id(THREAD_ENTRY *thread_p, DB_VALUE *value, bool update_last_insert_id)
Definition: session.c:1381
int qdata_bit_xor_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
REGU_DATATYPE type
Definition: regu_var.hpp:172
REGU_VARIABLE * rightptr
Definition: regu_var.hpp:129
REGU_VARIABLE * value
Definition: regu_var.hpp:96
static int fetch_peek_dbval_pos(REGU_VARIABLE *regu_var, QFILE_TUPLE tpl, int pos, DB_VALUE **peek_dbval, QFILE_TUPLE *next_tpl)
Definition: fetch.c:4304
int session_get_variable(THREAD_ENTRY *thread_p, const DB_VALUE *name, DB_VALUE *result)
Definition: session.c:2003
DB_CONST_C_BIT db_get_bit(const DB_VALUE *value, int *length)
int db_bigint_to_binary_string(const DB_VALUE *src_bigint, DB_VALUE *result)
int db_add_int_to_datetime(DB_DATETIME *datetime, DB_BIGINT bi2, DB_DATETIME *result_datetime)
Definition: db_date.c:4656
int db_string_chr(DB_VALUE *res, DB_VALUE *dbval1, DB_VALUE *dbval2)
int qdata_strcat_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
int db_string_index_prefix(const DB_VALUE *string1, const DB_VALUE *string2, const DB_VALUE *index_type, DB_VALUE *prefix_index)
int db_get_int(const DB_VALUE *value)
int thread_get_recursion_depth(cubthread::entry *thread_p)
DB_TYPE
Definition: dbtype_def.h:670
QFILE_TUPLE_VALUE_FLAG qfile_locate_tuple_value_r(QFILE_TUPLE tuple, int index, char **tuple_value_p, int *value_size_p)
Definition: list_file.c:922
void tz_timestamp_decode_no_leap_sec(int timestamp, int *yearp, int *monthsp, int *dayp, int *hoursp, int *minutesp, int *secondsp)
Definition: tz_support.c:601
#define ER_FAILED
Definition: error_code.h:47
TYPE_EVAL_TERM et_type
REGU_VARIABLE_LIST next
Definition: regu_var.hpp:221
int db_char_to_blob(const DB_VALUE *src_value, DB_VALUE *result_value)
int db_new_time(DB_VALUE *time_val, DB_VALUE *tz_source, DB_VALUE *tz_dest, DB_VALUE *result_time)
#define CHECK_REGU_VARIABLE_XASL_STATUS(r)
Definition: xasl.h:528
int db_convert_sec_to_time(const DB_VALUE *src, DB_VALUE *result)
int db_get_string_collation(const DB_VALUE *value)
int db_timestamp_encode_ses(const DB_DATE *date, const DB_TIME *timeval, DB_TIMESTAMP *utime, TZ_ID *dest_tz_id)
Definition: db_date.c:597
const int REGU_VARIABLE_FIELD_NESTED
Definition: regu_var.hpp:158
#define OR_BUF_INIT(buf, data, size)
int xserial_get_current_value(THREAD_ENTRY *thread_p, DB_VALUE *result_num, const OID *oid_p, int cached_num)
Definition: serial.c:156
TP_DOMAIN_STATUS tp_value_auto_cast(const DB_VALUE *src, DB_VALUE *dest, const TP_DOMAIN *desired_domain)
REGU_VARIABLE * leftptr
Definition: regu_var.hpp:128
#define ER_QPROC_INVALID_XASLNODE
Definition: error_code.h:532
#define ER_QPROC_INCOMPATIBLE_TYPES
Definition: error_code.h:536
DB_VALUE_COMPARE_RESULT tp_value_compare_with_error(const DB_VALUE *value1, const DB_VALUE *value2, int do_coercion, int total_order, bool *can_compare)
#define SECONDS_OF_ONE_DAY
int db_guid(THREAD_ENTRY *thread_p, DB_VALUE *result)
int db_get_enum_codeset(const DB_VALUE *value)
int pr_is_variable_type(DB_TYPE id)
int db_power_dbval(DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
Definition: arithmetic.c:836
int db_asin_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:3921
void tz_get_session_tz_region(TZ_REGION *tz_region)
Definition: tz_support.c:767
int fetch_copy_dbval(THREAD_ENTRY *thread_p, REGU_VARIABLE *regu_var, val_descr *vd, OID *class_oid, OID *obj_oid, QFILE_TUPLE tpl, DB_VALUE *dbval)
Definition: fetch.c:4466
int db_get_time_from_dbvalue(const DB_VALUE *src_date, int *hour, int *minute, int *second, int *millisecond)
int db_string_reverse(const DB_VALUE *src_str, DB_VALUE *result_str)
int db_exp_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:659
int db_round_dbval(DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
Definition: arithmetic.c:2315
TP_DOMAIN * tp_domain_resolve_value(const DB_VALUE *val, TP_DOMAIN *dbuf)
int db_string_from_base64(DB_VALUE const *src, DB_VALUE *result)
int qdata_unary_minus_dbval(DB_VALUE *result_p, DB_VALUE *dbval_p)
int qdata_bit_not_dbval(DB_VALUE *dbval_p, DB_VALUE *result_p, tp_domain *domain_p)
bool REGU_VARIABLE_IS_FLAGED(const regu_variable_node *regu, int flag)
Definition: regu_var.hpp:253
int tz_conv_tz_time_w_zone_name(const DB_TIME *time_source, const char *source_zone, int len_source, const char *dest_zone, int len_dest, DB_TIME *time_dest)
Definition: tz_support.c:1528
TP_DOMAIN tp_Integer_domain
int er_errid(void)
int db_time_dbval(DB_VALUE *result, const DB_VALUE *datetime_value, const TP_DOMAIN *domain)
int db_from_unixtime(const DB_VALUE *src_value, const DB_VALUE *format, const DB_VALUE *date_lang, DB_VALUE *result, const TP_DOMAIN *domain)
void fetch_force_not_const_recursive(REGU_VARIABLE &reguvar)
Definition: fetch.c:4856
int db_string_sha_one(DB_VALUE const *src, DB_VALUE *result)
int db_to_timestamp(const DB_VALUE *src_str, const DB_VALUE *format_str, const DB_VALUE *date_lang, const DB_TYPE type, DB_VALUE *result_timestamp)
int tz_conv_tz_datetime_w_region(const DB_DATETIME *src_dt, const TZ_REGION *src_tz_region, const TZ_REGION *dest_tz_region, DB_DATETIME *dest_dt, TZ_ID *src_tz_id_out, TZ_ID *dest_tz_id_out)
Definition: tz_support.c:3812
#define ER_MAX_RECURSION_SQL_DEPTH
Definition: error_code.h:1453
int db_add_time(const DB_VALUE *left, const DB_VALUE *right, DB_VALUE *result, const TP_DOMAIN *domain)
enum tp_domain_status TP_DOMAIN_STATUS
int db_timestamp_encode_sys(const DB_DATE *date, const DB_TIME *timeval, DB_TIMESTAMP *utime, TZ_ID *dest_tz_id)
Definition: db_date.c:617
int qdata_subtract_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
int db_sign_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:429
bool qdata_evaluate_connect_by_root(THREAD_ENTRY *thread_p, void *xasl_p, regu_variable_node *regu_p, DB_VALUE *result_val_p, val_descr *vd)
int qdata_bit_and_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
int db_blob_length(const DB_VALUE *src_value, DB_VALUE *result_value)
const int REGU_VARIABLE_FETCH_NOT_CONST
Definition: regu_var.hpp:164
int db_atan2_dbval(DB_VALUE *result, DB_VALUE *value, DB_VALUE *value2)
Definition: arithmetic.c:4006
QFILE_TUPLE_VALUE_FLAG qfile_locate_tuple_value(QFILE_TUPLE tuple, int index, char **tuple_value_p, int *value_size_p)
Definition: list_file.c:905
int db_log_generic_dbval(DB_VALUE *result, DB_VALUE *value, long b)
Definition: arithmetic.c:4118
int db_string_substring(const MISC_OPERAND substr_operand, const DB_VALUE *src_string, const DB_VALUE *start_position, const DB_VALUE *extraction_length, DB_VALUE *sub_string)
DB_DOMAIN_INFO domain
Definition: dbtype_def.h:1082
int db_sleep(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:4976
#define QSTR_IS_BIT(s)
Definition: string_opfunc.h:44
int qdata_multiply_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
void THREAD_ENTRY
int qdata_divide_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
OPERATOR_TYPE opcode
Definition: regu_var.hpp:131
int db_string_aes_decrypt(DB_VALUE const *src, DB_VALUE const *key, DB_VALUE *result)
int db_make_string(DB_VALUE *value, DB_CONST_C_CHAR str)
DB_LOGICAL eval_pred(THREAD_ENTRY *thread_p, const PRED_EXPR *pr, val_descr *vd, OID *obj_oid)
bool pr_is_set_type(DB_TYPE type)
int db_string_position(const DB_VALUE *sub_string, const DB_VALUE *src_string, DB_VALUE *result)
unsigned int DB_TIMESTAMP
Definition: dbtype_def.h:759
int db_unix_timestamp(const DB_VALUE *src_date, DB_VALUE *result_timestamp)
int db_add_days_to_year(const DB_VALUE *src_year, const DB_VALUE *src_days, DB_VALUE *result)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int db_string_lower(const DB_VALUE *string, DB_VALUE *lower_string)
cubxasl::pred_expr * pred
Definition: regu_var.hpp:133
int db_cot_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:3833
int db_value_put_encoded_time(DB_VALUE *value, const DB_TIME *time)
Definition: db_macro.c:1357
int db_log_dbval(DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
Definition: arithmetic.c:2603
int db_bit_count_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:4178
MISC_OPERAND misc_operand
Definition: regu_var.hpp:132
#define assert(x)
void fetch_init_val_list(regu_variable_list_node *regu_list)
Definition: fetch.c:4605
OPERATOR_TYPE
struct db_domain_info::numeric_info numeric_info
int prm_get_integer_value(PARAM_ID prm_id)
#define ER_TIME_CONVERSION
Definition: error_code.h:981
TP_DOMAIN * tp_infer_common_domain(TP_DOMAIN *arg1, TP_DOMAIN *arg2)
const int REGU_VARIABLE_FIELD_COMPARE
Definition: regu_var.hpp:157
int tp_domain_status_er_set(TP_DOMAIN_STATUS status, const char *file_name, const int line_no, const DB_VALUE *src, const TP_DOMAIN *domain)
int db_string_replace(const DB_VALUE *src_string, const DB_VALUE *srch_string, const DB_VALUE *repl_string, DB_VALUE *replaced_string)
comp_eval_term et_comp
REGU_VARIABLE value
Definition: regu_var.hpp:222
int db_format(const DB_VALUE *value, const DB_VALUE *decimals, const DB_VALUE *number_lang, DB_VALUE *result, const TP_DOMAIN *domain)
static bool is_argument_wrapped_with_cast_op(const REGU_VARIABLE *regu_var)
Definition: fetch.c:4629
int db_time_encode(DB_TIME *timeval, int hour, int minute, int second)
Definition: db_date.c:370
int db_string_compare(const DB_VALUE *string1, const DB_VALUE *string2, DB_VALUE *result)
int qdata_evaluate_function(THREAD_ENTRY *thread_p, regu_variable_node *function_p, val_descr *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
#define ER_ATTEMPT_TO_USE_ZERODATE
Definition: error_code.h:1478
union cubxasl::pred_expr::@185 pe
int db_tan_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:3801
int fetch_peek_dbval(THREAD_ENTRY *thread_p, REGU_VARIABLE *regu_var, val_descr *vd, OID *class_oid, OID *obj_oid, QFILE_TUPLE tpl, DB_VALUE **peek_dbval)
Definition: fetch.c:3773
int qdata_extract_dbval(const MISC_OPERAND extr_operand, DB_VALUE *dbval_p, DB_VALUE *result_p, tp_domain *domain_p)
int db_string_pad(const MISC_OPERAND pad_operand, const DB_VALUE *src_string, const DB_VALUE *pad_length, const DB_VALUE *pad_charset, DB_VALUE *padded_string)
#define DB_VALUE_DOMAIN_TYPE(value)
Definition: dbtype.h:70
int db_to_datetime(const DB_VALUE *src_str, const DB_VALUE *format_str, const DB_VALUE *date_lang, const DB_TYPE type, DB_VALUE *result_datetime)
int db_ascii(const DB_VALUE *param, DB_VALUE *result)
int db_string_substring_index(DB_VALUE *src_string, DB_VALUE *delim_string, const DB_VALUE *count, DB_VALUE *result)
#define TP_DOMAIN_COLLATION(dom)
int db_string_upper(const DB_VALUE *string, DB_VALUE *upper_string)
struct drand48_data * rand_seed
Definition: regu_var.hpp:136
int db_acos_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:3872
#define min(a, b)
#define NUM_F_INSERT_SUBSTRING_ARGS
int db_date_dbval(DB_VALUE *result, const DB_VALUE *date_value, const TP_DOMAIN *domain)
bool qdata_evaluate_sys_connect_by_path(THREAD_ENTRY *thread_p, void *xasl_p, regu_variable_node *regu_p, DB_VALUE *value_char, DB_VALUE *result_p, val_descr *vd)
int db_string_put_cs_and_collation(DB_VALUE *value, const int codeset, const int collation_id)
Definition: db_macro.c:4164
TP_DOMAIN_STATUS tp_value_cast(const DB_VALUE *src, DB_VALUE *dest, const TP_DOMAIN *desired_domain, bool implicit_coercion)
#define TP_DOMAIN_TYPE(dom)
static int get_date_weekday(const DB_VALUE *src_date, OPERATOR_TYPE op, DB_VALUE *result)
Definition: fetch.c:4779
int session_get_trace_stats(THREAD_ENTRY *thread_p, DB_VALUE *result)
Definition: session.c:2798
int db_timestamp(const DB_VALUE *src_datetime1, const DB_VALUE *src_time2, DB_VALUE *result_datetime)
int db_str_to_date(const DB_VALUE *str, const DB_VALUE *format, const DB_VALUE *date_lang, DB_VALUE *result, TP_DOMAIN *domain)
int db_string_translate(const DB_VALUE *src_string, const DB_VALUE *from_string, const DB_VALUE *to_string, DB_VALUE *transed_string)
#define NULL
Definition: freelistheap.h:34
#define QFILE_TUPLE_LENGTH_SIZE
Definition: query_list.h:224
int db_blob_to_bit(const DB_VALUE *src_value, const DB_VALUE *length_value, DB_VALUE *result_value)
FUNC_TYPE ftype
Definition: regu_var.hpp:144
struct pr_type * type
Definition: object_domain.h:76
int db_get_day_of_week(int year, int month, int day)
Definition: db_date.c:4723
int db_string_instr(const DB_VALUE *src_string, const DB_VALUE *sub_string, const DB_VALUE *start_pos, DB_VALUE *result)
int db_date_add_interval_days(DB_VALUE *result, const DB_VALUE *date, const DB_VALUE *db_days)
void tz_get_system_tz_region(TZ_REGION *tz_region)
Definition: tz_support.c:758
const char * pr_type_name(DB_TYPE id)
int qdata_add_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
regu_variable_node * rhs
int db_value_to_enumeration_value(const DB_VALUE *src, DB_VALUE *result, const TP_DOMAIN *enum_domain)
int xserial_get_next_value(THREAD_ENTRY *thread_p, DB_VALUE *result_num, const OID *oid_p, int cached_num, int num_alloc, int is_auto_increment, bool force_set_last_insert_id)
Definition: serial.c:282
int db_value_put_encoded_date(DB_VALUE *value, const DB_DATE *date)
Definition: db_macro.c:1383
void PRIM_SET_NULL(DB_VALUE *value)
int qdata_regu_list_to_regu_array(function_node *function_p, const int array_size, regu_variable_node *regu_array[], int *num_regu)
int db_add_months(const DB_VALUE *src_date, const DB_VALUE *nmonth, DB_VALUE *result_date)
int db_from_tz(DB_VALUE *time_val, DB_VALUE *tz, DB_VALUE *time_val_with_tz)
int db_to_number(const DB_VALUE *src_str, const DB_VALUE *format_str, const DB_VALUE *number_lang, DB_VALUE *result_num)
DB_VALUE * value
Definition: regu_var.hpp:127
int qdata_bit_shift_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, OPERATOR_TYPE op, DB_VALUE *result_p, tp_domain *domain_p)
int db_string_aes_encrypt(DB_VALUE const *src, DB_VALUE const *key, DB_VALUE *result)
need_clear_type need_clear
Definition: dbtype_def.h:1084
REGU_VALUE_ITEM * current_value
Definition: regu_var.hpp:106
int db_get_cs_coll_info(DB_VALUE *result, const DB_VALUE *val, const int mode)
int db_date_diff(const DB_VALUE *date_value1, const DB_VALUE *date_value2, DB_VALUE *result)
int db_trunc_dbval(DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
Definition: arithmetic.c:3311
#define cmp
Definition: mprec.h:351
int pr_clear_value(DB_VALUE *value)
DB_BIGINT db_get_bigint(const DB_VALUE *value)
int qdata_bit_or_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
int db_get_date_from_days(const DB_VALUE *src, DB_VALUE *result)
int db_string_char_length(const DB_VALUE *string, DB_VALUE *char_count)
int session_define_variable(THREAD_ENTRY *thread_p, DB_VALUE *name, DB_VALUE *value, DB_VALUE *result)
Definition: session.c:1970
#define max(a, b)
const int REGU_VARIABLE_APPLY_COLLATION
Definition: regu_var.hpp:159
int64_t DB_BIGINT
Definition: dbtype_def.h:751
#define ER_DATE_CONVERSION
Definition: error_code.h:242
static int fetch_peek_arith(THREAD_ENTRY *thread_p, REGU_VARIABLE *regu_var, val_descr *vd, OID *obj_oid, QFILE_TUPLE tpl, DB_VALUE **peek_dbval)
Definition: fetch.c:82
int db_clob_to_char(const DB_VALUE *src_value, const DB_VALUE *codeset_value, DB_VALUE *result_value)
void util_get_second_and_ms_since_epoch(time_t *secs, int *msec)
Definition: util_func.c:829
int db_last_day(const DB_VALUE *src_date, DB_VALUE *result_day)
DB_VALUE * dbval_ptr
int db_inet_aton(DB_VALUE *result_numbered_ip, const DB_VALUE *string)
#define TP_IS_CHAR_TYPE(typeid)
TP_DOMAIN_COLL_ACTION collation_flag
Definition: object_domain.h:94
int fetch_val_list(THREAD_ENTRY *thread_p, regu_variable_list_node *regu_list, val_descr *vd, OID *class_oid, OID *obj_oid, QFILE_TUPLE tpl, int peek)
Definition: fetch.c:4526
static void error(const char *msg)
Definition: gencat.c:331
int db_date_add_interval_expr(DB_VALUE *result, const DB_VALUE *date, const DB_VALUE *expr, const int unit)
int db_string_to_base64(DB_VALUE const *src, DB_VALUE *result)
static int rc
Definition: serial.c:50
#define TP_TYPE_HAS_COLLATION(typeid)
int db_cos_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:3737
DB_DATETIME sys_datetime
#define ARG_FILE_LINE
Definition: error_manager.h:44
int pr_clone_value(const DB_VALUE *src, DB_VALUE *dest)
const int REGU_VARIABLE_STRICT_TYPE_CAST
Definition: regu_var.hpp:167
OID * db_get_oid(const DB_VALUE *value)
QFILE_TUPLE_VALUE_FLAG
Definition: query_list.h:291
const int REGU_VARIABLE_INFER_COLLATION
Definition: regu_var.hpp:162
unsigned int DB_TIME
Definition: dbtype_def.h:754
int db_sqrt_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:731
int db_convert_time_to_sec(const DB_VALUE *src_date, DB_VALUE *result)
int pr_is_string_type(DB_TYPE type)
unsigned int DB_DATE
Definition: dbtype_def.h:771
int qdata_get_cardinality(THREAD_ENTRY *thread_p, DB_VALUE *db_class_name, DB_VALUE *db_index_name, DB_VALUE *db_key_position, DB_VALUE *result_p)
int db_get_date_dayofyear(const DB_VALUE *src_date, DB_VALUE *result)
#define ER_QPROC_INVALID_VALLIST_INDEX
Definition: error_code.h:525
int db_hex(const DB_VALUE *param, DB_VALUE *result)
void thread_dec_recursion_depth(cubthread::entry *thread_p)
#define strlen(s1)
Definition: intl_support.c:43
int db_datetime_encode(DB_DATETIME *datetime, int month, int day, int year, int hour, int minute, int second, int millisecond)
Definition: db_date.c:4597
int db_string_trim(const MISC_OPERAND tr_operand, const DB_VALUE *trim_charset, const DB_VALUE *src_string, DB_VALUE *trimmed_string)
int db_convert_to_time(const DB_VALUE *src_hour, const DB_VALUE *src_minute, const DB_VALUE *src_second, DB_VALUE *result)
DB_TIMESTAMP sys_epochtime
const char * tz_get_system_timezone(void)
Definition: tz_support.c:749
int db_enum_put_cs_and_collation(DB_VALUE *value, const int codeset, const int collation_id)
Definition: db_macro.c:4191
int db_to_time(const DB_VALUE *src_str, const DB_VALUE *format_str, const DB_VALUE *date_lang, const DB_TYPE type, DB_VALUE *result_time)
unsigned int date
Definition: dbtype_def.h:776
char * QFILE_TUPLE
Definition: query_list.h:281
int db_radians_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:4086
bool prm_get_bool_value(PARAM_ID prm_id)
int db_months_between(const DB_VALUE *start_mon, const DB_VALUE *end_mon, DB_VALUE *result_mon)
#define QSTR_IS_ANY_CHAR_OR_BIT(s)
Definition: string_opfunc.h:47
#define PI
Definition: arithmetic.h:34
class regu_variable_node REGU_VARIABLE
Definition: regu_var.hpp:64
int db_get_string_size(const DB_VALUE *value)
DB_C_SHORT db_get_short(const DB_VALUE *value)
struct drand48_data * qmgr_get_rand_buf(THREAD_ENTRY *thread_p)
void er_clear(void)
int db_to_date(const DB_VALUE *src_str, const DB_VALUE *format_str, const DB_VALUE *date_lang, DB_VALUE *result_date)
const char * tz_get_session_local_timezone(void)
Definition: tz_support.c:739
int db_time_diff(const DB_VALUE *val1, const DB_VALUE *val2, DB_VALUE *result)
int db_crc32_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:5020
#define ER_QSTR_INCOMPATIBLE_COLLATIONS
Definition: error_code.h:1472
int db_least_or_greatest(DB_VALUE *arg1, DB_VALUE *arg2, DB_VALUE *result, bool least)
Definition: arithmetic.c:6454
#define DB_VALUE_TYPE(value)
Definition: dbtype.h:72
int db_get_datetime_from_dbvalue(const DB_VALUE *src_date, int *year, int *month, int *day, int *hour, int *minute, int *second, int *millisecond, const char **endp)
int i
Definition: dynamic_load.c:954
double drand
int db_to_char(const DB_VALUE *src_value, const DB_VALUE *format_or_length, const DB_VALUE *lang_str, DB_VALUE *result_str, const TP_DOMAIN *domain)
int db_make_null(DB_VALUE *value)
DB_TYPE id
#define DB_IS_NULL(value)
Definition: dbtype.h:63
int db_date_sub_interval_days(DB_VALUE *result, const DB_VALUE *date, const DB_VALUE *db_days)
int db_string_sha_two(DB_VALUE const *src, DB_VALUE const *hash_len, DB_VALUE *result)
int db_make_double(DB_VALUE *value, const DB_C_DOUBLE num)
int session_get_row_count(THREAD_ENTRY *thread_p, int *row_count)
Definition: session.c:1562
int db_mod_dbval(DB_VALUE *result, DB_VALUE *value1, DB_VALUE *value2)
Definition: arithmetic.c:1928
int db_date_sub_interval_expr(DB_VALUE *result, const DB_VALUE *date, const DB_VALUE *expr, const int unit)
int db_string_bit_length(const DB_VALUE *string, DB_VALUE *bit_count)
bool qdata_copy_db_value(DB_VALUE *dest_p, const DB_VALUE *src_p)
Definition: query_opfunc.c:310
int db_floor_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:87
#define EXECUTE_REGU_VARIABLE_XASL(thread_p, r, v)
Definition: xasl.h:499
TYPE_PRED_EXPR type
const int REGU_VARIABLE_FETCH_ALL_CONST
Definition: regu_var.hpp:163
int db_char_to_clob(const DB_VALUE *src_value, DB_VALUE *result_value)
int db_string_repeat(const DB_VALUE *src_string, const DB_VALUE *count, DB_VALUE *result)
int db_make_timestamp(DB_VALUE *value, const DB_C_TIMESTAMP timeval)
int db_make_int(DB_VALUE *value, const int num)
int db_get_string_length(const DB_VALUE *value)
int db_conv(const DB_VALUE *num, const DB_VALUE *from_base, const DB_VALUE *to_base, DB_VALUE *result)
REGU_VARIABLE * thirdptr
Definition: regu_var.hpp:130
int db_tz_offset(const DB_VALUE *src_str, DB_VALUE *result_str, DB_DATETIME *datetime)
int db_make_oid(DB_VALUE *value, const OID *oid)
int db_atan_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:3970
union cubxasl::eval_term::@184 et
int db_sys_timezone(DB_VALUE *result_timezone)
void thread_inc_recursion_depth(cubthread::entry *thread_p)
int db_typeof_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:4302
int db_clob_length(const DB_VALUE *src_value, DB_VALUE *result_value)
int db_string_md5(DB_VALUE const *val, DB_VALUE *result)
#define ER_QPROC_INVALID_DATATYPE
Definition: error_code.h:534
int db_abs_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:565
pred_expr * rhs
int db_conv_tz(DB_VALUE *time_val, DB_VALUE *result_time)
static int fetch_peek_min_max_value_of_width_bucket_func(THREAD_ENTRY *thread_p, REGU_VARIABLE *regu_var, val_descr *vd, OID *obj_oid, QFILE_TUPLE tpl, DB_VALUE **min, DB_VALUE **max)
Definition: fetch.c:4352
int day_of_week(int jul_day)
Definition: db_date.c:176
TP_DOMAIN_STATUS tp_value_cast_force(const DB_VALUE *src, DB_VALUE *dest, const TP_DOMAIN *desired_domain, bool implicit_coercion)
int db_ceil_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:254
int db_get_string_codeset(const DB_VALUE *value)
int db_degrees_dbval(DB_VALUE *result, DB_VALUE *value)
Definition: arithmetic.c:4054
int db_bit_to_blob(const DB_VALUE *src_value, DB_VALUE *result_value)
unsigned int time
Definition: dbtype_def.h:777
int db_get_date_week(const DB_VALUE *src_date, const DB_VALUE *mode, DB_VALUE *result)
#define ER_QPROC_GENERIC_FUNCTION_FAILURE
Definition: error_code.h:861
int db_like_bound(const DB_VALUE *const src_pattern, const DB_VALUE *const src_escape, DB_VALUE *const result_bound, const bool compute_lower_bound)
#define TP_DOMAIN_COLLATION_FLAG(dom)
DB_VALUE * value
Definition: regu_var.hpp:142
int db_width_bucket(DB_VALUE *result, const DB_VALUE *value1, const DB_VALUE *value2, const DB_VALUE *value3, const DB_VALUE *value4)
Definition: arithmetic.c:4598
TP_DOMAIN * domain
Definition: regu_var.hpp:125