CUBRID Engine  latest
query_opfunc.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  * query_opfunc.c - The manipulation of data stored in the XASL nodes
21  */
22 
23 #ident "$Id$"
24 
25 #include "config.h"
26 
27 #include <stdio.h>
28 #include <string.h>
29 #include <float.h>
30 #include <math.h>
31 #include <assert.h>
32 
33 #include "query_opfunc.h"
34 
35 #include "system_parameter.h"
36 #include "error_manager.h"
37 #include "fetch.h"
38 #include "list_file.h"
39 #include "object_domain.h"
40 #include "object_primitive.h"
41 #include "object_representation.h"
42 #include "set_object.h"
43 #include "query_executor.h"
44 #include "databases_file.h"
45 #include "tz_support.h"
46 #include "memory_hash.h"
47 #include "numeric_opfunc.h"
48 #include "tz_support.h"
49 #include "db_date.h"
50 #include "dbtype.h"
51 #include "query_dump.h"
52 #include "query_list.h"
53 #include "db_json.hpp"
54 #include "arithmetic.h"
55 #include "xasl.h"
56 #include "xasl_aggregate.hpp"
57 #include "xasl_analytic.hpp"
58 
59 #include "dbtype.h"
60 
61 #include <chrono>
62 #include <regex>
63 
64 #define NOT_NULL_VALUE(a, b) ((a) ? (a) : (b))
65 #define INITIAL_OID_STACK_SIZE 1
66 
67 #define SYS_CONNECT_BY_PATH_MEM_STEP 256
68 
69 static bool qdata_is_zero_value_date (DB_VALUE * dbval_p);
70 
71 static int qdata_add_short (short s, DB_VALUE * dbval_p, DB_VALUE * result_p);
72 static int qdata_add_int (int i1, int i2, DB_VALUE * result_p);
73 static int qdata_add_bigint (DB_BIGINT i1, DB_BIGINT i2, DB_VALUE * result_p);
74 static int qdata_add_float (float f1, float f2, DB_VALUE * result_p);
75 static int qdata_add_double (double d1, double d2, DB_VALUE * result_p);
76 static double qdata_coerce_numeric_to_double (DB_VALUE * numeric_val_p);
77 static void qdata_coerce_dbval_to_numeric (DB_VALUE * dbval_p, DB_VALUE * result_p);
78 static int qdata_add_numeric (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
79 static int qdata_add_numeric_to_monetary (DB_VALUE * numeric_val_p, DB_VALUE * monetary_val_p, DB_VALUE * result_p);
80 static int qdata_add_monetary (double d1, double d2, DB_CURRENCY type, DB_VALUE * result_p);
81 static int qdata_add_bigint_to_time (DB_VALUE * time_val_p, DB_BIGINT add_time, DB_VALUE * result_p);
82 static int qdata_add_short_to_utime_asymmetry (DB_VALUE * utime_val_p, short s, unsigned int *utime,
83  DB_VALUE * result_p, TP_DOMAIN * domain_p);
84 static int qdata_add_int_to_utime_asymmetry (DB_VALUE * utime_val_p, int i, unsigned int *utime, DB_VALUE * result_p,
85  TP_DOMAIN * domain_p);
86 static int qdata_add_short_to_utime (DB_VALUE * utime_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p);
87 static int qdata_add_int_to_utime (DB_VALUE * utime_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p);
88 static int qdata_add_bigint_to_utime (DB_VALUE * utime_val_p, DB_BIGINT bi, DB_VALUE * result_p, TP_DOMAIN * domain_p);
89 static int qdata_add_short_to_timestamptz (DB_VALUE * ts_tz_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p);
90 static int qdata_add_int_to_timestamptz (DB_VALUE * ts_tz_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p);
91 static int qdata_add_bigint_to_timestamptz (DB_VALUE * ts_tz_val_p, DB_BIGINT bi, DB_VALUE * result_p,
92  TP_DOMAIN * domain_p);
93 static int qdata_add_short_to_datetime (DB_VALUE * datetime_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p);
94 static int qdata_add_int_to_datetime (DB_VALUE * datetime_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p);
95 static int qdata_add_bigint_to_datetime (DB_VALUE * datetime_val_p, DB_BIGINT bi, DB_VALUE * result_p,
96  TP_DOMAIN * domain_p);
97 static int qdata_add_short_to_date (DB_VALUE * date_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p);
98 static int qdata_add_int_to_date (DB_VALUE * date_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p);
99 static int qdata_add_bigint_to_date (DB_VALUE * date_val_p, DB_BIGINT i, DB_VALUE * result_p, TP_DOMAIN * domain_p);
100 
101 static int qdata_add_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
102  TP_DOMAIN * domain_p);
103 static int qdata_add_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p);
104 static int qdata_add_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
105  TP_DOMAIN * domain_p);
106 static int qdata_add_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
107 static int qdata_add_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
108 static int qdata_add_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
109 static int qdata_add_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
110 static int qdata_add_chars_to_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p);
111 static int qdata_add_sequence_to_dbval (DB_VALUE * seq_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
112  TP_DOMAIN * domain_p);
113 static int qdata_add_time_to_dbval (DB_VALUE * time_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
114 static int qdata_add_utime_to_dbval (DB_VALUE * utime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
115  TP_DOMAIN * domain_p);
116 static int qdata_add_timestamptz_to_dbval (DB_VALUE * ts_tz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
117 static int qdata_add_datetime_to_dbval (DB_VALUE * datetime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
118  TP_DOMAIN * domain_p);
119 static int qdata_add_datetimetz_to_dbval (DB_VALUE * datetimetz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
120 static int qdata_add_date_to_dbval (DB_VALUE * date_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
121  TP_DOMAIN * domain_p);
122 static int qdata_coerce_result_to_domain (DB_VALUE * result_p, TP_DOMAIN * domain_p);
123 static int qdata_cast_to_domain (DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p);
124 
125 static int qdata_subtract_short (short s1, short s2, DB_VALUE * result_p);
126 static int qdata_subtract_int (int i1, int i2, DB_VALUE * result_p);
127 static int qdata_subtract_bigint (DB_BIGINT i1, DB_BIGINT i2, DB_VALUE * result_p);
128 static int qdata_subtract_float (float f1, float f2, DB_VALUE * result_p);
129 static int qdata_subtract_double (double d1, double d2, DB_VALUE * result_p);
130 static int qdata_subtract_monetary (double d1, double d2, DB_CURRENCY currency, DB_VALUE * result_p);
131 static int qdata_subtract_time (DB_TIME u1, DB_TIME u2, DB_VALUE * result_p);
132 static int qdata_subtract_utime (DB_UTIME u1, DB_UTIME u2, DB_VALUE * result_p);
133 static int qdata_subtract_utime_to_short_asymmetry (DB_VALUE * utime_val_p, short s, unsigned int *utime,
134  DB_VALUE * result_p, TP_DOMAIN * domain_p);
135 static int qdata_subtract_utime_to_int_asymmetry (DB_VALUE * utime_val_p, int i, unsigned int *utime,
136  DB_VALUE * result_p, TP_DOMAIN * domain_p);
137 static int qdata_subtract_datetime_to_int (DB_DATETIME * dt1, DB_BIGINT i2, DB_VALUE * result_p);
138 static int qdata_subtract_datetime (DB_DATETIME * dt1, DB_DATETIME * dt2, DB_VALUE * result_p);
139 static int qdata_subtract_datetime_to_int_asymmetry (DB_VALUE * datetime_val_p, DB_BIGINT i, DB_DATETIME * datetime,
140  DB_VALUE * result_p, TP_DOMAIN * domain_p);
141 static int qdata_subtract_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
142 static int qdata_subtract_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
143 static int qdata_subtract_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
144 static int qdata_subtract_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
145 static int qdata_subtract_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
146 static int qdata_subtract_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
147 static int qdata_subtract_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
148 static int qdata_subtract_sequence_to_dbval (DB_VALUE * seq_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
149  TP_DOMAIN * domain_p);
150 static int qdata_subtract_time_to_dbval (DB_VALUE * time_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
151 static int qdata_subtract_utime_to_dbval (DB_VALUE * utime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
152  TP_DOMAIN * domain_p);
153 static int qdata_subtract_timestampltz_to_dbval (DB_VALUE * ts_ltz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
154  TP_DOMAIN * domain_p);
155 static int qdata_subtract_timestamptz_to_dbval (DB_VALUE * utime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
156  TP_DOMAIN * domain_p);
157 static int qdata_subtract_datetime_to_dbval (DB_VALUE * datetime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
158  TP_DOMAIN * domain_p);
159 static int qdata_subtract_datetimetz_to_dbval (DB_VALUE * dt_tz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
160  TP_DOMAIN * domain_p);
161 static int qdata_subtract_date_to_dbval (DB_VALUE * date_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
162  TP_DOMAIN * domain_p);
163 
164 static int qdata_multiply_short (DB_VALUE * short_val_p, short s2, DB_VALUE * result_p);
165 static int qdata_multiply_int (DB_VALUE * int_val_p, int i2, DB_VALUE * result_p);
166 static int qdata_multiply_bigint (DB_VALUE * bigint_val_p, DB_BIGINT bi2, DB_VALUE * result_p);
167 static int qdata_multiply_float (DB_VALUE * float_val_p, float f2, DB_VALUE * result_p);
168 static int qdata_multiply_double (double d1, double d2, DB_VALUE * result_p);
169 static int qdata_multiply_numeric (DB_VALUE * numeric_val_p, DB_VALUE * dbval, DB_VALUE * result_p);
170 static int qdata_multiply_monetary (DB_VALUE * monetary_val_p, double d, DB_VALUE * result_p);
171 
172 static int qdata_multiply_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
173 static int qdata_multiply_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
174 static int qdata_multiply_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
175 static int qdata_multiply_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
176 static int qdata_multiply_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
177 static int qdata_multiply_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
178 static int qdata_multiply_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
179 static int qdata_multiply_sequence_to_dbval (DB_VALUE * seq_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
180  TP_DOMAIN * domain_p);
181 
182 static bool qdata_is_divided_zero (DB_VALUE * dbval_p);
183 static int qdata_divide_short (short s1, short s2, DB_VALUE * result_p);
184 static int qdata_divide_int (int i1, int i2, DB_VALUE * result_p);
185 static int qdata_divide_bigint (DB_BIGINT bi1, DB_BIGINT bi2, DB_VALUE * result_p);
186 static int qdata_divide_float (float f1, float f2, DB_VALUE * result_p);
187 static int qdata_divide_double (double d1, double d2, DB_VALUE * result_p, bool is_check_overflow);
188 static int qdata_divide_monetary (double d1, double d2, DB_CURRENCY currency, DB_VALUE * result_p,
189  bool is_check_overflow);
190 
191 static int qdata_divide_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
192 static int qdata_divide_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
193 static int qdata_divide_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
194 static int qdata_divide_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
195 static int qdata_divide_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
196 static int qdata_divide_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
197 static int qdata_divide_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p);
198 
200  VAL_DESCR * val_desc_p);
201 static int qdata_convert_dbvals_to_set (THREAD_ENTRY * thread_p, DB_TYPE stype, REGU_VARIABLE * func,
202  VAL_DESCR * val_desc_p, OID * obj_oid_p, QFILE_TUPLE tuple);
203 static int qdata_evaluate_generic_function (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p,
204  OID * obj_oid_p, QFILE_TUPLE tuple);
205 static int qdata_get_class_of_function (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p,
206  OID * obj_oid_p, QFILE_TUPLE tuple);
207 
208 static int qdata_convert_table_to_set (THREAD_ENTRY * thread_p, DB_TYPE stype, REGU_VARIABLE * func,
209  VAL_DESCR * val_desc_p);
210 
211 static int qdata_insert_substring_function (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p,
212  OID * obj_oid_p, QFILE_TUPLE tuple);
213 
214 static int qdata_elt (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p, OID * obj_oid_p,
215  QFILE_TUPLE tuple);
216 static int qdata_benchmark (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p,
217  OID * obj_oid_p, QFILE_TUPLE tuple);
218 
219 static int qdata_regexp_function (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p,
220  OID * obj_oid_p, QFILE_TUPLE tuple);
221 
222 static int qdata_convert_operands_to_value_and_call (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p,
223  VAL_DESCR * val_desc_p, OID * obj_oid_p, QFILE_TUPLE tuple,
224  int (*function_to_call) (DB_VALUE *, DB_VALUE * const *,
225  int const));
226 
227 static bool
229 {
230  DB_TYPE type;
231  DB_UTIME *utime;
232  DB_DATE *date;
233  DB_DATETIME *datetime;
234  DB_TIMESTAMPTZ *ts_tz;
235  DB_DATETIMETZ *dt_tz;
236 
237  if (DB_IS_NULL (dbval_p)) /* NULL is not zero value */
238  {
239  return false;
240  }
241 
242  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
243  if (TP_IS_DATE_TYPE (type))
244  {
245  switch (type)
246  {
247  case DB_TYPE_TIMESTAMP:
249  utime = db_get_timestamp (dbval_p);
250  return (*utime == 0);
251  case DB_TYPE_TIMESTAMPTZ:
252  ts_tz = db_get_timestamptz (dbval_p);
253  return (ts_tz->timestamp == 0);
254  case DB_TYPE_DATETIME:
255  case DB_TYPE_DATETIMELTZ:
256  datetime = db_get_datetime (dbval_p);
257  return (datetime->date == 0 && datetime->time == 0);
258  case DB_TYPE_DATETIMETZ:
259  dt_tz = db_get_datetimetz (dbval_p);
260  return (dt_tz->datetime.date == 0 && dt_tz->datetime.time == 0);
261  case DB_TYPE_DATE:
262  date = db_get_date (dbval_p);
263  return (*date == 0);
264  default:
265  break;
266  }
267  }
268 
269  return false;
270 }
271 
272 /*
273  * qdata_set_value_list_to_null () -
274  * return:
275  * val_list(in) : Value List
276  *
277  * Note: Set all db_values on the value list to null.
278  */
279 void
281 {
282  QPROC_DB_VALUE_LIST db_val_list;
283 
284  if (val_list_p == NULL)
285  {
286  return;
287  }
288 
289  db_val_list = val_list_p->valp;
290  while (db_val_list)
291  {
292  pr_clear_value (db_val_list->val);
293  db_val_list = db_val_list->next;
294  }
295 }
296 
297 /*
298  * COPY ROUTINES
299  */
300 
301 /*
302  * qdata_copy_db_value () -
303  * return: int (true on success, false on failure)
304  * dbval1(in) : Destination db_value node
305  * dbval2(in) : Source db_value node
306  *
307  * Note: Copy source value to destination value.
308  */
309 bool
310 qdata_copy_db_value (DB_VALUE * dest_p, const DB_VALUE * src_p)
311 {
312  PR_TYPE *pr_type_p;
313  DB_TYPE src_type;
314 
315  /* check if there is nothing to do, so we don't clobber a db_value if we happen to try to copy it to itself */
316  if (dest_p == src_p)
317  {
318  return true;
319  }
320 
321  /* clear any value from a previous iteration */
322  (void) pr_clear_value (dest_p);
323 
324  src_type = DB_VALUE_DOMAIN_TYPE (src_p);
325  pr_type_p = pr_type_from_id (src_type);
326  if (pr_type_p == NULL)
327  {
328  return false;
329  }
330 
331  if (pr_type_p->setval (dest_p, src_p, true) == NO_ERROR)
332  {
333  return true;
334  }
335  else
336  {
337  return false;
338  }
339 }
340 
341 /*
342  * qdata_copy_db_value_to_tuple_value () -
343  * return: int (true on success, false on failure)
344  * dbval(in) : Source dbval node
345  * clear_compressed_string(in): true, if need to clear compressed string
346  * tvalp(in) : Tuple value
347  * tval_size(out) : Set to the tuple value size
348  *
349  * Note: Copy an db_value to an tuple value.
350  * THIS ROUTINE ASSUMES THAT THE VALUE WILL FIT IN THE TPL!!!!
351  */
352 int
353 qdata_copy_db_value_to_tuple_value (DB_VALUE * dbval_p, bool clear_compressed_string, char *tuple_val_p,
354  int *tuple_val_size)
355 {
356  char *val_p;
357  int val_size, align, rc;
358  OR_BUF buf;
359  PR_TYPE *pr_type;
360  DB_TYPE dbval_type;
361 
362  if (DB_IS_NULL (dbval_p))
363  {
364  QFILE_PUT_TUPLE_VALUE_FLAG (tuple_val_p, V_UNBOUND);
365  QFILE_PUT_TUPLE_VALUE_LENGTH (tuple_val_p, 0);
366  *tuple_val_size = QFILE_TUPLE_VALUE_HEADER_SIZE;
367  }
368  else
369  {
370  QFILE_PUT_TUPLE_VALUE_FLAG (tuple_val_p, V_BOUND);
371  val_p = (char *) tuple_val_p + QFILE_TUPLE_VALUE_HEADER_SIZE;
372 
373  dbval_type = DB_VALUE_DOMAIN_TYPE (dbval_p);
374  pr_type = pr_type_from_id (dbval_type);
375  if (pr_type == NULL)
376  {
377  return ER_FAILED;
378  }
379 
380  val_size = pr_data_writeval_disk_size (dbval_p);
381  OR_BUF_INIT (buf, val_p, val_size);
382  rc = pr_type->data_writeval (&buf, dbval_p);
383 
384  if (rc != NO_ERROR)
385  {
386  /* ER_TF_BUFFER_OVERFLOW means that val_size or packing is bad. */
388  return ER_FAILED;
389  }
390 
391  /* Good moment to clear the compressed_string that might have been stored in the DB_VALUE */
392  if (clear_compressed_string)
393  {
394  if (dbval_type == DB_TYPE_VARCHAR || dbval_type == DB_TYPE_VARNCHAR)
395  {
396  rc = pr_clear_compressed_string (dbval_p);
397  if (rc != NO_ERROR)
398  {
399  /* This should not happen for now */
400  assert (false);
401  return ER_FAILED;
402  }
403  }
404  }
405 
406  /* I don't know if the following is still true. */
407  /* since each tuple data value field is already aligned with MAX_ALIGNMENT, val_size by itself can be used to
408  * find the maximum alignment for the following field which is next val_header */
409 
410  align = DB_ALIGN (val_size, MAX_ALIGNMENT); /* to align for the next field */
411  *tuple_val_size = QFILE_TUPLE_VALUE_HEADER_SIZE + align;
412  QFILE_PUT_TUPLE_VALUE_LENGTH (tuple_val_p, align);
413 
414 #if !defined(NDEBUG)
415  /* suppress valgrind UMW error */
416  memset (tuple_val_p + QFILE_TUPLE_VALUE_HEADER_SIZE + val_size, 0, align - val_size);
417 #endif
418  }
419 
420  return NO_ERROR;
421 }
422 
423 /*
424  * qdata_copy_valptr_list_to_tuple () -
425  * return: NO_ERROR, or ER_code
426  * valptr_list(in) : Value pointer list
427  * vd(in) : Value descriptor
428  * tplrec(in) : Tuple descriptor
429  *
430  * Note: Copy valptr_list values to tuple descriptor. Regu variables
431  * that are hidden columns are not copied to the list file tuple
432  */
433 int
434 qdata_copy_valptr_list_to_tuple (THREAD_ENTRY * thread_p, valptr_list_node * valptr_list_p, val_descr * val_desc_p,
435  qfile_tuple_record * tuple_record_p)
436 {
437  REGU_VARIABLE_LIST reg_var_p;
438  DB_VALUE *dbval_p;
439  char *tuple_p;
440  int k, tval_size, tlen, tpl_size;
441  int n_size, toffset;
442  bool clear_compressed_string = false;
443 
444  tpl_size = 0;
446  toffset = 0; /* tuple offset position */
447 
448  /* skip the length of the tuple, we'll fill it in after we know what it is */
449  tuple_p = (char *) (tuple_record_p->tpl) + tlen;
450  toffset += tlen;
451 
452  /* copy each value into the tuple */
453  reg_var_p = valptr_list_p->valptrp;
454  for (k = 0; k < valptr_list_p->valptr_cnt; k++, reg_var_p = reg_var_p->next)
455  {
456  if (!REGU_VARIABLE_IS_FLAGED (&reg_var_p->value, REGU_VARIABLE_HIDDEN_COLUMN))
457  {
458  dbval_p = qdata_get_dbval_from_constant_regu_variable (thread_p, &reg_var_p->value, val_desc_p);
459  if (dbval_p == NULL)
460  {
461  return ER_FAILED;
462  }
463 
465  {
466  clear_compressed_string = false;
467  }
468  else
469  {
470  clear_compressed_string = true;
471  }
472 
473  n_size = qdata_get_tuple_value_size_from_dbval (dbval_p);
474  if (n_size == ER_FAILED)
475  {
476  return ER_FAILED;
477  }
478 
479  if ((tuple_record_p->size - toffset) < n_size)
480  {
481  /* no space left in tuple to put next item, increase the tuple size by the max of n_size and DB_PAGE_SIZE
482  * since we can't compute the actual tuple size without re-evaluating the expressions. This guarantees
483  * that we can at least get the next value into the tuple. */
484  tpl_size = MAX (tuple_record_p->size, QFILE_TUPLE_LENGTH_SIZE);
485  tpl_size += MAX (n_size, DB_PAGESIZE);
486  if (tuple_record_p->size == 0)
487  {
488  tuple_record_p->tpl = (char *) db_private_alloc (thread_p, tpl_size);
489  if (tuple_record_p->tpl == NULL)
490  {
491  return ER_FAILED;
492  }
493  }
494  else
495  {
496  tuple_record_p->tpl = (char *) db_private_realloc (thread_p, tuple_record_p->tpl, tpl_size);
497  if (tuple_record_p->tpl == NULL)
498  {
499  return ER_FAILED;
500  }
501  }
502 
503  tuple_record_p->size = tpl_size;
504  tuple_p = (char *) (tuple_record_p->tpl) + toffset;
505  }
506 
507  if (qdata_copy_db_value_to_tuple_value (dbval_p, clear_compressed_string, tuple_p, &tval_size) != NO_ERROR)
508  {
509  return ER_FAILED;
510  }
511 
512  tlen += tval_size;
513  tuple_p += tval_size;
514  toffset += tval_size;
515  }
516  }
517 
518  /* now that we know the tuple size, set it. */
519  QFILE_PUT_TUPLE_LENGTH (tuple_record_p->tpl, tlen);
520 
521  return NO_ERROR;
522 }
523 
524 /*
525  * qdata_generate_tuple_desc_for_valptr_list () -
526  * return: QPROC_TPLDESCR_SUCCESS on success or
527  * QP_TPLDESCR_RETRY_xxx,
528  * QPROC_TPLDESCR_FAILURE
529  * valptr_list(in) : Value pointer list
530  * vd(in) : Value descriptor
531  * tdp(in) : Tuple descriptor
532  *
533  * Note: Generate tuple descriptor for given valptr_list values.
534  * Regu variables that are hidden columns are not copied
535  * to the list file tuple
536  */
539  val_descr * val_desc_p, qfile_tuple_descriptor * tuple_desc_p)
540 {
541  REGU_VARIABLE_LIST reg_var_p;
542  int i;
543  int value_size;
545  DB_TYPE dbval_type;
546 
547  tuple_desc_p->tpl_size = QFILE_TUPLE_LENGTH_SIZE; /* set tuple size as header size */
548  tuple_desc_p->f_cnt = 0;
549 
550  /* copy each value pointer into the each tdp field */
551  reg_var_p = valptr_list_p->valptrp;
552  for (i = 0; i < valptr_list_p->valptr_cnt; i++)
553  {
555  {
556  tuple_desc_p->f_valp[tuple_desc_p->f_cnt] =
557  qdata_get_dbval_from_constant_regu_variable (thread_p, &reg_var_p->value, val_desc_p);
558 
559  if (tuple_desc_p->f_valp[tuple_desc_p->f_cnt] == NULL)
560  {
561  status = QPROC_TPLDESCR_FAILURE;
562  goto exit_with_status;
563  }
564 
565  /* Set clear_f_val_at_clone_decache to avoid memory issues */
566  assert (tuple_desc_p->clear_f_val_at_clone_decache != NULL);
568  {
569  tuple_desc_p->clear_f_val_at_clone_decache[tuple_desc_p->f_cnt] = true;
570  }
571  else
572  {
573  tuple_desc_p->clear_f_val_at_clone_decache[tuple_desc_p->f_cnt] = false;
574  }
575 
576  dbval_type = DB_VALUE_DOMAIN_TYPE (tuple_desc_p->f_valp[tuple_desc_p->f_cnt]);
577 
578  /* SET data-type cannot use tuple descriptor */
579  if (pr_is_set_type (dbval_type))
580  {
582  goto exit_with_status;
583  }
584 
585  /* add aligned field size to tuple size */
586  value_size = qdata_get_tuple_value_size_from_dbval (tuple_desc_p->f_valp[tuple_desc_p->f_cnt]);
587  if (value_size == ER_FAILED)
588  {
589  status = QPROC_TPLDESCR_FAILURE;
590  goto exit_with_status;
591  }
592 
593  /* The compressed string will be deallocated later, after copying db_value into tuple. */
594 
595  tuple_desc_p->tpl_size += value_size;
596  tuple_desc_p->f_cnt += 1; /* increase field number */
597  }
598 
599  reg_var_p = reg_var_p->next;
600  }
601 
602  /* BIG RECORD cannot use tuple descriptor */
603  if (tuple_desc_p->tpl_size >= QFILE_MAX_TUPLE_SIZE_IN_PAGE)
604  {
606  }
607 
608 exit_with_status:
609 
610  return status;
611 }
612 
613 /*
614  * qdata_set_valptr_list_unbound () -
615  * return: NO_ERROR, or ER_code
616  * valptr_list(in) : Value pointer list
617  * vd(in) : Value descriptor
618  *
619  * Note: Set valptr_list values UNBOUND.
620  */
621 int
622 qdata_set_valptr_list_unbound (THREAD_ENTRY * thread_p, valptr_list_node * valptr_list_p, val_descr * val_desc_p)
623 {
624  REGU_VARIABLE_LIST reg_var_p;
625  DB_VALUE *dbval_p;
626  int i;
627 
628  reg_var_p = valptr_list_p->valptrp;
629  for (i = 0; i < valptr_list_p->valptr_cnt; i++)
630  {
631  dbval_p = qdata_get_dbval_from_constant_regu_variable (thread_p, &reg_var_p->value, val_desc_p);
632 
633  if (dbval_p != NULL)
634  {
636  {
637  /* this may be shared with another regu variable that was already evaluated */
638  pr_clear_value (dbval_p);
639 
641  != NO_ERROR)
642  {
643  return ER_FAILED;
644  }
645  }
646  }
647 
648  reg_var_p = reg_var_p->next;
649  }
650 
651  return NO_ERROR;
652 }
653 
654 /*
655  * ARITHMETIC EXPRESSION EVALUATION ROUTINES
656  */
657 
658 static int
659 qdata_add_short (short s, DB_VALUE * dbval_p, DB_VALUE * result_p)
660 {
661  short result, tmp;
662 
663  tmp = db_get_short (dbval_p);
664  result = s + tmp;
665 
666  if (OR_CHECK_ADD_OVERFLOW (s, tmp, result))
667  {
670  }
671 
672  db_make_short (result_p, result);
673  return NO_ERROR;
674 }
675 
676 static int
677 qdata_add_int (int i1, int i2, DB_VALUE * result_p)
678 {
679  int result;
680 
681  result = i1 + i2;
682 
683  if (OR_CHECK_ADD_OVERFLOW (i1, i2, result))
684  {
687  }
688 
689  db_make_int (result_p, result);
690  return NO_ERROR;
691 }
692 
693 static int
695 {
696  DB_BIGINT result;
697 
698  result = bi1 + bi2;
699 
700  if (OR_CHECK_ADD_OVERFLOW (bi1, bi2, result))
701  {
704  }
705 
706  db_make_bigint (result_p, result);
707  return NO_ERROR;
708 }
709 
710 static int
711 qdata_add_float (float f1, float f2, DB_VALUE * result_p)
712 {
713  float result;
714 
715  result = f1 + f2;
716 
717  if (OR_CHECK_FLOAT_OVERFLOW (result))
718  {
721  }
722 
723  db_make_float (result_p, result);
724  return NO_ERROR;
725 }
726 
727 static int
728 qdata_add_double (double d1, double d2, DB_VALUE * result_p)
729 {
730  double result;
731 
732  result = d1 + d2;
733 
734  if (OR_CHECK_DOUBLE_OVERFLOW (result))
735  {
738  }
739 
740  db_make_double (result_p, result);
741  return NO_ERROR;
742 }
743 
744 static double
746 {
747  DB_VALUE dbval_tmp;
748  DB_DATA_STATUS data_stat;
749 
751  (void) numeric_db_value_coerce_from_num (numeric_val_p, &dbval_tmp, &data_stat);
752 
753  return db_get_double (&dbval_tmp);
754 }
755 
756 static void
758 {
759  DB_DATA_STATUS data_stat;
760 
762  (void) numeric_db_value_coerce_to_num (dbval_p, result_p, &data_stat);
763 }
764 
765 static int
766 qdata_add_numeric (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
767 {
768  DB_VALUE dbval_tmp;
769 
770  qdata_coerce_dbval_to_numeric (dbval_p, &dbval_tmp);
771 
772  if (numeric_db_value_add (&dbval_tmp, numeric_val_p, result_p) != NO_ERROR)
773  {
776  }
777 
778  return NO_ERROR;
779 }
780 
781 static int
782 qdata_add_numeric_to_monetary (DB_VALUE * numeric_val_p, DB_VALUE * monetary_val_p, DB_VALUE * result_p)
783 {
784  double d1, d2, dtmp;
785 
786  d1 = qdata_coerce_numeric_to_double (numeric_val_p);
787  d2 = (db_get_monetary (monetary_val_p))->amount;
788 
789  dtmp = d1 + d2;
790 
791  db_make_monetary (result_p, (db_get_monetary (monetary_val_p))->type, dtmp);
792 
793  return NO_ERROR;
794 }
795 
796 static int
797 qdata_add_monetary (double d1, double d2, DB_CURRENCY type, DB_VALUE * result_p)
798 {
799  double result;
800 
801  result = d1 + d2;
802 
803  if (OR_CHECK_DOUBLE_OVERFLOW (result))
804  {
807  }
808 
809  db_make_monetary (result_p, type, result);
810  return NO_ERROR;
811 }
812 
813 #if defined (ENABLE_UNUSED_FUNCTION)
814 static int
815 qdata_add_int_to_time (DB_VALUE * time_val_p, unsigned int add_time, DB_VALUE * result_p)
816 {
817  unsigned int result, utime;
818  DB_TIME *time;
819  int hour, minute, second;
820 
821  time = db_get_time (time_val_p);
822  utime = (unsigned int) *time % SECONDS_OF_ONE_DAY;
823 
824  result = (utime + add_time) % SECONDS_OF_ONE_DAY;
825 
826  db_time_decode (&result, &hour, &minute, &second);
827 
829  {
830  db_make_time (result_p, hour, minute, second);
831  }
832  else
833  {
834  DB_TYPE type = DB_VALUE_DOMAIN_TYPE (result_p);
835 
836  switch (type)
837  {
838  case DB_TYPE_INTEGER:
839  db_make_int (result_p, (hour * 100 + minute) * 100 + second);
840  break;
841 
842  case DB_TYPE_SHORT:
843  db_make_short (result_p, (hour * 100 + minute) * 100 + second);
844  break;
845 
846  default:
847  db_make_time (result_p, hour, minute, second);
848  break;
849  }
850  }
851 
852  return NO_ERROR;
853 }
854 #endif
855 
856 static int
857 qdata_add_bigint_to_time (DB_VALUE * time_val_p, DB_BIGINT add_time, DB_VALUE * result_p)
858 {
859  DB_TIME utime, result;
860  int hour, minute, second;
861  int error = NO_ERROR;
862 
863  utime = *(db_get_time (time_val_p)) % SECONDS_OF_ONE_DAY;
864  add_time = add_time % SECONDS_OF_ONE_DAY;
865  if (add_time < 0)
866  {
867  return qdata_subtract_time (utime, (DB_TIME) (-add_time), result_p);
868  }
869 
870  result = (utime + add_time) % SECONDS_OF_ONE_DAY;
871  db_time_decode (&result, &hour, &minute, &second);
872 
874  {
875  error = db_make_time (result_p, hour, minute, second);
876  }
877  else
878  {
879  DB_TYPE type = DB_VALUE_DOMAIN_TYPE (result_p);
880 
881  switch (type)
882  {
883  case DB_TYPE_BIGINT:
884  error = db_make_bigint (result_p, (hour * 100 + minute) * 100 + second);
885  break;
886 
887  case DB_TYPE_INTEGER:
888  error = db_make_int (result_p, (hour * 100 + minute) * 100 + second);
889  break;
890 
891  default:
892  error = db_make_time (result_p, hour, minute, second);
893  break;
894  }
895  }
896 
897  return error;
898 }
899 
900 static int
901 qdata_add_short_to_utime_asymmetry (DB_VALUE * utime_val_p, short s, unsigned int *utime, DB_VALUE * result_p,
902  TP_DOMAIN * domain_p)
903 {
904  DB_VALUE tmp;
905 
906  if (s == DB_INT16_MIN) /* check for asymmetry */
907  {
908  if (*utime <= 1)
909  {
912  }
913 
914  (*utime)--;
915  s++;
916  }
917 
918  db_make_short (&tmp, -(s));
919  return (qdata_subtract_dbval (utime_val_p, &tmp, result_p, domain_p));
920 }
921 
922 static int
923 qdata_add_int_to_utime_asymmetry (DB_VALUE * utime_val_p, int i, unsigned int *utime, DB_VALUE * result_p,
924  TP_DOMAIN * domain_p)
925 {
926  DB_VALUE tmp;
927 
928  if (i == DB_INT32_MIN) /* check for asymmetry */
929  {
930  if (*utime <= 1)
931  {
934  }
935 
936  (*utime)--;
937  i++;
938  }
939 
940  db_make_int (&tmp, -i);
941  return (qdata_subtract_dbval (utime_val_p, &tmp, result_p, domain_p));
942 }
943 
944 static int
945 qdata_add_bigint_to_utime_asymmetry (DB_VALUE * utime_val_p, DB_BIGINT bi, unsigned int *utime, DB_VALUE * result_p,
946  TP_DOMAIN * domain_p)
947 {
948  DB_VALUE tmp;
949 
950  if (bi == DB_BIGINT_MIN) /* check for asymmetry */
951  {
952  if (*utime <= 1)
953  {
956  }
957 
958  (*utime)--;
959  bi++;
960  }
961 
962  db_make_bigint (&tmp, -bi);
963  return (qdata_subtract_dbval (utime_val_p, &tmp, result_p, domain_p));
964 }
965 
966 static int
967 qdata_add_short_to_utime (DB_VALUE * utime_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p)
968 {
969  DB_UTIME *utime;
970  DB_UTIME utmp, u1, u2;
971  DB_DATE date;
972  DB_TIME time;
973  DB_TYPE type;
974  DB_BIGINT bigint = 0;
975  int d, m, y, h, mi, sec;
976 
977  utime = db_get_timestamp (utime_val_p);
978 
979  if (s < 0)
980  {
981  return qdata_add_short_to_utime_asymmetry (utime_val_p, s, utime, result_p, domain_p);
982  }
983 
984  u1 = s;
985  u2 = *utime;
986  utmp = u1 + u2;
987 
988  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || INT_MAX < utmp)
989  {
992  }
993 
995  {
996  db_make_timestamp (result_p, utmp);
997  }
998  else
999  {
1000  type = DB_VALUE_DOMAIN_TYPE (result_p);
1001 
1002  switch (type)
1003  {
1004  case DB_TYPE_BIGINT:
1005  (void) db_timestamp_decode_ses (&utmp, &date, &time);
1006  db_date_decode (&date, &m, &d, &y);
1007  db_time_decode (&time, &h, &mi, &sec);
1008  bigint = (y * 100 + m) * 100 + d;
1009  bigint = ((bigint * 100 + h) * 100 + mi) * 100 + sec;
1010  db_make_bigint (result_p, bigint);
1011  break;
1012 
1013  default:
1014  db_make_timestamp (result_p, utmp);
1015  break;
1016  }
1017  }
1018 
1019  return NO_ERROR;
1020 }
1021 
1022 static int
1023 qdata_add_int_to_utime (DB_VALUE * utime_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1024 {
1025  DB_UTIME *utime;
1026  DB_UTIME utmp, u1, u2;
1027  DB_DATE date;
1028  DB_TIME time;
1029  DB_TYPE type;
1030  DB_BIGINT bigint;
1031  int d, m, y, h, mi, s;
1032 
1033  utime = db_get_timestamp (utime_val_p);
1034 
1035  if (i < 0)
1036  {
1037  return qdata_add_int_to_utime_asymmetry (utime_val_p, i, utime, result_p, domain_p);
1038  }
1039 
1040  u1 = i;
1041  u2 = *utime;
1042  utmp = u1 + u2;
1043 
1044  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || INT_MAX < utmp)
1045  {
1048  }
1049 
1051  {
1052  db_make_timestamp (result_p, utmp);
1053  }
1054  else
1055  {
1056  type = DB_VALUE_DOMAIN_TYPE (result_p);
1057 
1058  switch (type)
1059  {
1060  case DB_TYPE_BIGINT:
1061  (void) db_timestamp_decode_ses (&utmp, &date, &time);
1062  db_date_decode (&date, &m, &d, &y);
1063  db_time_decode (&time, &h, &mi, &s);
1064  bigint = (y * 100 + m) * 100 + d;
1065  bigint = ((bigint * 100 + h) * 100 + mi) * 100 + s;
1066  db_make_bigint (result_p, bigint);
1067  break;
1068 
1069  default:
1070  db_make_timestamp (result_p, utmp);
1071  break;
1072  }
1073  }
1074 
1075  return NO_ERROR;
1076 }
1077 
1078 static int
1079 qdata_add_bigint_to_utime (DB_VALUE * utime_val_p, DB_BIGINT bi, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1080 {
1081  DB_UTIME *utime;
1082  DB_BIGINT utmp, u1, u2;
1083  DB_DATE date;
1084  DB_TIME time;
1085  DB_TYPE type;
1086  DB_BIGINT bigint;
1087  int d, m, y, h, mi, s;
1088 
1089  utime = db_get_timestamp (utime_val_p);
1090 
1091  if (bi < 0)
1092  {
1093  return qdata_add_bigint_to_utime_asymmetry (utime_val_p, bi, utime, result_p, domain_p);
1094  }
1095 
1096  u1 = bi;
1097  u2 = *utime;
1098  utmp = u1 + u2;
1099 
1100  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || INT_MAX < utmp)
1101  {
1104  }
1106  {
1107  db_make_timestamp (result_p, (unsigned int) utmp); /* truncate to 4bytes time_t */
1108  }
1109  else
1110  {
1111  type = DB_VALUE_DOMAIN_TYPE (result_p);
1112 
1113  switch (type)
1114  {
1115  case DB_TYPE_BIGINT:
1116  {
1117  DB_TIMESTAMP timestamp = (DB_TIMESTAMP) utmp;
1118  (void) db_timestamp_decode_ses (&timestamp, &date, &time);
1119  db_date_decode (&date, &m, &d, &y);
1120  db_time_decode (&time, &h, &mi, &s);
1121  bigint = (y * 100 + m) * 100 + d;
1122  bigint = ((bigint * 100 + h) * 100 + mi) * 100 + s;
1123  db_make_bigint (result_p, bigint);
1124  }
1125  break;
1126 
1127  default:
1128  db_make_timestamp (result_p, (unsigned int) utmp);
1129  break;
1130  }
1131  }
1132 
1133  return NO_ERROR;
1134 }
1135 
1136 static int
1137 qdata_add_short_to_timestamptz (DB_VALUE * ts_tz_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1138 {
1139  int err = NO_ERROR;
1140  DB_TIMESTAMPTZ *ts_tz_p;
1141  DB_TIMESTAMPTZ ts_tz_res, ts_tz_fixed;
1142  DB_UTIME utime;
1143  DB_UTIME utmp, u1, u2;
1144  DB_DATE date;
1145  DB_TIME time;
1146  DB_TYPE type;
1147  DB_BIGINT bigint = 0;
1148  int d, m, y, h, mi, sec;
1149  DB_VALUE tmp_utime_val, tmp_utime_val_res;
1150 
1151  ts_tz_p = db_get_timestamptz (ts_tz_val_p);
1152  utime = ts_tz_p->timestamp;
1153 
1154  if (s < 0)
1155  {
1156  db_make_timestamp (&tmp_utime_val, utime);
1157  err =
1158  qdata_add_short_to_utime_asymmetry (&tmp_utime_val, s, &utime, &tmp_utime_val_res,
1160  if (err != NO_ERROR)
1161  {
1162  goto exit;
1163  }
1164 
1165  assert (DB_VALUE_TYPE (&tmp_utime_val_res) == DB_TYPE_TIMESTAMP);
1166  utmp = *db_get_timestamp (&tmp_utime_val_res);
1167 
1168  goto return_timestamp_tz;
1169  }
1170 
1171  u1 = s;
1172  u2 = utime;
1173  utmp = u1 + u2;
1174 
1175  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || INT_MAX < utmp)
1176  {
1179  goto exit;
1180  }
1181 
1183  {
1184  goto return_timestamp_tz;
1185  }
1186  else
1187  {
1188  type = DB_VALUE_DOMAIN_TYPE (result_p);
1189 
1190  switch (type)
1191  {
1192  case DB_TYPE_BIGINT:
1193  ts_tz_res.timestamp = utmp;
1194  ts_tz_res.tz_id = ts_tz_p->tz_id;
1195  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_fixed);
1196  if (err != NO_ERROR)
1197  {
1198  goto exit;
1199  }
1200  err = db_timestamp_decode_w_tz_id (&ts_tz_fixed.timestamp, &ts_tz_fixed.tz_id, &date, &time);
1201  if (err != NO_ERROR)
1202  {
1203  goto exit;
1204  }
1205  db_date_decode (&date, &m, &d, &y);
1206  db_time_decode (&time, &h, &mi, &sec);
1207  bigint = (y * 100 + m) * 100 + d;
1208  bigint = ((bigint * 100 + h) * 100 + mi) * 100 + sec;
1209  db_make_bigint (result_p, bigint);
1210  break;
1211 
1212  default:
1213  break;
1214  }
1215  }
1216 
1217 return_timestamp_tz:
1218  ts_tz_res.timestamp = utmp;
1219  ts_tz_res.tz_id = ts_tz_p->tz_id;
1220 
1221  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_fixed);
1222  if (err != NO_ERROR)
1223  {
1224  return err;
1225  }
1226  db_make_timestamptz (result_p, &ts_tz_fixed);
1227 
1228 exit:
1229  return err;
1230 }
1231 
1232 static int
1233 qdata_add_int_to_timestamptz (DB_VALUE * ts_tz_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1234 {
1235  int err = NO_ERROR;
1236  DB_TIMESTAMPTZ *ts_tz_p;
1237  DB_TIMESTAMPTZ ts_tz_res, ts_tz_fixed;
1238  DB_UTIME utime;
1239  DB_UTIME utmp, u1, u2;
1240  DB_DATE date;
1241  DB_TIME time;
1242  DB_TYPE type;
1243  DB_BIGINT bigint = 0;
1244  int d, m, y, h, mi, sec;
1245  DB_VALUE tmp_utime_val, tmp_utime_val_res;
1246 
1247  ts_tz_p = db_get_timestamptz (ts_tz_val_p);
1248  utime = ts_tz_p->timestamp;
1249 
1250  if (i < 0)
1251  {
1252  db_make_timestamp (&tmp_utime_val, utime);
1253  err =
1254  qdata_add_int_to_utime_asymmetry (&tmp_utime_val, i, &utime, &tmp_utime_val_res,
1256  if (err != NO_ERROR)
1257  {
1258  goto exit;
1259  }
1260 
1261  assert (DB_VALUE_TYPE (&tmp_utime_val_res) == DB_TYPE_TIMESTAMP);
1262  utmp = *db_get_timestamp (&tmp_utime_val_res);
1263 
1264  goto return_timestamp_tz;
1265  }
1266 
1267  u1 = i;
1268  u2 = utime;
1269  utmp = u1 + u2;
1270 
1271  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || INT_MAX < utmp)
1272  {
1275  goto exit;
1276  }
1277 
1279  {
1280  goto return_timestamp_tz;
1281  }
1282  else
1283  {
1284  type = DB_VALUE_DOMAIN_TYPE (result_p);
1285 
1286  switch (type)
1287  {
1288  case DB_TYPE_BIGINT:
1289  ts_tz_res.timestamp = utmp;
1290  ts_tz_res.tz_id = ts_tz_p->tz_id;
1291  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_fixed);
1292  if (err != NO_ERROR)
1293  {
1294  goto exit;
1295  }
1296  err = db_timestamp_decode_w_tz_id (&ts_tz_fixed.timestamp, &ts_tz_fixed.tz_id, &date, &time);
1297  if (err != NO_ERROR)
1298  {
1299  goto exit;
1300  }
1301  db_date_decode (&date, &m, &d, &y);
1302  db_time_decode (&time, &h, &mi, &sec);
1303  bigint = (y * 100 + m) * 100 + d;
1304  bigint = ((bigint * 100 + h) * 100 + mi) * 100 + sec;
1305  db_make_bigint (result_p, bigint);
1306  break;
1307 
1308  default:
1309  break;
1310  }
1311  }
1312 
1313 return_timestamp_tz:
1314  ts_tz_res.timestamp = utmp;
1315  ts_tz_res.tz_id = ts_tz_p->tz_id;
1316 
1317  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_fixed);
1318  if (err != NO_ERROR)
1319  {
1320  return err;
1321  }
1322  db_make_timestamptz (result_p, &ts_tz_fixed);
1323 
1324 exit:
1325  return err;
1326 }
1327 
1328 static int
1329 qdata_add_bigint_to_timestamptz (DB_VALUE * ts_tz_val_p, DB_BIGINT bi, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1330 {
1331  int err = NO_ERROR;
1332  DB_TIMESTAMPTZ *ts_tz_p;
1333  DB_TIMESTAMPTZ ts_tz_res, ts_tz_fixed;
1334  DB_UTIME utime;
1335  DB_DATE date;
1336  DB_TIME time;
1337  DB_TYPE type;
1338  DB_BIGINT u1, u2, utmp, bigint = 0;
1339  int d, m, y, h, mi, sec;
1340  DB_VALUE tmp_utime_val, tmp_utime_val_res;
1341 
1342  ts_tz_p = db_get_timestamptz (ts_tz_val_p);
1343  utime = ts_tz_p->timestamp;
1344 
1345  if (bi < 0)
1346  {
1347  db_make_timestamp (&tmp_utime_val, utime);
1348  err =
1349  qdata_add_bigint_to_utime_asymmetry (&tmp_utime_val, bi, &utime, &tmp_utime_val_res,
1351  if (err != NO_ERROR)
1352  {
1353  goto exit;
1354  }
1355 
1356  assert (DB_VALUE_TYPE (&tmp_utime_val_res) == DB_TYPE_TIMESTAMP);
1357  utmp = *db_get_timestamp (&tmp_utime_val_res);
1358 
1359  goto return_timestamp_tz;
1360  }
1361 
1362  u1 = bi;
1363  u2 = utime;
1364  utmp = u1 + u2;
1365 
1366  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || INT_MAX < utmp)
1367  {
1370  goto exit;
1371  }
1372 
1374  {
1375  goto return_timestamp_tz;
1376  }
1377  else
1378  {
1379  type = DB_VALUE_DOMAIN_TYPE (result_p);
1380 
1381  switch (type)
1382  {
1383  case DB_TYPE_BIGINT:
1384  utime = (DB_UTIME) utmp;
1385  ts_tz_res.timestamp = utime;
1386  ts_tz_res.tz_id = ts_tz_p->tz_id;
1387  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_fixed);
1388  if (err != NO_ERROR)
1389  {
1390  goto exit;
1391  }
1392  err = db_timestamp_decode_w_tz_id (&ts_tz_fixed.timestamp, &ts_tz_fixed.tz_id, &date, &time);
1393  if (err != NO_ERROR)
1394  {
1395  goto exit;
1396  }
1397  db_date_decode (&date, &m, &d, &y);
1398  db_time_decode (&time, &h, &mi, &sec);
1399  bigint = (y * 100 + m) * 100 + d;
1400  bigint = ((bigint * 100 + h) * 100 + mi) * 100 + sec;
1401  db_make_bigint (result_p, bigint);
1402  break;
1403 
1404  default:
1405  break;
1406  }
1407  }
1408 
1409 return_timestamp_tz:
1410  utime = (DB_UTIME) utmp;
1411  ts_tz_res.timestamp = utime;
1412  ts_tz_res.tz_id = ts_tz_p->tz_id;
1413 
1414  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_fixed);
1415  if (err != NO_ERROR)
1416  {
1417  return err;
1418  }
1419  db_make_timestamptz (result_p, &ts_tz_fixed);
1420 
1421 exit:
1422  return err;
1423 }
1424 
1425 static int
1426 qdata_add_short_to_datetime (DB_VALUE * datetime_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1427 {
1428  DB_DATETIME *datetime;
1429  DB_DATETIME tmp;
1430  int error = NO_ERROR;
1431 
1432  datetime = db_get_datetime (datetime_val_p);
1433 
1434  error = db_add_int_to_datetime (datetime, s, &tmp);
1435  if (error == NO_ERROR)
1436  {
1437  db_make_datetime (result_p, &tmp);
1438  }
1439  return error;
1440 }
1441 
1442 static int
1443 qdata_add_int_to_datetime (DB_VALUE * datetime_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1444 {
1445  DB_DATETIME *datetime;
1446  DB_DATETIME tmp;
1447  int error = NO_ERROR;
1448 
1449  datetime = db_get_datetime (datetime_val_p);
1450 
1451  error = db_add_int_to_datetime (datetime, i, &tmp);
1452  if (error == NO_ERROR)
1453  {
1454  db_make_datetime (result_p, &tmp);
1455  }
1456  return error;
1457 }
1458 
1459 static int
1460 qdata_add_bigint_to_datetime (DB_VALUE * datetime_val_p, DB_BIGINT bi, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1461 {
1462  DB_DATETIME *datetime;
1463  DB_DATETIME tmp;
1464  int error = NO_ERROR;
1465 
1466  datetime = db_get_datetime (datetime_val_p);
1467 
1468  error = db_add_int_to_datetime (datetime, bi, &tmp);
1469  if (error == NO_ERROR)
1470  {
1471  db_make_datetime (result_p, &tmp);
1472  }
1473  return error;
1474 }
1475 
1476 static int
1477 qdata_add_short_to_date (DB_VALUE * date_val_p, short s, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1478 {
1479  DB_DATE *date;
1480  unsigned int utmp, u1, u2;
1481  int day, month, year;
1482 
1483  date = db_get_date (date_val_p);
1484  if (s < 0)
1485  {
1486  return qdata_add_short_to_utime_asymmetry (date_val_p, s, date, result_p, domain_p);
1487  }
1488 
1489  u1 = (unsigned int) s;
1490  u2 = (unsigned int) *date;
1491  utmp = u1 + u2;
1492 
1493  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || utmp > DB_DATE_MAX)
1494  {
1497  }
1498 
1499  db_date_decode (&utmp, &month, &day, &year);
1500 
1502  {
1503  db_make_date (result_p, month, day, year);
1504  }
1505  else
1506  {
1507  DB_TYPE type = DB_VALUE_DOMAIN_TYPE (result_p);
1508 
1509  switch (type)
1510  {
1511  case DB_TYPE_SHORT:
1512  db_make_short (result_p, (year * 100 + month) * 100 + day);
1513  break;
1514 
1515  default:
1516  db_make_date (result_p, month, day, year);
1517  break;
1518  }
1519  }
1520 
1521  return NO_ERROR;
1522 }
1523 
1524 static int
1525 qdata_add_int_to_date (DB_VALUE * date_val_p, int i, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1526 {
1527  DB_DATE *date;
1528  unsigned int utmp, u1, u2;
1529  int day, month, year;
1530 
1531  date = db_get_date (date_val_p);
1532 
1533  if (i < 0)
1534  {
1535  return qdata_add_int_to_utime_asymmetry (date_val_p, i, date, result_p, domain_p);
1536  }
1537 
1538  u1 = (unsigned int) i;
1539  u2 = (unsigned int) *date;
1540  utmp = u1 + u2;
1541 
1542  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || utmp > DB_DATE_MAX)
1543  {
1546  }
1547 
1548  db_date_decode (&utmp, &month, &day, &year);
1550  {
1551  db_make_date (result_p, month, day, year);
1552  }
1553  else
1554  {
1555  DB_TYPE type = DB_VALUE_DOMAIN_TYPE (result_p);
1556 
1557  switch (type)
1558  {
1559  case DB_TYPE_INTEGER:
1560  db_make_int (result_p, (year * 100 + month) * 100 + day);
1561  break;
1562 
1563  default:
1564  db_make_date (result_p, month, day, year);
1565  break;
1566  }
1567  }
1568 
1569  return NO_ERROR;
1570 }
1571 
1572 static int
1573 qdata_add_bigint_to_date (DB_VALUE * date_val_p, DB_BIGINT bi, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1574 {
1575  DB_DATE *date;
1576  DB_BIGINT utmp, u1, u2;
1577  DB_DATE tmp_date;
1578  int day, month, year;
1579 
1580  date = db_get_date (date_val_p);
1581 
1582  if (bi < 0)
1583  {
1584  return qdata_add_bigint_to_utime_asymmetry (date_val_p, bi, date, result_p, domain_p);
1585  }
1586 
1587  u1 = bi;
1588  u2 = *date;
1589  utmp = u1 + u2;
1590 
1591  if (OR_CHECK_UNS_ADD_OVERFLOW (u1, u2, utmp) || utmp > DB_DATE_MAX)
1592  {
1595  }
1596 
1597  tmp_date = (DB_DATE) utmp;
1598  db_date_decode (&tmp_date, &month, &day, &year);
1600  {
1601  db_make_date (result_p, month, day, year);
1602  }
1603  else
1604  {
1605  DB_TYPE type = DB_VALUE_DOMAIN_TYPE (result_p);
1606 
1607  switch (type)
1608  {
1609  case DB_TYPE_BIGINT:
1610  db_make_bigint (result_p, (year * 100 + month) * 100 + day);
1611  break;
1612 
1613  default:
1614  db_make_date (result_p, month, day, year);
1615  break;
1616  }
1617  }
1618 
1619  return NO_ERROR;
1620 }
1621 
1622 static int
1623 qdata_add_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1624 {
1625  int err = NO_ERROR;
1626  DB_VALUE tmp_val;
1627  short s;
1628  DB_TYPE type;
1629 
1630  s = db_get_short (short_val_p);
1631  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
1632 
1633  switch (type)
1634  {
1635  case DB_TYPE_SHORT:
1636  return qdata_add_short (s, dbval_p, result_p);
1637 
1638  case DB_TYPE_INTEGER:
1639  return qdata_add_int (s, db_get_int (dbval_p), result_p);
1640 
1641  case DB_TYPE_BIGINT:
1642  return qdata_add_bigint (s, db_get_bigint (dbval_p), result_p);
1643 
1644  case DB_TYPE_FLOAT:
1645  return qdata_add_float (s, db_get_float (dbval_p), result_p);
1646 
1647  case DB_TYPE_DOUBLE:
1648  return qdata_add_double (s, db_get_double (dbval_p), result_p);
1649 
1650  case DB_TYPE_NUMERIC:
1651  return qdata_add_numeric (dbval_p, short_val_p, result_p);
1652 
1653  case DB_TYPE_MONETARY:
1654  return qdata_add_monetary (s, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p);
1655 
1656  case DB_TYPE_TIME:
1657  return qdata_add_bigint_to_time (dbval_p, (DB_BIGINT) s, result_p);
1658 
1659  case DB_TYPE_TIMESTAMP:
1660  return qdata_add_short_to_utime (dbval_p, s, result_p, domain_p);
1661 
1662  case DB_TYPE_TIMESTAMPLTZ:
1663  {
1664  DB_TIMESTAMPTZ ts_tz;
1665  ts_tz.timestamp = *db_get_timestamp (dbval_p);
1666 
1667  err = tz_create_session_tzid_for_timestamp (&ts_tz.timestamp, &ts_tz.tz_id);
1668  if (err != NO_ERROR)
1669  {
1670  break;
1671  }
1672  db_make_timestamptz (&tmp_val, &ts_tz);
1673 
1674  err = qdata_add_short_to_timestamptz (&tmp_val, (DB_BIGINT) s, result_p, domain_p);
1675  if (err != NO_ERROR)
1676  {
1677  break;
1678  }
1679  if (DB_VALUE_TYPE (result_p) == DB_TYPE_TIMESTAMPTZ)
1680  {
1681  ts_tz = *db_get_timestamptz (result_p);
1682  db_make_timestampltz (result_p, ts_tz.timestamp);
1683  }
1684  break;
1685  }
1686 
1687  case DB_TYPE_TIMESTAMPTZ:
1688  return qdata_add_short_to_timestamptz (dbval_p, s, result_p, domain_p);
1689 
1690  case DB_TYPE_DATETIME:
1691  case DB_TYPE_DATETIMELTZ:
1692  err = qdata_add_short_to_datetime (dbval_p, s, &tmp_val, domain_p);
1693  if (err == NO_ERROR && type == DB_TYPE_DATETIMELTZ)
1694  {
1695  db_make_datetimeltz (result_p, db_get_datetime (&tmp_val));
1696  }
1697  return err;
1698 
1699  case DB_TYPE_DATETIMETZ:
1700  db_make_short (&tmp_val, s);
1701  return qdata_add_datetimetz_to_dbval (dbval_p, &tmp_val, result_p);
1702 
1703  case DB_TYPE_DATE:
1704  return qdata_add_short_to_date (dbval_p, s, result_p, domain_p);
1705 
1706  default:
1707  break;
1708  }
1709 
1710  return err;
1711 }
1712 
1713 static int
1714 qdata_add_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1715 {
1716  int i;
1717  int err = NO_ERROR;
1718  DB_TYPE type;
1719  DB_VALUE tmp_val;
1720 
1721  i = db_get_int (int_val_p);
1722  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
1723 
1724  switch (type)
1725  {
1726  case DB_TYPE_SHORT:
1727  return qdata_add_int (i, db_get_short (dbval_p), result_p);
1728 
1729  case DB_TYPE_INTEGER:
1730  return qdata_add_int (i, db_get_int (dbval_p), result_p);
1731 
1732  case DB_TYPE_BIGINT:
1733  return qdata_add_bigint (i, db_get_bigint (dbval_p), result_p);
1734 
1735  case DB_TYPE_FLOAT:
1736  return qdata_add_float ((float) i, db_get_float (dbval_p), result_p);
1737 
1738  case DB_TYPE_DOUBLE:
1739  return qdata_add_double (i, db_get_double (dbval_p), result_p);
1740 
1741  case DB_TYPE_NUMERIC:
1742  return qdata_add_numeric (dbval_p, int_val_p, result_p);
1743  break;
1744 
1745  case DB_TYPE_MONETARY:
1746  return qdata_add_monetary (i, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p);
1747 
1748  case DB_TYPE_TIME:
1749  return qdata_add_bigint_to_time (dbval_p, (DB_BIGINT) i, result_p);
1750 
1751  case DB_TYPE_TIMESTAMP:
1752  return qdata_add_int_to_utime (dbval_p, i, result_p, domain_p);
1753 
1754  case DB_TYPE_TIMESTAMPLTZ:
1755  {
1756  DB_TIMESTAMPTZ ts_tz;
1757  ts_tz.timestamp = *db_get_timestamp (dbval_p);
1758 
1759  err = tz_create_session_tzid_for_timestamp (&ts_tz.timestamp, &ts_tz.tz_id);
1760  if (err != NO_ERROR)
1761  {
1762  break;
1763  }
1764  db_make_timestamptz (&tmp_val, &ts_tz);
1765 
1766  err = qdata_add_int_to_timestamptz (&tmp_val, (DB_BIGINT) i, result_p, domain_p);
1767  if (err != NO_ERROR)
1768  {
1769  break;
1770  }
1771  if (DB_VALUE_TYPE (result_p) == DB_TYPE_TIMESTAMPTZ)
1772  {
1773  ts_tz = *db_get_timestamptz (result_p);
1774  db_make_timestampltz (result_p, ts_tz.timestamp);
1775  }
1776  break;
1777  }
1778 
1779  case DB_TYPE_TIMESTAMPTZ:
1780  return qdata_add_int_to_timestamptz (dbval_p, i, result_p, domain_p);
1781 
1782  case DB_TYPE_DATETIME:
1783  case DB_TYPE_DATETIMELTZ:
1784  err = qdata_add_int_to_datetime (dbval_p, i, &tmp_val, domain_p);
1785  if (err == NO_ERROR && type == DB_TYPE_DATETIMELTZ)
1786  {
1787  db_make_datetimeltz (result_p, db_get_datetime (&tmp_val));
1788  }
1789  return err;
1790 
1791  case DB_TYPE_DATETIMETZ:
1792  db_make_int (&tmp_val, i);
1793  return qdata_add_datetimetz_to_dbval (dbval_p, &tmp_val, result_p);
1794 
1795  case DB_TYPE_DATE:
1796  return qdata_add_int_to_date (dbval_p, i, result_p, domain_p);
1797 
1798  default:
1799  break;
1800  }
1801 
1802  return err;
1803 }
1804 
1805 static int
1806 qdata_add_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
1807 {
1808  int err = NO_ERROR;
1809  DB_BIGINT bi;
1810  DB_TYPE type;
1811  DB_VALUE tmp_val;
1812 
1813  bi = db_get_bigint (bigint_val_p);
1814  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
1815 
1816  switch (type)
1817  {
1818  case DB_TYPE_SHORT:
1819  return qdata_add_bigint (bi, db_get_short (dbval_p), result_p);
1820 
1821  case DB_TYPE_INTEGER:
1822  return qdata_add_bigint (bi, db_get_int (dbval_p), result_p);
1823 
1824  case DB_TYPE_BIGINT:
1825  return qdata_add_bigint (bi, db_get_bigint (dbval_p), result_p);
1826 
1827  case DB_TYPE_FLOAT:
1828  return qdata_add_float ((float) bi, db_get_float (dbval_p), result_p);
1829 
1830  case DB_TYPE_DOUBLE:
1831  return qdata_add_double ((double) bi, db_get_double (dbval_p), result_p);
1832 
1833  case DB_TYPE_NUMERIC:
1834  return qdata_add_numeric (dbval_p, bigint_val_p, result_p);
1835  break;
1836 
1837  case DB_TYPE_MONETARY:
1838  return qdata_add_monetary ((double) bi, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type,
1839  result_p);
1840 
1841  case DB_TYPE_TIME:
1842  return qdata_add_bigint_to_time (dbval_p, bi, result_p);
1843 
1844  case DB_TYPE_TIMESTAMP:
1845  return qdata_add_bigint_to_utime (dbval_p, bi, result_p, domain_p);
1846 
1847  case DB_TYPE_TIMESTAMPLTZ:
1848  {
1849  DB_TIMESTAMPTZ ts_tz;
1850  ts_tz.timestamp = *db_get_timestamp (dbval_p);
1851 
1852  err = tz_create_session_tzid_for_timestamp (&ts_tz.timestamp, &ts_tz.tz_id);
1853  if (err != NO_ERROR)
1854  {
1855  break;
1856  }
1857  db_make_timestamptz (&tmp_val, &ts_tz);
1858 
1859  err = qdata_add_bigint_to_timestamptz (&tmp_val, bi, result_p, domain_p);
1860  if (err != NO_ERROR)
1861  {
1862  break;
1863  }
1864  if (DB_VALUE_TYPE (result_p) == DB_TYPE_TIMESTAMPTZ)
1865  {
1866  ts_tz = *db_get_timestamptz (result_p);
1867  db_make_timestampltz (result_p, ts_tz.timestamp);
1868  }
1869  break;
1870  }
1871 
1872  case DB_TYPE_TIMESTAMPTZ:
1873  return qdata_add_bigint_to_timestamptz (dbval_p, bi, result_p, domain_p);
1874 
1875  case DB_TYPE_DATE:
1876  return qdata_add_bigint_to_date (dbval_p, bi, result_p, domain_p);
1877 
1878  case DB_TYPE_DATETIME:
1879  return qdata_add_bigint_to_datetime (dbval_p, bi, result_p, domain_p);
1880 
1881  case DB_TYPE_DATETIMELTZ:
1882  err = qdata_add_bigint_to_datetime (dbval_p, bi, &tmp_val, domain_p);
1883  if (err == NO_ERROR && type == DB_TYPE_DATETIMELTZ)
1884  {
1885  db_make_datetimeltz (result_p, db_get_datetime (&tmp_val));
1886  }
1887  return err;
1888 
1889  case DB_TYPE_DATETIMETZ:
1890  db_make_bigint (&tmp_val, bi);
1891  return qdata_add_datetimetz_to_dbval (dbval_p, &tmp_val, result_p);
1892 
1893  default:
1894  break;
1895  }
1896 
1897  return err;
1898 }
1899 
1900 static int
1901 qdata_add_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
1902 {
1903  float f1;
1904  DB_TYPE type;
1905 
1906  f1 = db_get_float (float_val_p);
1907  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
1908 
1909  switch (type)
1910  {
1911  case DB_TYPE_SHORT:
1912  return qdata_add_float (f1, (float) db_get_short (dbval_p), result_p);
1913 
1914  case DB_TYPE_INTEGER:
1915  return qdata_add_float (f1, (float) db_get_int (dbval_p), result_p);
1916 
1917  case DB_TYPE_BIGINT:
1918  return qdata_add_double (f1, (double) db_get_bigint (dbval_p), result_p);
1919 
1920  case DB_TYPE_FLOAT:
1921  return qdata_add_float (f1, db_get_float (dbval_p), result_p);
1922 
1923  case DB_TYPE_DOUBLE:
1924  return qdata_add_double (f1, db_get_double (dbval_p), result_p);
1925 
1926  case DB_TYPE_NUMERIC:
1927  return qdata_add_double (f1, qdata_coerce_numeric_to_double (dbval_p), result_p);
1928 
1929  case DB_TYPE_MONETARY:
1930  return qdata_add_monetary (f1, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p);
1931 
1932  default:
1933  break;
1934  }
1935 
1936  return NO_ERROR;
1937 }
1938 
1939 static int
1940 qdata_add_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
1941 {
1942  double d1;
1943  DB_TYPE type;
1944 
1945  d1 = db_get_double (double_val_p);
1946  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
1947 
1948  switch (type)
1949  {
1950  case DB_TYPE_SHORT:
1951  return qdata_add_double (d1, db_get_short (dbval_p), result_p);
1952 
1953  case DB_TYPE_INTEGER:
1954  return qdata_add_double (d1, db_get_int (dbval_p), result_p);
1955 
1956  case DB_TYPE_BIGINT:
1957  return qdata_add_double (d1, (double) db_get_bigint (dbval_p), result_p);
1958 
1959  case DB_TYPE_FLOAT:
1960  return qdata_add_double (d1, db_get_float (dbval_p), result_p);
1961 
1962  case DB_TYPE_DOUBLE:
1963  return qdata_add_double (d1, db_get_double (dbval_p), result_p);
1964 
1965  case DB_TYPE_NUMERIC:
1966  return qdata_add_double (d1, qdata_coerce_numeric_to_double (dbval_p), result_p);
1967 
1968  case DB_TYPE_MONETARY:
1969  return qdata_add_monetary (d1, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p);
1970 
1971  default:
1972  break;
1973  }
1974 
1975  return NO_ERROR;
1976 }
1977 
1978 static int
1979 qdata_add_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
1980 {
1981  DB_TYPE type;
1982 
1983  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
1984 
1985  switch (type)
1986  {
1987  case DB_TYPE_SHORT:
1988  case DB_TYPE_INTEGER:
1989  case DB_TYPE_BIGINT:
1990  return qdata_add_numeric (numeric_val_p, dbval_p, result_p);
1991 
1992  case DB_TYPE_NUMERIC:
1993  if (numeric_db_value_add (numeric_val_p, dbval_p, result_p) != NO_ERROR)
1994  {
1997  }
1998  break;
1999 
2000  case DB_TYPE_FLOAT:
2001  return qdata_add_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_float (dbval_p), result_p);
2002 
2003  case DB_TYPE_DOUBLE:
2004  return qdata_add_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_double (dbval_p), result_p);
2005 
2006  case DB_TYPE_MONETARY:
2007  return qdata_add_numeric_to_monetary (numeric_val_p, dbval_p, result_p);
2008 
2009  default:
2010  break;
2011  }
2012 
2013  return NO_ERROR;
2014 }
2015 
2016 static int
2017 qdata_add_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
2018 {
2019  DB_TYPE type;
2020  double d1;
2021  DB_CURRENCY currency;
2022 
2023  d1 = (db_get_monetary (monetary_val_p))->amount;
2024  currency = (db_get_monetary (monetary_val_p))->type;
2025 
2026  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
2027 
2028  switch (type)
2029  {
2030  case DB_TYPE_SHORT:
2031  return qdata_add_monetary (d1, db_get_short (dbval_p), currency, result_p);
2032 
2033  case DB_TYPE_INTEGER:
2034  return qdata_add_monetary (d1, db_get_int (dbval_p), currency, result_p);
2035 
2036  case DB_TYPE_BIGINT:
2037  return qdata_add_monetary (d1, (double) db_get_bigint (dbval_p), currency, result_p);
2038 
2039  case DB_TYPE_FLOAT:
2040  return qdata_add_monetary (d1, db_get_float (dbval_p), currency, result_p);
2041 
2042  case DB_TYPE_DOUBLE:
2043  return qdata_add_monetary (d1, db_get_double (dbval_p), currency, result_p);
2044 
2045  case DB_TYPE_NUMERIC:
2046  return qdata_add_numeric_to_monetary (dbval_p, monetary_val_p, result_p);
2047 
2048  case DB_TYPE_MONETARY:
2049  /* Note: we probably should return an error if the two monetaries have different monetary types. */
2050  return qdata_add_monetary (d1, (db_get_monetary (dbval_p))->amount, currency, result_p);
2051 
2052  default:
2053  break;
2054  }
2055 
2056  return NO_ERROR;
2057 }
2058 
2059 static int
2060 qdata_add_chars_to_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p)
2061 {
2062  DB_DATA_STATUS data_stat;
2063 
2064  if ((db_string_concatenate (dbval1_p, dbval2_p, result_p, &data_stat) != NO_ERROR) || (data_stat != DATA_STATUS_OK))
2065  {
2066  return ER_FAILED;
2067  }
2068 
2069  return NO_ERROR;
2070 }
2071 
2072 static int
2073 qdata_add_sequence_to_dbval (DB_VALUE * seq_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
2074 {
2075  DB_SET *set_tmp;
2076  DB_SEQ *seq_tmp, *seq_tmp1;
2077  DB_VALUE dbval_tmp;
2078  int i, card, card1;
2079 #if !defined(NDEBUG)
2080  DB_TYPE type1, type2;
2081 #endif
2082 
2083 #if !defined(NDEBUG)
2084  type1 = DB_VALUE_DOMAIN_TYPE (seq_val_p);
2085  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
2086 
2087  assert (TP_IS_SET_TYPE (type1));
2088  assert (TP_IS_SET_TYPE (type2));
2089 #endif
2090 
2091  if (domain_p == NULL)
2092  {
2093  return ER_FAILED;
2094  }
2095 
2096  db_make_null (&dbval_tmp);
2097 
2098  if (TP_DOMAIN_TYPE (domain_p) == DB_TYPE_SEQUENCE)
2099  {
2100  if (tp_value_coerce (seq_val_p, result_p, domain_p) != DOMAIN_COMPATIBLE)
2101  {
2102  return ER_FAILED;
2103  }
2104 
2105  seq_tmp = db_get_set (dbval_p);
2106  card = db_seq_size (seq_tmp);
2107  seq_tmp1 = db_get_set (result_p);
2108  card1 = db_seq_size (seq_tmp1);
2109 
2110  for (i = 0; i < card; i++)
2111  {
2112  if (db_seq_get (seq_tmp, i, &dbval_tmp) != NO_ERROR)
2113  {
2114  return ER_FAILED;
2115  }
2116 
2117  if (db_seq_put (seq_tmp1, card1 + i, &dbval_tmp) != NO_ERROR)
2118  {
2119  pr_clear_value (&dbval_tmp);
2120  return ER_FAILED;
2121  }
2122 
2123  pr_clear_value (&dbval_tmp);
2124  }
2125  }
2126  else
2127  {
2128  /* set or multiset */
2129  if (set_union (db_get_set (seq_val_p), db_get_set (dbval_p), &set_tmp, domain_p) < 0)
2130  {
2131  return ER_FAILED;
2132  }
2133 
2134  pr_clear_value (result_p);
2135  set_make_collection (result_p, set_tmp);
2136  }
2137 
2138  return NO_ERROR;
2139 }
2140 
2141 static int
2142 qdata_add_time_to_dbval (DB_VALUE * time_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
2143 {
2144  DB_TYPE type;
2145 
2146  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
2147 
2148  switch (type)
2149  {
2150  case DB_TYPE_SHORT:
2151  return qdata_add_bigint_to_time (time_val_p, (DB_BIGINT) db_get_short (dbval_p), result_p);
2152 
2153  case DB_TYPE_INTEGER:
2154  return qdata_add_bigint_to_time (time_val_p, (DB_BIGINT) db_get_int (dbval_p), result_p);
2155 
2156  case DB_TYPE_BIGINT:
2157  return qdata_add_bigint_to_time (time_val_p, db_get_bigint (dbval_p), result_p);
2158 
2159  default:
2160  break;
2161  }
2162 
2163  return NO_ERROR;
2164 }
2165 
2166 static int
2167 qdata_add_utime_to_dbval (DB_VALUE * utime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
2168 {
2169  DB_TYPE type;
2170 
2171  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
2172 
2173  switch (type)
2174  {
2175  case DB_TYPE_SHORT:
2176  return qdata_add_short_to_utime (utime_val_p, db_get_short (dbval_p), result_p, domain_p);
2177 
2178  case DB_TYPE_INTEGER:
2179  return qdata_add_int_to_utime (utime_val_p, db_get_int (dbval_p), result_p, domain_p);
2180 
2181  case DB_TYPE_BIGINT:
2182  return qdata_add_bigint_to_utime (utime_val_p, db_get_bigint (dbval_p), result_p, domain_p);
2183 
2184  default:
2185  break;
2186  }
2187 
2188  return NO_ERROR;
2189 }
2190 
2191 static int
2192 qdata_add_timestamptz_to_dbval (DB_VALUE * ts_tz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
2193 {
2194  DB_TYPE type;
2195  TP_DOMAIN *domain_p;
2196 
2197  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
2198 
2200 
2201  switch (type)
2202  {
2203  case DB_TYPE_SHORT:
2204  return qdata_add_short_to_timestamptz (ts_tz_val_p, db_get_short (dbval_p), result_p, domain_p);
2205 
2206  case DB_TYPE_INTEGER:
2207  return qdata_add_int_to_timestamptz (ts_tz_val_p, db_get_int (dbval_p), result_p, domain_p);
2208 
2209  case DB_TYPE_BIGINT:
2210  return qdata_add_bigint_to_timestamptz (ts_tz_val_p, db_get_bigint (dbval_p), result_p, domain_p);
2211 
2212  default:
2213  break;
2214  }
2215 
2216  return NO_ERROR;
2217 }
2218 
2219 static int
2220 qdata_add_datetime_to_dbval (DB_VALUE * datetime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
2221 {
2222  DB_TYPE type;
2223 
2224  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
2225 
2226  switch (type)
2227  {
2228  case DB_TYPE_SHORT:
2229  return qdata_add_short_to_datetime (datetime_val_p, db_get_short (dbval_p), result_p, domain_p);
2230 
2231  case DB_TYPE_INTEGER:
2232  return qdata_add_int_to_datetime (datetime_val_p, db_get_int (dbval_p), result_p, domain_p);
2233 
2234  case DB_TYPE_BIGINT:
2235  return qdata_add_bigint_to_datetime (datetime_val_p, db_get_bigint (dbval_p), result_p, domain_p);
2236 
2237  default:
2238  break;
2239  }
2240 
2241  return NO_ERROR;
2242 }
2243 
2244 static int
2245 qdata_add_datetimetz_to_dbval (DB_VALUE * datetimetz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
2246 {
2247  int error = NO_ERROR;
2248  DB_VALUE dt_val, dt_val_res;
2249  DB_DATETIMETZ *dt_tz_p = db_get_datetimetz (datetimetz_val_p);
2250  DB_DATETIMETZ dt_tz_res, dt_tz_fixed;
2251 
2252  db_make_datetime (&dt_val, &dt_tz_p->datetime);
2253  error = qdata_add_datetime_to_dbval (&dt_val, dbval_p, &dt_val_res, tp_domain_resolve_default (DB_TYPE_DATETIME));
2254  if (error != NO_ERROR)
2255  {
2256  return error;
2257  }
2258 
2259  dt_tz_res.datetime = *db_get_datetime (&dt_val_res);
2260  dt_tz_res.tz_id = dt_tz_p->tz_id;
2261 
2262  error = tz_datetimetz_fix_zone (&dt_tz_res, &dt_tz_fixed);
2263  if (error != NO_ERROR)
2264  {
2265  return error;
2266  }
2267 
2268  db_make_datetimetz (result_p, &dt_tz_fixed);
2269  return NO_ERROR;
2270 }
2271 
2272 static int
2273 qdata_add_date_to_dbval (DB_VALUE * date_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
2274 {
2275  DB_TYPE type;
2276 
2277  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
2278 
2279  switch (type)
2280  {
2281  case DB_TYPE_SHORT:
2282  return qdata_add_short_to_date (date_val_p, db_get_short (dbval_p), result_p, domain_p);
2283 
2284  case DB_TYPE_INTEGER:
2285  return qdata_add_int_to_date (date_val_p, db_get_int (dbval_p), result_p, domain_p);
2286 
2287  case DB_TYPE_BIGINT:
2288  return qdata_add_bigint_to_date (date_val_p, db_get_bigint (dbval_p), result_p, domain_p);
2289 
2290  default:
2292  {
2295  }
2296  break;
2297  }
2298 
2299  return NO_ERROR;
2300 }
2301 
2302 static int
2304 {
2305  int error = NO_ERROR;
2306  TP_DOMAIN_STATUS dom_status;
2307 
2308  if (domain_p != NULL)
2309  {
2310  dom_status = tp_value_coerce (result_p, result_p, domain_p);
2311  if (dom_status != DOMAIN_COMPATIBLE)
2312  {
2313  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, result_p, domain_p);
2314  assert_release (error != NO_ERROR);
2315  }
2316  }
2317 
2318  return error;
2319 }
2320 
2321 static int
2322 qdata_cast_to_domain (DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
2323 {
2324  int error = NO_ERROR;
2325  TP_DOMAIN_STATUS dom_status;
2326 
2327  if (domain_p != NULL)
2328  {
2329  dom_status = tp_value_cast (dbval_p, result_p, domain_p, false);
2330  if (dom_status != DOMAIN_COMPATIBLE)
2331  {
2332  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval_p, domain_p);
2333  assert_release (error != NO_ERROR);
2334  }
2335  }
2336 
2337  return error;
2338 }
2339 
2340 /*
2341  * qdata_add_dbval () -
2342  * return: NO_ERROR, or ER_code
2343  * dbval1(in) : First db_value node
2344  * dbval2(in) : Second db_value node
2345  * res(out) : Resultant db_value node
2346  * domain(in) :
2347  *
2348  * Note: Add two db_values.
2349  * Overflow checks are only done when both operand maximums have
2350  * overlapping precision/scale. That is,
2351  * short + integer -> overflow is checked
2352  * float + double -> overflow is not checked. Maximum float
2353  * value does not overlap maximum double
2354  * precision/scale.
2355  * MAX_FLT + MAX_DBL = MAX_DBL
2356  */
2357 int
2358 qdata_add_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
2359 {
2360  DB_TYPE type1;
2361  DB_TYPE type2;
2362  int error = NO_ERROR;
2363  DB_VALUE cast_value1;
2364  DB_VALUE cast_value2;
2365  TP_DOMAIN *cast_dom1 = NULL;
2366  TP_DOMAIN *cast_dom2 = NULL;
2367  TP_DOMAIN_STATUS dom_status;
2368 
2369  if (domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL)
2370  {
2371  return NO_ERROR;
2372  }
2373 
2374  type1 = dbval1_p ? DB_VALUE_DOMAIN_TYPE (dbval1_p) : DB_TYPE_NULL;
2375  type2 = dbval2_p ? DB_VALUE_DOMAIN_TYPE (dbval2_p) : DB_TYPE_NULL;
2376 
2377  /* Enumeration */
2378  if (type1 == DB_TYPE_ENUMERATION)
2379  {
2380  if (TP_IS_CHAR_BIT_TYPE (type2))
2381  {
2383  }
2384  else
2385  {
2387  }
2388 
2389  dom_status = tp_value_auto_cast (dbval1_p, &cast_value1, cast_dom1);
2390  if (dom_status != DOMAIN_COMPATIBLE)
2391  {
2392  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval1_p, cast_dom1);
2393  return error;
2394  }
2395  error = qdata_add_dbval (&cast_value1, dbval2_p, result_p, domain_p);
2396  pr_clear_value (&cast_value1);
2397  return error;
2398  }
2399  else if (type2 == DB_TYPE_ENUMERATION)
2400  {
2401  if (TP_IS_CHAR_BIT_TYPE (type1))
2402  {
2404  }
2405  else
2406  {
2408  }
2409  dom_status = tp_value_auto_cast (dbval2_p, &cast_value2, cast_dom2);
2410  if (dom_status != DOMAIN_COMPATIBLE)
2411  {
2412  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval2_p, cast_dom2);
2413  return error;
2414  }
2415  error = qdata_add_dbval (dbval1_p, &cast_value2, result_p, domain_p);
2416  pr_clear_value (&cast_value2);
2417  return error;
2418  }
2419 
2420  /* plus as concat : when both operands are string or bit */
2422  {
2423  if (TP_IS_CHAR_BIT_TYPE (type1) && TP_IS_CHAR_BIT_TYPE (type2))
2424  {
2425  return qdata_strcat_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2426  }
2427  }
2428 
2429  if (DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
2430  {
2431  return NO_ERROR;
2432  }
2433 
2434  db_make_null (&cast_value1);
2435  db_make_null (&cast_value2);
2436 
2437  /* not all pairs of operands types can be handled; for some of these pairs, reverse the order of operands to match
2438  * the handled case */
2439  /* STRING + NUMBER NUMBER + DATE STRING + DATE */
2440  if ((TP_IS_CHAR_TYPE (type1) && TP_IS_NUMERIC_TYPE (type2))
2441  || (TP_IS_NUMERIC_TYPE (type1) && TP_IS_DATE_OR_TIME_TYPE (type2)) || (TP_IS_CHAR_TYPE (type1)
2442  && TP_IS_DATE_OR_TIME_TYPE (type2)))
2443  {
2444  DB_VALUE *temp = NULL;
2445 
2446  temp = dbval1_p;
2447  dbval1_p = dbval2_p;
2448  dbval2_p = temp;
2449  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
2450  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
2451  }
2452 
2453  /* number + string : cast string to DOUBLE, add as numbers */
2454  if (TP_IS_NUMERIC_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
2455  {
2456  /* cast string to double */
2458  }
2459  /* date + number : cast number to bigint, add as date + bigint */
2460  /* date + string : cast string to bigint, add as date + bigint */
2461  else if (TP_IS_DATE_OR_TIME_TYPE (type1) && (TP_IS_FLOATING_NUMBER_TYPE (type2) || TP_IS_CHAR_TYPE (type2)))
2462  {
2463  /* cast number to BIGINT */
2465  }
2466  /* string + string: cast number to bigint, add as date + bigint */
2467  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
2468  {
2469  /* cast number to BIGINT */
2472  }
2473 
2474  if (cast_dom2 != NULL)
2475  {
2476  dom_status = tp_value_auto_cast (dbval2_p, &cast_value2, cast_dom2);
2477  if (dom_status != DOMAIN_COMPATIBLE)
2478  {
2479  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval2_p, cast_dom2);
2480  return error;
2481  }
2482  dbval2_p = &cast_value2;
2483  }
2484 
2485  if (cast_dom1 != NULL)
2486  {
2487  dom_status = tp_value_auto_cast (dbval1_p, &cast_value1, cast_dom1);
2488  if (dom_status != DOMAIN_COMPATIBLE)
2489  {
2490  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval1_p, cast_dom1);
2491  return error;
2492  }
2493  dbval1_p = &cast_value1;
2494  }
2495 
2496  type1 = dbval1_p ? DB_VALUE_DOMAIN_TYPE (dbval1_p) : DB_TYPE_NULL;
2497  type2 = dbval2_p ? DB_VALUE_DOMAIN_TYPE (dbval2_p) : DB_TYPE_NULL;
2498 
2499  if (DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
2500  {
2501  return NO_ERROR;
2502  }
2503 
2504  if (qdata_is_zero_value_date (dbval1_p) || qdata_is_zero_value_date (dbval2_p))
2505  {
2506  /* add operation with zero date returns null */
2507  db_make_null (result_p);
2509  {
2512  }
2513  return NO_ERROR;
2514  }
2515 
2516  switch (type1)
2517  {
2518  case DB_TYPE_SHORT:
2519  error = qdata_add_short_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2520  break;
2521 
2522  case DB_TYPE_INTEGER:
2523  error = qdata_add_int_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2524  break;
2525 
2526  case DB_TYPE_BIGINT:
2527  error = qdata_add_bigint_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2528  break;
2529 
2530  case DB_TYPE_FLOAT:
2531  error = qdata_add_float_to_dbval (dbval1_p, dbval2_p, result_p);
2532  break;
2533 
2534  case DB_TYPE_DOUBLE:
2535  error = qdata_add_double_to_dbval (dbval1_p, dbval2_p, result_p);
2536  break;
2537 
2538  case DB_TYPE_NUMERIC:
2539  error = qdata_add_numeric_to_dbval (dbval1_p, dbval2_p, result_p);
2540  break;
2541 
2542  case DB_TYPE_MONETARY:
2543  error = qdata_add_monetary_to_dbval (dbval1_p, dbval2_p, result_p);
2544  break;
2545 
2546  case DB_TYPE_CHAR:
2547  case DB_TYPE_VARCHAR:
2548  case DB_TYPE_NCHAR:
2549  case DB_TYPE_VARNCHAR:
2550  case DB_TYPE_BIT:
2551  case DB_TYPE_VARBIT:
2552  error = qdata_add_chars_to_dbval (dbval1_p, dbval2_p, result_p);
2553  break;
2554 
2555  case DB_TYPE_SET:
2556  case DB_TYPE_MULTISET:
2557  case DB_TYPE_SEQUENCE:
2558  if (!TP_IS_SET_TYPE (type2))
2559  {
2562  }
2563  if (domain_p == NULL)
2564  {
2565  if (type1 == type2)
2566  {
2567  /* partial resolve : set only basic domain; full domain will be resolved in 'fetch', based on the
2568  * result's value */
2569  domain_p = tp_domain_resolve_default (type1);
2570  }
2571  else
2572  {
2574  }
2575  }
2576  error = qdata_add_sequence_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2577  break;
2578 
2579  case DB_TYPE_TIME:
2580  error = qdata_add_time_to_dbval (dbval1_p, dbval2_p, result_p);
2581  break;
2582 
2583  case DB_TYPE_TIMESTAMP:
2584  error = qdata_add_utime_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2585  break;
2586 
2587  case DB_TYPE_TIMESTAMPLTZ:
2588  {
2589  DB_TIMESTAMPTZ ts_tz, *ts_tz_p;
2590  DB_VALUE ts_tz_val, tmp_val_res;
2591 
2592  ts_tz.timestamp = *db_get_timestamp (dbval1_p);
2593 
2594  error = tz_create_session_tzid_for_timestamp (&ts_tz.timestamp, &ts_tz.tz_id);
2595  if (error != NO_ERROR)
2596  {
2597  break;
2598  }
2599 
2600  db_make_timestamptz (&ts_tz_val, &ts_tz);
2601 
2602  error = qdata_add_timestamptz_to_dbval (&ts_tz_val, dbval2_p, &tmp_val_res);
2603  if (error != NO_ERROR)
2604  {
2605  break;
2606  }
2607  if (DB_VALUE_TYPE (&tmp_val_res) == DB_TYPE_TIMESTAMPTZ)
2608  {
2609  ts_tz_p = db_get_timestamptz (&tmp_val_res);
2610  db_make_timestampltz (result_p, ts_tz_p->timestamp);
2611  }
2612  else
2613  {
2614  assert (DB_VALUE_TYPE (&tmp_val_res) == DB_TYPE_BIGINT);
2615  pr_clone_value (&tmp_val_res, result_p);
2616  }
2617  break;
2618  }
2619 
2620  case DB_TYPE_TIMESTAMPTZ:
2621  error = qdata_add_timestamptz_to_dbval (dbval1_p, dbval2_p, result_p);
2622  break;
2623 
2624  case DB_TYPE_DATETIME:
2625  case DB_TYPE_DATETIMELTZ:
2626  /* we are adding only numbers, safe to handle DATETIMELTZ as DATETIME */
2627  error = qdata_add_datetime_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2628  if (error == NO_ERROR && type1 == DB_TYPE_DATETIMELTZ)
2629  {
2630  db_make_datetimeltz (result_p, db_get_datetime (result_p));
2631  }
2632  break;
2633 
2634  case DB_TYPE_DATETIMETZ:
2635  error = qdata_add_datetimetz_to_dbval (dbval1_p, dbval2_p, result_p);
2636  break;
2637 
2638  case DB_TYPE_DATE:
2639  error = qdata_add_date_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
2640  break;
2641 
2642  default:
2645  }
2646 
2647  if (error != NO_ERROR)
2648  {
2649  return error;
2650  }
2651 
2652  return qdata_coerce_result_to_domain (result_p, domain_p);
2653 }
2654 
2655 /*
2656  * qdata_concatenate_dbval () -
2657  * return: NO_ERROR, or ER_code
2658  * dbval1(in) : First db_value node
2659  * dbval2(in) : Second db_value node
2660  * result_p(out) : Resultant db_value node
2661  * domain_p(in) : DB domain of result
2662  * max_allowed_size(in) : max allowed size for result
2663  * warning_context(in) : used only to display truncation warning context
2664  *
2665  * Note: Concatenates a db_values to string db value.
2666  * Value to be added is truncated in case the allowed size would be
2667  * exceeded . Truncation is done without modifying the value (a new
2668  * temporary value is used).
2669  * A warning is logged the first time the allowed size is exceeded
2670  * (when the value to add has already exceeded the size, no warning is
2671  * logged).
2672  */
2673 int
2674 qdata_concatenate_dbval (THREAD_ENTRY * thread_p, DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p,
2675  tp_domain * domain_p, const int max_allowed_size, const char *warning_context)
2676 {
2677  DB_TYPE type2, type1;
2678  int error = NO_ERROR;
2679  DB_VALUE arg_val, db_temp;
2680  int res_size = 0, val_size = 0;
2681  bool warning_size_exceeded = false;
2682  int spare_bytes = 0;
2683  bool save_need_clear;
2684 
2685  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
2686  {
2687  return NO_ERROR;
2688  }
2689 
2690  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
2691  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
2692 
2693  if (!QSTR_IS_ANY_CHAR_OR_BIT (type1))
2694  {
2695  assert (false);
2698  }
2699  db_make_null (&arg_val);
2700  db_make_null (&db_temp);
2701 
2702  res_size = db_get_string_size (dbval1_p);
2703 
2704  switch (type2)
2705  {
2706  case DB_TYPE_CHAR:
2707  case DB_TYPE_VARCHAR:
2708  case DB_TYPE_NCHAR:
2709  case DB_TYPE_VARNCHAR:
2710  case DB_TYPE_BIT:
2711  case DB_TYPE_VARBIT:
2712  val_size = db_get_string_size (dbval2_p);
2713  if (res_size >= max_allowed_size)
2714  {
2715  assert (warning_size_exceeded == false);
2716  break;
2717  }
2718  else if (res_size + val_size > max_allowed_size)
2719  {
2720  warning_size_exceeded = true;
2721  error = db_string_limit_size_string (dbval2_p, &db_temp, max_allowed_size - res_size, &spare_bytes);
2722  if (error != NO_ERROR)
2723  {
2724  break;
2725  }
2726 
2727  error = qdata_add_chars_to_dbval (dbval1_p, &db_temp, result_p);
2728 
2729  if (spare_bytes > 0)
2730  {
2731  /* The adjusted 'db_temp' string was truncated to the last full multibyte character. Increase the
2732  * 'result' with 'spare_bytes' remained from the last truncated multibyte character. This prevents
2733  * GROUP_CONCAT to add other single-byte chars (or char with fewer bytes than 'spare_bytes' to current
2734  * aggregate. */
2735  save_need_clear = result_p->need_clear;
2736  qstr_make_typed_string (DB_VALUE_DOMAIN_TYPE (result_p), result_p, DB_VALUE_PRECISION (result_p),
2737  db_get_string (result_p), db_get_string_size (result_p) + spare_bytes,
2738  db_get_string_codeset (dbval1_p), db_get_string_collation (dbval1_p));
2739  result_p->need_clear = save_need_clear;
2740  }
2741  }
2742  else
2743  {
2744  error = qdata_add_chars_to_dbval (dbval1_p, dbval2_p, result_p);
2745  }
2746  break;
2747  case DB_TYPE_SHORT:
2748  case DB_TYPE_INTEGER:
2749  case DB_TYPE_BIGINT:
2750  case DB_TYPE_FLOAT:
2751  case DB_TYPE_DOUBLE:
2752  case DB_TYPE_NUMERIC:
2753  case DB_TYPE_MONETARY:
2754  case DB_TYPE_TIME:
2755  case DB_TYPE_DATE:
2756  case DB_TYPE_DATETIME:
2757  case DB_TYPE_DATETIMELTZ:
2758  case DB_TYPE_DATETIMETZ:
2759  case DB_TYPE_TIMESTAMP:
2760  case DB_TYPE_TIMESTAMPLTZ:
2761  case DB_TYPE_TIMESTAMPTZ:
2762  case DB_TYPE_ENUMERATION:
2763  {
2764  TP_DOMAIN_STATUS err_dom;
2765  err_dom = tp_value_cast (dbval2_p, &arg_val, domain_p, false);
2766 
2767  if (err_dom == DOMAIN_COMPATIBLE)
2768  {
2769  val_size = db_get_string_size (&arg_val);
2770 
2771  if (res_size >= max_allowed_size)
2772  {
2773  assert (warning_size_exceeded == false);
2774  break;
2775  }
2776  else if (res_size + val_size > max_allowed_size)
2777  {
2778  warning_size_exceeded = true;
2779  error = db_string_limit_size_string (&arg_val, &db_temp, max_allowed_size - res_size, &spare_bytes);
2780  if (error != NO_ERROR)
2781  {
2782  break;
2783  }
2784 
2785  error = qdata_add_chars_to_dbval (dbval1_p, &db_temp, result_p);
2786 
2787  if (spare_bytes > 0)
2788  {
2789  save_need_clear = result_p->need_clear;
2790  qstr_make_typed_string (DB_VALUE_DOMAIN_TYPE (result_p), result_p, DB_VALUE_PRECISION (result_p),
2791  db_get_string (result_p), db_get_string_size (result_p) + spare_bytes,
2792  db_get_string_codeset (dbval1_p), db_get_string_collation (dbval1_p));
2793  result_p->need_clear = save_need_clear;
2794  }
2795  }
2796  else
2797  {
2798  error = qdata_add_chars_to_dbval (dbval1_p, &arg_val, result_p);
2799  }
2800  }
2801  else
2802  {
2803  error = tp_domain_status_er_set (err_dom, ARG_FILE_LINE, dbval2_p, domain_p);
2804  }
2805  }
2806  break;
2807 
2808  default:
2811  }
2812 
2813  pr_clear_value (&arg_val);
2814  pr_clear_value (&db_temp);
2815  if (error == NO_ERROR && warning_size_exceeded == true)
2816  {
2818  }
2819 
2820  return error;
2821 }
2822 
2823 
2824 /*
2825  * qdata_increment_dbval () -
2826  * return: NO_ERROR, or ER_code
2827  * dbval1(in) : db_value node
2828  * res(in) :
2829  * incval(in) :
2830  *
2831  * Note: Increment the db_value.
2832  * If overflow happens, reset the db_value as 0.
2833  */
2834 int
2835 qdata_increment_dbval (DB_VALUE * dbval_p, DB_VALUE * result_p, int inc_val)
2836 {
2837  DB_TYPE type1;
2838  short stmp, s1;
2839  int itmp, i1;
2840  DB_BIGINT bitmp, bi1;
2841 
2842  type1 = DB_VALUE_DOMAIN_TYPE (dbval_p);
2843 
2844  switch (type1)
2845  {
2846  case DB_TYPE_SHORT:
2847  s1 = db_get_short (dbval_p);
2848  stmp = s1 + inc_val;
2849  if ((inc_val > 0 && OR_CHECK_ADD_OVERFLOW (s1, inc_val, stmp))
2850  || (inc_val < 0 && OR_CHECK_SUB_UNDERFLOW (s1, -inc_val, stmp)))
2851  {
2852  stmp = 0;
2853  }
2854 
2855  db_make_short (result_p, stmp);
2856  break;
2857 
2858  case DB_TYPE_INTEGER:
2859  i1 = db_get_int (dbval_p);
2860  itmp = i1 + inc_val;
2861  if ((inc_val > 0 && OR_CHECK_ADD_OVERFLOW (i1, inc_val, itmp))
2862  || (inc_val < 0 && OR_CHECK_SUB_UNDERFLOW (i1, -inc_val, itmp)))
2863  {
2864  itmp = 0;
2865  }
2866 
2867  db_make_int (result_p, itmp);
2868  break;
2869 
2870  case DB_TYPE_BIGINT:
2871  bi1 = db_get_bigint (dbval_p);
2872  bitmp = bi1 + inc_val;
2873  if ((inc_val > 0 && OR_CHECK_ADD_OVERFLOW (bi1, inc_val, bitmp))
2874  || (inc_val < 0 && OR_CHECK_SUB_UNDERFLOW (bi1, -inc_val, bitmp)))
2875  {
2876  bitmp = 0;
2877  }
2878 
2879  db_make_bigint (result_p, bitmp);
2880  break;
2881 
2882  default:
2884  return ER_FAILED;
2885  }
2886 
2887  return NO_ERROR;
2888 }
2889 
2890 static int
2891 qdata_subtract_short (short s1, short s2, DB_VALUE * result_p)
2892 {
2893  short stmp;
2894 
2895  stmp = s1 - s2;
2896 
2897  if (OR_CHECK_SUB_UNDERFLOW (s1, s2, stmp))
2898  {
2900  return ER_FAILED;
2901  }
2902 
2903  db_make_short (result_p, stmp);
2904  return NO_ERROR;
2905 }
2906 
2907 static int
2908 qdata_subtract_int (int i1, int i2, DB_VALUE * result_p)
2909 {
2910  int itmp;
2911 
2912  itmp = i1 - i2;
2913 
2914  if (OR_CHECK_SUB_UNDERFLOW (i1, i2, itmp))
2915  {
2917  return ER_FAILED;
2918  }
2919 
2920  db_make_int (result_p, itmp);
2921  return NO_ERROR;
2922 }
2923 
2924 static int
2926 {
2927  DB_BIGINT bitmp;
2928 
2929  bitmp = bi1 - bi2;
2930 
2931  if (OR_CHECK_SUB_UNDERFLOW (bi1, bi2, bitmp))
2932  {
2934  return ER_FAILED;
2935  }
2936 
2937  db_make_bigint (result_p, bitmp);
2938  return NO_ERROR;
2939 }
2940 
2941 static int
2942 qdata_subtract_float (float f1, float f2, DB_VALUE * result_p)
2943 {
2944  float ftmp;
2945 
2946  ftmp = f1 - f2;
2947 
2948  if (OR_CHECK_FLOAT_OVERFLOW (ftmp))
2949  {
2951  return ER_FAILED;
2952  }
2953 
2954  db_make_float (result_p, ftmp);
2955  return NO_ERROR;
2956 }
2957 
2958 static int
2959 qdata_subtract_double (double d1, double d2, DB_VALUE * result_p)
2960 {
2961  double dtmp;
2962 
2963  dtmp = d1 - d2;
2964 
2965  if (OR_CHECK_DOUBLE_OVERFLOW (dtmp))
2966  {
2968  return ER_FAILED;
2969  }
2970 
2971  db_make_double (result_p, dtmp);
2972  return NO_ERROR;
2973 }
2974 
2975 static int
2976 qdata_subtract_monetary (double d1, double d2, DB_CURRENCY currency, DB_VALUE * result_p)
2977 {
2978  double dtmp;
2979 
2980  dtmp = d1 - d2;
2981 
2982  if (OR_CHECK_DOUBLE_OVERFLOW (dtmp))
2983  {
2985  return ER_FAILED;
2986  }
2987 
2988  db_make_monetary (result_p, currency, dtmp);
2989  return NO_ERROR;
2990 }
2991 
2992 static int
2994 {
2995  DB_TIME utmp;
2996  int hour, minute, second;
2997 
2998  if (u1 < u2)
2999  {
3000  u1 += SECONDS_OF_ONE_DAY;
3001  }
3002 
3003  utmp = u1 - u2;
3004  db_time_decode (&utmp, &hour, &minute, &second);
3005  db_make_time (result_p, hour, minute, second);
3006 
3007  return NO_ERROR;
3008 }
3009 
3010 static int
3012 {
3013  DB_UTIME utmp;
3014 
3015  utmp = u1 - u2;
3016  if (OR_CHECK_UNS_SUB_UNDERFLOW (u1, u2, utmp))
3017  {
3019  return ER_FAILED;
3020  }
3021 
3022  db_make_timestamp (result_p, utmp);
3023  return NO_ERROR;
3024 }
3025 
3026 static int
3027 qdata_subtract_utime_to_short_asymmetry (DB_VALUE * utime_val_p, short s, unsigned int *utime, DB_VALUE * result_p,
3028  TP_DOMAIN * domain_p)
3029 {
3030  DB_VALUE tmp;
3031  int error = NO_ERROR;
3032 
3033  if (s == DB_INT16_MIN) /* check for asymmetry. */
3034  {
3035  if (*utime == DB_UINT32_MAX)
3036  {
3039  }
3040 
3041  (*utime)++;
3042  s++;
3043  }
3044 
3045  db_make_short (&tmp, -(s));
3046  error = qdata_add_dbval (utime_val_p, &tmp, result_p, domain_p);
3047 
3048  return error;
3049 }
3050 
3051 static int
3052 qdata_subtract_utime_to_int_asymmetry (DB_VALUE * utime_val_p, int i, unsigned int *utime, DB_VALUE * result_p,
3053  TP_DOMAIN * domain_p)
3054 {
3055  DB_VALUE tmp;
3056  int error = NO_ERROR;
3057 
3058  if (i == DB_INT32_MIN) /* check for asymmetry. */
3059  {
3060  if (*utime == DB_UINT32_MAX)
3061  {
3064  }
3065 
3066  (*utime)++;
3067  i++;
3068  }
3069 
3070  db_make_int (&tmp, -(i));
3071  error = qdata_add_dbval (utime_val_p, &tmp, result_p, domain_p);
3072 
3073  return error;
3074 }
3075 
3076 static int
3077 qdata_subtract_utime_to_bigint_asymmetry (DB_VALUE * utime_val_p, DB_BIGINT bi, unsigned int *utime,
3078  DB_VALUE * result_p, TP_DOMAIN * domain_p)
3079 {
3080  DB_VALUE tmp;
3081  int error = NO_ERROR;
3082 
3083  if (bi == DB_BIGINT_MIN) /* check for asymmetry. */
3084  {
3085  if (*utime == DB_UINT32_MAX)
3086  {
3089  }
3090 
3091  (*utime)++;
3092  bi++;
3093  }
3094 
3095  db_make_bigint (&tmp, -(bi));
3096  error = qdata_add_dbval (utime_val_p, &tmp, result_p, domain_p);
3097 
3098  return error;
3099 }
3100 
3101 static int
3103 {
3104  DB_DATETIME datetime_tmp;
3105  int error;
3106 
3107  error = db_subtract_int_from_datetime (dt1, i2, &datetime_tmp);
3108  if (error != NO_ERROR)
3109  {
3110  return error;
3111  }
3112 
3113  db_make_datetime (result_p, &datetime_tmp);
3114  return NO_ERROR;
3115 }
3116 
3117 static int
3119 {
3120  DB_BIGINT u1, u2, tmp;
3121 
3122  u1 = ((DB_BIGINT) dt1->date) * MILLISECONDS_OF_ONE_DAY + dt1->time;
3123  u2 = ((DB_BIGINT) dt2->date) * MILLISECONDS_OF_ONE_DAY + dt2->time;
3124 
3125  tmp = u1 - u2;
3126  if (OR_CHECK_SUB_UNDERFLOW (u1, u2, tmp))
3127  {
3129  return ER_FAILED;
3130  }
3131 
3132  db_make_bigint (result_p, tmp);
3133  return NO_ERROR;
3134 }
3135 
3136 static int
3138  DB_VALUE * result_p, TP_DOMAIN * domain_p)
3139 {
3140  DB_VALUE tmp;
3141  int error = NO_ERROR;
3142 
3143  if (i == DB_BIGINT_MIN) /* check for asymmetry. */
3144  {
3145  if (datetime->time == 0)
3146  {
3147  datetime->date--;
3148  datetime->time = MILLISECONDS_OF_ONE_DAY;
3149  }
3150 
3151  datetime->time--;
3152  i++;
3153  }
3154 
3155  db_make_bigint (&tmp, -(i));
3156  error = qdata_add_dbval (datetime_val_p, &tmp, result_p, domain_p);
3157 
3158  return error;
3159 }
3160 
3161 static int
3162 qdata_subtract_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3163 {
3164  short s;
3165  DB_TYPE type2;
3166  DB_VALUE dbval_tmp;
3167  DB_TIME *timeval, timetmp;
3168  DB_DATE *date;
3169  unsigned int u1, u2, utmp;
3170  int hour, minute, second;
3171  int err = NO_ERROR;
3172  DB_VALUE tmp_val;
3173 
3174  s = db_get_short (short_val_p);
3175  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
3176 
3177  switch (type2)
3178  {
3179  case DB_TYPE_SHORT:
3180  return qdata_subtract_short (s, db_get_short (dbval_p), result_p);
3181 
3182  case DB_TYPE_INTEGER:
3183  return qdata_subtract_int (s, db_get_int (dbval_p), result_p);
3184 
3185  case DB_TYPE_BIGINT:
3186  return qdata_subtract_bigint (s, db_get_bigint (dbval_p), result_p);
3187 
3188  case DB_TYPE_FLOAT:
3189  return qdata_subtract_float (s, db_get_float (dbval_p), result_p);
3190 
3191  case DB_TYPE_DOUBLE:
3192  return qdata_subtract_double (s, db_get_double (dbval_p), result_p);
3193 
3194  case DB_TYPE_NUMERIC:
3195  qdata_coerce_dbval_to_numeric (short_val_p, &dbval_tmp);
3196 
3197  if (numeric_db_value_sub (&dbval_tmp, dbval_p, result_p) != NO_ERROR)
3198  {
3201  }
3202  break;
3203 
3204  case DB_TYPE_MONETARY:
3205  return qdata_subtract_monetary (s, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type,
3206  result_p);
3207 
3208  case DB_TYPE_TIME:
3209  if (s < 0)
3210  {
3211  timetmp = s + SECONDS_OF_ONE_DAY;
3212  }
3213  else
3214  {
3215  timetmp = s;
3216  }
3217 
3218  timeval = db_get_time (dbval_p);
3219 
3220  err = qdata_subtract_time (timetmp, (DB_TIME) (*timeval % SECONDS_OF_ONE_DAY), result_p);
3221  return err;
3222 
3223  case DB_TYPE_TIMESTAMP:
3224  case DB_TYPE_TIMESTAMPLTZ:
3225  case DB_TYPE_TIMESTAMPTZ:
3226  db_make_bigint (&tmp_val, (DB_BIGINT) s);
3227  return qdata_subtract_bigint_to_dbval (&tmp_val, dbval_p, result_p);
3228 
3229  case DB_TYPE_DATETIME:
3230  case DB_TYPE_DATETIMELTZ:
3231  case DB_TYPE_DATETIMETZ:
3232  db_make_int (&tmp_val, (int) s);
3233  return qdata_subtract_int_to_dbval (&tmp_val, dbval_p, result_p);
3234 
3235  case DB_TYPE_DATE:
3236  date = db_get_date (dbval_p);
3237 
3238  u1 = (unsigned int) s;
3239  u2 = (unsigned int) *date;
3240  utmp = u1 - u2;
3241 
3242  if (s < 0 || OR_CHECK_UNS_SUB_UNDERFLOW (u1, u2, utmp))
3243  {
3245  return ER_FAILED;
3246  }
3247 
3248  db_time_decode (&utmp, &hour, &minute, &second);
3249  db_make_time (result_p, hour, minute, second);
3250  break;
3251 
3252  default:
3253  break;
3254  }
3255 
3256  return err;
3257 }
3258 
3259 static int
3260 qdata_subtract_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3261 {
3262  int i;
3263  DB_TYPE type;
3264  DB_VALUE dbval_tmp;
3265  DB_DATE *date;
3266  DB_DATETIME *datetime, datetime_tmp;
3267  unsigned int u1, u2, utmp;
3268  int day, month, year;
3269  DB_VALUE tmp_val;
3270  int err = NO_ERROR;
3271 
3272  i = db_get_int (int_val_p);
3273  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3274 
3275  switch (type)
3276  {
3277  case DB_TYPE_SHORT:
3278  return qdata_subtract_int (i, db_get_short (dbval_p), result_p);
3279 
3280  case DB_TYPE_INTEGER:
3281  return qdata_subtract_int (i, db_get_int (dbval_p), result_p);
3282 
3283  case DB_TYPE_BIGINT:
3284  return qdata_subtract_bigint (i, db_get_bigint (dbval_p), result_p);
3285 
3286  case DB_TYPE_FLOAT:
3287  return qdata_subtract_float ((float) i, db_get_float (dbval_p), result_p);
3288 
3289  case DB_TYPE_DOUBLE:
3290  return qdata_subtract_double (i, db_get_double (dbval_p), result_p);
3291 
3292  case DB_TYPE_NUMERIC:
3293  qdata_coerce_dbval_to_numeric (int_val_p, &dbval_tmp);
3294 
3295  if (numeric_db_value_sub (&dbval_tmp, dbval_p, result_p) != NO_ERROR)
3296  {
3298  return ER_FAILED;
3299  }
3300  break;
3301 
3302  case DB_TYPE_MONETARY:
3303  return qdata_subtract_monetary (i, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type,
3304  result_p);
3305 
3306  case DB_TYPE_TIME:
3307  case DB_TYPE_TIMESTAMP:
3308  case DB_TYPE_TIMESTAMPLTZ:
3309  case DB_TYPE_TIMESTAMPTZ:
3310  db_make_bigint (&tmp_val, (DB_BIGINT) i);
3311  return qdata_subtract_bigint_to_dbval (&tmp_val, dbval_p, result_p);
3312 
3313  case DB_TYPE_DATETIME:
3314  datetime = db_get_datetime (dbval_p);
3315 
3316  datetime_tmp.date = i / MILLISECONDS_OF_ONE_DAY;
3317  datetime_tmp.time = i % MILLISECONDS_OF_ONE_DAY;
3318 
3319  return qdata_subtract_datetime (&datetime_tmp, datetime, result_p);
3320 
3321  case DB_TYPE_DATETIMELTZ:
3322  {
3323  DB_DATETIME dt_local;
3324 
3325  datetime = db_get_datetime (dbval_p);
3326  err = tz_datetimeltz_to_local (datetime, &dt_local);
3327  if (err != NO_ERROR)
3328  {
3329  break;
3330  }
3331 
3332  datetime_tmp.date = i / MILLISECONDS_OF_ONE_DAY;
3333  datetime_tmp.time = i % MILLISECONDS_OF_ONE_DAY;
3334 
3335  return qdata_subtract_datetime (&datetime_tmp, &dt_local, result_p);
3336  }
3337 
3338  case DB_TYPE_DATETIMETZ:
3339  {
3340  DB_DATETIMETZ dt_tz;
3341  DB_DATETIME dt_local;
3342 
3343  dt_tz = *db_get_datetimetz (dbval_p);
3344 
3345  err = tz_utc_datetimetz_to_local (&dt_tz.datetime, &dt_tz.tz_id, &dt_local);
3346  if (err != NO_ERROR)
3347  {
3348  break;
3349  }
3350 
3351  datetime_tmp.date = i / MILLISECONDS_OF_ONE_DAY;
3352  datetime_tmp.time = i % MILLISECONDS_OF_ONE_DAY;
3353 
3354  return qdata_subtract_datetime (&datetime_tmp, &dt_local, result_p);
3355  }
3356 
3357  case DB_TYPE_DATE:
3358  date = db_get_date (dbval_p);
3359 
3360  u1 = (unsigned int) i;
3361  u2 = (unsigned int) *date;
3362  utmp = u1 - u2;
3363 
3364  if (i < 0 || OR_CHECK_UNS_SUB_UNDERFLOW (u1, u2, utmp))
3365  {
3367  return ER_FAILED;
3368  }
3369 
3370  db_date_decode (&utmp, &month, &day, &year);
3371  db_make_date (result_p, month, day, year);
3372  break;
3373 
3374  default:
3375  break;
3376  }
3377 
3378  return NO_ERROR;
3379 }
3380 
3381 static int
3382 qdata_subtract_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3383 {
3384  DB_BIGINT bi;
3385  DB_TYPE type;
3386  DB_VALUE dbval_tmp;
3387  DB_TIME *timeval;
3388  DB_DATE *date;
3389  unsigned int u1, u2, utmp;
3390  DB_UTIME *utime;
3391  int day, month, year;
3392  int err = NO_ERROR;
3393 
3394  bi = db_get_bigint (bigint_val_p);
3395  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3396 
3397  switch (type)
3398  {
3399  case DB_TYPE_SHORT:
3400  return qdata_subtract_bigint (bi, db_get_short (dbval_p), result_p);
3401 
3402  case DB_TYPE_INTEGER:
3403  return qdata_subtract_bigint (bi, db_get_int (dbval_p), result_p);
3404 
3405  case DB_TYPE_BIGINT:
3406  return qdata_subtract_bigint (bi, db_get_bigint (dbval_p), result_p);
3407 
3408  case DB_TYPE_FLOAT:
3409  return qdata_subtract_float ((float) bi, db_get_float (dbval_p), result_p);
3410 
3411  case DB_TYPE_DOUBLE:
3412  return qdata_subtract_double ((double) bi, db_get_double (dbval_p), result_p);
3413 
3414  case DB_TYPE_NUMERIC:
3415  qdata_coerce_dbval_to_numeric (bigint_val_p, &dbval_tmp);
3416 
3417  if (numeric_db_value_sub (&dbval_tmp, dbval_p, result_p) != NO_ERROR)
3418  {
3420  return ER_FAILED;
3421  }
3422  break;
3423 
3424  case DB_TYPE_MONETARY:
3425  return qdata_subtract_monetary ((double) bi, (db_get_monetary (dbval_p))->amount,
3426  (db_get_monetary (dbval_p))->type, result_p);
3427 
3428  case DB_TYPE_TIME:
3429  if (bi < 0)
3430  {
3431  bi = (bi % SECONDS_OF_ONE_DAY) + SECONDS_OF_ONE_DAY;
3432  }
3433  else
3434  {
3435  bi %= SECONDS_OF_ONE_DAY;
3436  }
3437 
3438  timeval = db_get_time (dbval_p);
3439  err = qdata_subtract_time ((DB_TIME) bi, (DB_TIME) (*timeval % SECONDS_OF_ONE_DAY), result_p);
3440  return err;
3441 
3442  case DB_TYPE_TIMESTAMP:
3443  case DB_TYPE_TIMESTAMPLTZ:
3444  utime = db_get_timestamp (dbval_p);
3445  err = qdata_subtract_utime ((DB_UTIME) bi, *utime, result_p);
3446  if (err != NO_ERROR)
3447  {
3448  break;
3449  }
3450  if (err == NO_ERROR && type == DB_TYPE_TIMESTAMPLTZ)
3451  {
3452  db_make_timestampltz (result_p, *db_get_timestamp (result_p));
3453  }
3454  return err;
3455 
3456  case DB_TYPE_TIMESTAMPTZ:
3457  {
3458  DB_TIMESTAMPTZ ts_tz_res, ts_tz_fixed, *ts_tz_p;
3459 
3460  ts_tz_p = db_get_timestamptz (dbval_p);
3461  utime = &ts_tz_p->timestamp;
3462  err = qdata_subtract_utime ((DB_UTIME) bi, *utime, result_p);
3463  if (err != NO_ERROR)
3464  {
3465  break;
3466  }
3467  ts_tz_res.timestamp = *db_get_timestamp (result_p);
3468  ts_tz_res.tz_id = ts_tz_p->tz_id;
3469  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_fixed);
3470  if (err != NO_ERROR)
3471  {
3472  break;
3473  }
3474  db_make_timestamptz (result_p, &ts_tz_fixed);
3475  return err;
3476  }
3477 
3478  case DB_TYPE_DATE:
3479  date = db_get_date (dbval_p);
3480 
3481  u1 = (unsigned int) bi;
3482  u2 = (unsigned int) *date;
3483  utmp = u1 - u2;
3484 
3485  if (bi < 0 || OR_CHECK_UNS_SUB_UNDERFLOW (u1, u2, utmp))
3486  {
3488  return ER_FAILED;
3489  }
3490 
3491  db_date_decode (&utmp, &month, &day, &year);
3492  db_make_date (result_p, month, day, year);
3493  break;
3494 
3495  default:
3496  break;
3497  }
3498 
3499  return err;
3500 }
3501 
3502 static int
3503 qdata_subtract_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3504 {
3505  float f;
3506  DB_TYPE type;
3507 
3508  f = db_get_float (float_val_p);
3509  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3510 
3511  switch (type)
3512  {
3513  case DB_TYPE_SHORT:
3514  return qdata_subtract_float (f, db_get_short (dbval_p), result_p);
3515 
3516  case DB_TYPE_INTEGER:
3517  return qdata_subtract_float (f, (float) db_get_int (dbval_p), result_p);
3518 
3519  case DB_TYPE_BIGINT:
3520  return qdata_subtract_float (f, (float) db_get_bigint (dbval_p), result_p);
3521 
3522  case DB_TYPE_FLOAT:
3523  return qdata_subtract_float (f, db_get_float (dbval_p), result_p);
3524 
3525  case DB_TYPE_DOUBLE:
3526  return qdata_subtract_double (f, db_get_double (dbval_p), result_p);
3527 
3528  case DB_TYPE_NUMERIC:
3529  return qdata_subtract_double (f, qdata_coerce_numeric_to_double (dbval_p), result_p);
3530 
3531  case DB_TYPE_MONETARY:
3532  return qdata_subtract_monetary (f, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type,
3533  result_p);
3534 
3535  default:
3536  break;
3537  }
3538 
3539  return NO_ERROR;
3540 }
3541 
3542 static int
3543 qdata_subtract_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3544 {
3545  double d;
3546  DB_TYPE type;
3547 
3548  d = db_get_double (double_val_p);
3549  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3550 
3551  switch (type)
3552  {
3553  case DB_TYPE_SHORT:
3554  return qdata_subtract_double (d, db_get_short (dbval_p), result_p);
3555 
3556  case DB_TYPE_INTEGER:
3557  return qdata_subtract_double (d, db_get_int (dbval_p), result_p);
3558 
3559  case DB_TYPE_BIGINT:
3560  return qdata_subtract_double (d, (double) db_get_bigint (dbval_p), result_p);
3561 
3562  case DB_TYPE_FLOAT:
3563  return qdata_subtract_double (d, db_get_float (dbval_p), result_p);
3564 
3565  case DB_TYPE_DOUBLE:
3566  return qdata_subtract_double (d, db_get_double (dbval_p), result_p);
3567 
3568  case DB_TYPE_NUMERIC:
3569  return qdata_subtract_double (d, qdata_coerce_numeric_to_double (dbval_p), result_p);
3570 
3571  case DB_TYPE_MONETARY:
3572  return qdata_subtract_monetary (d, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type,
3573  result_p);
3574 
3575  default:
3576  break;
3577  }
3578 
3579  return NO_ERROR;
3580 }
3581 
3582 static int
3583 qdata_subtract_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3584 {
3585  DB_TYPE type;
3586  DB_VALUE dbval_tmp;
3587 
3588  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3589 
3590  switch (type)
3591  {
3592  case DB_TYPE_SHORT:
3593  case DB_TYPE_INTEGER:
3594  case DB_TYPE_BIGINT:
3595  qdata_coerce_dbval_to_numeric (dbval_p, &dbval_tmp);
3596 
3597  if (numeric_db_value_sub (numeric_val_p, &dbval_tmp, result_p) != NO_ERROR)
3598  {
3600  return ER_FAILED;
3601  }
3602  break;
3603 
3604  case DB_TYPE_NUMERIC:
3605  if (numeric_db_value_sub (numeric_val_p, dbval_p, result_p) != NO_ERROR)
3606  {
3608  return ER_FAILED;
3609  }
3610  break;
3611 
3612  case DB_TYPE_FLOAT:
3613  return qdata_subtract_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_float (dbval_p), result_p);
3614  break;
3615 
3616  case DB_TYPE_DOUBLE:
3617  return qdata_subtract_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_double (dbval_p), result_p);
3618  break;
3619 
3620  case DB_TYPE_MONETARY:
3622  (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p);
3623  break;
3624 
3625  default:
3626  break;
3627  }
3628 
3629  return NO_ERROR;
3630 }
3631 
3632 static int
3633 qdata_subtract_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3634 {
3635  double d;
3636  DB_CURRENCY currency;
3637  DB_TYPE type;
3638 
3639  d = (db_get_monetary (monetary_val_p))->amount;
3640  currency = (db_get_monetary (monetary_val_p))->type;
3641  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3642 
3643  switch (type)
3644  {
3645  case DB_TYPE_SHORT:
3646  return qdata_subtract_monetary (d, db_get_short (dbval_p), currency, result_p);
3647 
3648  case DB_TYPE_INTEGER:
3649  return qdata_subtract_monetary (d, db_get_int (dbval_p), currency, result_p);
3650 
3651  case DB_TYPE_BIGINT:
3652  return qdata_subtract_monetary (d, (double) db_get_bigint (dbval_p), currency, result_p);
3653 
3654  case DB_TYPE_FLOAT:
3655  return qdata_subtract_monetary (d, db_get_float (dbval_p), currency, result_p);
3656 
3657  case DB_TYPE_DOUBLE:
3658  return qdata_subtract_monetary (d, db_get_double (dbval_p), currency, result_p);
3659 
3660  case DB_TYPE_NUMERIC:
3661  return qdata_subtract_monetary (d, qdata_coerce_numeric_to_double (dbval_p), currency, result_p);
3662 
3663  case DB_TYPE_MONETARY:
3664  /* Note: we probably should return an error if the two monetaries have different monetary types. */
3665  return qdata_subtract_monetary (d, (db_get_monetary (dbval_p))->amount, currency, result_p);
3666 
3667  default:
3668  break;
3669  }
3670 
3671  return NO_ERROR;
3672 }
3673 
3674 static int
3675 qdata_subtract_sequence_to_dbval (DB_VALUE * seq_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
3676 {
3677  DB_SET *set_tmp;
3678 #if !defined(NDEBUG)
3679  DB_TYPE type1, type2;
3680 #endif
3681 
3682 #if !defined(NDEBUG)
3683  type1 = DB_VALUE_DOMAIN_TYPE (seq_val_p);
3684  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
3685 
3686  assert (TP_IS_SET_TYPE (type1));
3687  assert (TP_IS_SET_TYPE (type2));
3688 #endif
3689 
3690  if (domain_p == NULL)
3691  {
3692  return ER_FAILED;
3693  }
3694 
3695  if (set_difference (db_get_set (seq_val_p), db_get_set (dbval_p), &set_tmp, domain_p) < 0)
3696  {
3697  return ER_FAILED;
3698  }
3699 
3700  set_make_collection (result_p, set_tmp);
3701  return NO_ERROR;
3702 }
3703 
3704 static int
3705 qdata_subtract_time_to_dbval (DB_VALUE * time_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
3706 {
3707  DB_TYPE type;
3708  DB_TIME *timeval, *timeval1;
3709  int subval;
3710  int err = NO_ERROR;
3711 
3712  timeval = db_get_time (time_val_p);
3713  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3714 
3715  switch (type)
3716  {
3717  case DB_TYPE_SHORT:
3718  subval = (int) db_get_short (dbval_p);
3719  if (subval < 0)
3720  {
3721  return qdata_add_bigint_to_time (time_val_p, (DB_BIGINT) (-subval), result_p);
3722  }
3723  return qdata_subtract_time ((DB_TIME) (*timeval % SECONDS_OF_ONE_DAY), (DB_TIME) subval, result_p);
3724 
3725  case DB_TYPE_INTEGER:
3726  subval = (int) (db_get_int (dbval_p) % SECONDS_OF_ONE_DAY);
3727  if (subval < 0)
3728  {
3729  return qdata_add_bigint_to_time (time_val_p, (DB_BIGINT) (-subval), result_p);
3730  }
3731  return qdata_subtract_time ((DB_TIME) (*timeval % SECONDS_OF_ONE_DAY), (DB_TIME) subval, result_p);
3732 
3733  case DB_TYPE_BIGINT:
3734  subval = (int) (db_get_bigint (dbval_p) % SECONDS_OF_ONE_DAY);
3735  if (subval < 0)
3736  {
3737  return qdata_add_bigint_to_time (time_val_p, (DB_BIGINT) (-subval), result_p);
3738  }
3739  return qdata_subtract_time ((DB_TIME) (*timeval % SECONDS_OF_ONE_DAY), (DB_TIME) subval, result_p);
3740 
3741  case DB_TYPE_TIME:
3742  timeval1 = db_get_time (dbval_p);
3743  db_make_int (result_p, ((int) *timeval - (int) *timeval1));
3744  break;
3745 
3746  default:
3747  break;
3748  }
3749 
3750  return err;
3751 }
3752 
3753 static int
3754 qdata_subtract_utime_to_dbval (DB_VALUE * utime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
3755 {
3756  DB_TYPE type;
3757  DB_UTIME *utime, *utime1;
3758  DB_TIMESTAMPTZ *ts_tz1;
3759  DB_DATETIME *datetime;
3760  DB_DATETIME tmp_datetime;
3761  DB_DATETIMETZ datetime_tz_1;
3762  unsigned int u1;
3763  short s2;
3764  int i2;
3765  DB_BIGINT bi2;
3766 
3767  utime = db_get_timestamp (utime_val_p);
3768  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3769 
3770  switch (type)
3771  {
3772  case DB_TYPE_SHORT:
3773  u1 = (unsigned int) *utime;
3774  s2 = db_get_short (dbval_p);
3775  if (s2 < 0)
3776  {
3777  /* We're really adding. */
3778  return qdata_subtract_utime_to_short_asymmetry (utime_val_p, s2, utime, result_p, domain_p);
3779  }
3780 
3781  return qdata_subtract_utime (*utime, (DB_UTIME) s2, result_p);
3782 
3783  case DB_TYPE_INTEGER:
3784  u1 = (unsigned int) *utime;
3785  i2 = db_get_int (dbval_p);
3786  if (i2 < 0)
3787  {
3788  /* We're really adding. */
3789  return qdata_subtract_utime_to_int_asymmetry (utime_val_p, i2, utime, result_p, domain_p);
3790  }
3791 
3792  return qdata_subtract_utime (*utime, (DB_UTIME) i2, result_p);
3793 
3794  case DB_TYPE_BIGINT:
3795  u1 = (unsigned int) *utime;
3796  bi2 = db_get_bigint (dbval_p);
3797  if (bi2 < 0)
3798  {
3799  /* We're really adding. */
3800  return qdata_subtract_utime_to_bigint_asymmetry (utime_val_p, bi2, utime, result_p, domain_p);
3801  }
3802 
3803  return qdata_subtract_utime (*utime, (DB_UTIME) bi2, result_p);
3804 
3805  case DB_TYPE_TIMESTAMP:
3806  case DB_TYPE_TIMESTAMPLTZ:
3807  utime1 = db_get_timestamp (dbval_p);
3808  db_make_int (result_p, ((int) *utime - (int) *utime1));
3809  break;
3810 
3811  case DB_TYPE_TIMESTAMPTZ:
3812  ts_tz1 = db_get_timestamptz (dbval_p);
3813  db_make_int (result_p, ((int) *utime - (int) ts_tz1->timestamp));
3814  break;
3815 
3816  case DB_TYPE_DATETIME:
3817  datetime = db_get_datetime (dbval_p);
3818 
3819  (void) db_timestamp_decode_ses (utime, &tmp_datetime.date, &tmp_datetime.time);
3820 
3821  return qdata_subtract_datetime (&tmp_datetime, datetime, result_p);
3822 
3823  case DB_TYPE_DATETIMELTZ:
3824  datetime = db_get_datetime (dbval_p);
3825  (void) db_timestamp_decode_utc (utime, &tmp_datetime.date, &tmp_datetime.time);
3826 
3827  return qdata_subtract_datetime (&tmp_datetime, datetime, result_p);
3828 
3829  case DB_TYPE_DATETIMETZ:
3830  datetime_tz_1 = *db_get_datetimetz (dbval_p);
3831  (void) db_timestamp_decode_utc (utime, &tmp_datetime.date, &tmp_datetime.time);
3832 
3833  return qdata_subtract_datetime (&tmp_datetime, &datetime_tz_1.datetime, result_p);
3834 
3835  default:
3836  break;
3837  }
3838 
3839  return NO_ERROR;
3840 }
3841 
3842 static int
3843 qdata_subtract_timestampltz_to_dbval (DB_VALUE * ts_ltz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
3844  TP_DOMAIN * domain_p)
3845 {
3846  DB_TYPE type;
3847  DB_UTIME *utime_p;
3848  DB_VALUE utime_val, tmp_val_res;
3849  int err = NO_ERROR;
3850 
3851  utime_p = db_get_timestamp (ts_ltz_val_p);
3852  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3853 
3854  switch (type)
3855  {
3856  case DB_TYPE_SHORT:
3857  case DB_TYPE_INTEGER:
3858  case DB_TYPE_BIGINT:
3859  case DB_TYPE_TIMESTAMP:
3860  case DB_TYPE_TIMESTAMPLTZ:
3861  case DB_TYPE_TIMESTAMPTZ:
3862  case DB_TYPE_DATETIME:
3863  case DB_TYPE_DATETIMELTZ:
3864  case DB_TYPE_DATETIMETZ:
3865  /* perform operation as simple UTIME */
3866  db_make_timestamp (&utime_val, *utime_p);
3867  err =
3868  qdata_subtract_utime_to_dbval (&utime_val, dbval_p, &tmp_val_res,
3870  if (err != NO_ERROR)
3871  {
3872  break;
3873  }
3874 
3875  if (DB_VALUE_TYPE (&tmp_val_res) == DB_TYPE_TIMESTAMP)
3876  {
3877  db_make_timestampltz (result_p, *db_get_timestamp (&tmp_val_res));
3878  }
3879  else
3880  {
3881  assert (tmp_val_res.need_clear == false);
3882  pr_clone_value (&tmp_val_res, result_p);
3883  }
3884  break;
3885  default:
3886  break;
3887  }
3888 
3889  return NO_ERROR;
3890 }
3891 
3892 static int
3893 qdata_subtract_timestamptz_to_dbval (DB_VALUE * ts_tz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
3894  TP_DOMAIN * domain_p)
3895 {
3896  int err = NO_ERROR;
3897  DB_TYPE type;
3898  DB_UTIME *utime1 = NULL, *utime2 = NULL;
3899  DB_TIMESTAMPTZ *ts_tz1_p = NULL, *ts_tz2_p = NULL, ts_tz_res, ts_tz_res_fixed;
3900  DB_DATETIME *datetime = NULL;
3901  DB_DATETIME tmp_datetime;
3902  DB_DATETIMETZ datetime_tz_1;
3903  DB_DATE date;
3904  DB_TIME time;
3905  unsigned int u1;
3906  short s2;
3907  int i2;
3908  DB_BIGINT bi2;
3909 
3910  DB_VALUE tmp_val_res;
3911  tmp_val_res.data.utime = 0;
3912 
3913  ts_tz1_p = db_get_timestamptz (ts_tz_val_p);
3914  utime1 = &ts_tz1_p->timestamp;
3915  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
3916 
3917  switch (type)
3918  {
3919  case DB_TYPE_SHORT:
3920  u1 = (unsigned int) *utime1;
3921  s2 = db_get_short (dbval_p);
3922  if (s2 < 0)
3923  {
3924  /* We're really adding. */
3925  return qdata_subtract_utime_to_short_asymmetry (ts_tz_val_p, s2, utime1, result_p, domain_p);
3926  }
3927 
3928  err = qdata_subtract_utime (*utime1, (DB_UTIME) s2, &tmp_val_res);
3929  break;
3930 
3931  case DB_TYPE_INTEGER:
3932  u1 = (unsigned int) *utime1;
3933  i2 = db_get_int (dbval_p);
3934  if (i2 < 0)
3935  {
3936  /* We're really adding. */
3937  return qdata_subtract_utime_to_int_asymmetry (ts_tz_val_p, i2, utime1, result_p, domain_p);
3938  }
3939 
3940  err = qdata_subtract_utime (*utime1, (DB_UTIME) i2, &tmp_val_res);
3941  break;
3942 
3943  case DB_TYPE_BIGINT:
3944  u1 = (unsigned int) *utime1;
3945  bi2 = db_get_bigint (dbval_p);
3946  if (bi2 < 0)
3947  {
3948  /* We're really adding. */
3949  return qdata_subtract_utime_to_bigint_asymmetry (ts_tz_val_p, bi2, utime1, result_p, domain_p);
3950  }
3951 
3952  err = qdata_subtract_utime (*utime1, (DB_UTIME) bi2, &tmp_val_res);
3953  break;
3954 
3955  case DB_TYPE_TIMESTAMP:
3956  case DB_TYPE_TIMESTAMPLTZ:
3957  utime2 = db_get_timestamp (dbval_p);
3958  db_make_int (result_p, ((int) *utime1 - (int) *utime2));
3959  return err;
3960 
3961  case DB_TYPE_TIMESTAMPTZ:
3962  ts_tz2_p = db_get_timestamptz (dbval_p);
3963  db_make_int (result_p, ((int) *utime1 - (int) ts_tz2_p->timestamp));
3964  return err;
3965 
3966  case DB_TYPE_DATETIME:
3967  datetime = db_get_datetime (dbval_p);
3968 
3969  err = db_timestamp_decode_w_tz_id (utime1, &ts_tz1_p->tz_id, &date, &time);
3970  if (err != NO_ERROR)
3971  {
3972  break;
3973  }
3974 
3975  tmp_datetime.date = date;
3976  tmp_datetime.time = time * 1000;
3977 
3978  return qdata_subtract_datetime (&tmp_datetime, datetime, result_p);
3979 
3980  case DB_TYPE_DATETIMELTZ:
3981  datetime = db_get_datetime (dbval_p);
3982  db_timestamp_decode_utc (utime1, &date, &time);
3983 
3984  tmp_datetime.date = date;
3985  tmp_datetime.time = time * 1000;
3986 
3987  return qdata_subtract_datetime (&tmp_datetime, datetime, result_p);
3988 
3989  case DB_TYPE_DATETIMETZ:
3990  datetime_tz_1 = *db_get_datetimetz (dbval_p);
3991  db_timestamp_decode_utc (utime1, &date, &time);
3992 
3993  if (err != NO_ERROR)
3994  {
3995  break;
3996  }
3997 
3998  tmp_datetime.date = date;
3999  tmp_datetime.time = time * 1000;
4000 
4001  return qdata_subtract_datetime (&tmp_datetime, &datetime_tz_1.datetime, result_p);
4002 
4003  default:
4004  break;
4005  }
4006 
4007  if (err == NO_ERROR)
4008  {
4009  assert (DB_VALUE_TYPE (&tmp_val_res) == DB_TYPE_TIMESTAMP);
4010  /* create TIMESTAMPTZ from result UTIME by adjusting TZ_ID */
4011  ts_tz_res.timestamp = *db_get_timestamp (&tmp_val_res);
4012  ts_tz_res.tz_id = ts_tz1_p->tz_id;
4013  err = tz_timestamptz_fix_zone (&ts_tz_res, &ts_tz_res_fixed);
4014  if (err != NO_ERROR)
4015  {
4016  return err;
4017  }
4018 
4019  db_make_timestamptz (result_p, &ts_tz_res_fixed);
4020  }
4021  return err;
4022 }
4023 
4024 static int
4025 qdata_subtract_datetime_to_dbval (DB_VALUE * datetime_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
4026  TP_DOMAIN * domain_p)
4027 {
4028  DB_TYPE type;
4029  DB_DATETIME *datetime1_p;
4030 
4031  datetime1_p = db_get_datetime (datetime_val_p);
4032  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
4033 
4034  switch (type)
4035  {
4036  case DB_TYPE_SHORT:
4037  {
4038  short s2;
4039  s2 = db_get_short (dbval_p);
4040  if (s2 < 0)
4041  {
4042  /* We're really adding. */
4043  return qdata_subtract_datetime_to_int_asymmetry (datetime_val_p, s2, datetime1_p, result_p, domain_p);
4044  }
4045 
4046  return qdata_subtract_datetime_to_int (datetime1_p, s2, result_p);
4047  }
4048 
4049  case DB_TYPE_INTEGER:
4050  {
4051  int i2;
4052  i2 = db_get_int (dbval_p);
4053  if (i2 < 0)
4054  {
4055  /* We're really adding. */
4056  return qdata_subtract_datetime_to_int_asymmetry (datetime_val_p, i2, datetime1_p, result_p, domain_p);
4057  }
4058 
4059  return qdata_subtract_datetime_to_int (datetime1_p, i2, result_p);
4060  }
4061 
4062  case DB_TYPE_BIGINT:
4063  {
4064  DB_BIGINT bi2;
4065 
4066  bi2 = db_get_bigint (dbval_p);
4067  if (bi2 < 0)
4068  {
4069  /* We're really adding. */
4070  return qdata_subtract_datetime_to_int_asymmetry (datetime_val_p, bi2, datetime1_p, result_p, domain_p);
4071  }
4072 
4073  return qdata_subtract_datetime_to_int (datetime1_p, bi2, result_p);
4074  }
4075 
4076  case DB_TYPE_TIMESTAMP:
4077  {
4078  DB_BIGINT u1, u2;
4079  DB_DATETIME datetime2;
4080 
4081  (void) db_timestamp_decode_ses (db_get_timestamp (dbval_p), &datetime2.date, &datetime2.time);
4082 
4083  u1 = ((DB_BIGINT) datetime1_p->date) * MILLISECONDS_OF_ONE_DAY + datetime1_p->time;
4084  u2 = ((DB_BIGINT) datetime2.date) * MILLISECONDS_OF_ONE_DAY + datetime2.time;
4085 
4086  return db_make_bigint (result_p, u1 - u2);
4087  }
4088 
4089  case DB_TYPE_TIMESTAMPLTZ:
4090  {
4091  DB_BIGINT u1, u2;
4092  DB_DATETIME datetime2;
4093 
4094  (void) db_timestamp_decode_ses (db_get_timestamp (dbval_p), &datetime2.date, &datetime2.time);
4095 
4096  u1 = ((DB_BIGINT) datetime1_p->date) * MILLISECONDS_OF_ONE_DAY + datetime1_p->time;
4097  u2 = ((DB_BIGINT) datetime2.date) * MILLISECONDS_OF_ONE_DAY + datetime2.time;
4098 
4099  return db_make_bigint (result_p, u1 - u2);
4100  }
4101 
4102  case DB_TYPE_TIMESTAMPTZ:
4103  {
4104  DB_BIGINT u1, u2;
4105  DB_DATETIME datetime2;
4106  DB_TIMESTAMPTZ ts_tz2;
4107 
4108  ts_tz2 = *db_get_timestamptz (dbval_p);
4109 
4110  (void) db_timestamp_decode_ses (&ts_tz2.timestamp, &datetime2.date, &datetime2.time);
4111 
4112  u1 = ((DB_BIGINT) datetime1_p->date) * MILLISECONDS_OF_ONE_DAY + datetime1_p->time;
4113  u2 = ((DB_BIGINT) datetime2.date) * MILLISECONDS_OF_ONE_DAY + datetime2.time;
4114 
4115  return db_make_bigint (result_p, u1 - u2);
4116  }
4117 
4118  case DB_TYPE_DATETIME:
4119  {
4120  DB_BIGINT u1, u2;
4121  DB_DATETIME *datetime2_p;
4122 
4123  datetime2_p = db_get_datetime (dbval_p);
4124 
4125  u1 = ((DB_BIGINT) datetime1_p->date) * MILLISECONDS_OF_ONE_DAY + datetime1_p->time;
4126  u2 = ((DB_BIGINT) datetime2_p->date) * MILLISECONDS_OF_ONE_DAY + datetime2_p->time;
4127 
4128  return db_make_bigint (result_p, u1 - u2);
4129  }
4130 
4131  case DB_TYPE_DATETIMELTZ:
4132  {
4133  DB_BIGINT u1, u2;
4134  DB_DATETIMETZ dt_tz1;
4135  DB_DATETIME *dt_utc2_p;
4136  int err;
4137 
4138  err = tz_create_datetimetz_from_ses (datetime1_p, &dt_tz1);
4139  if (err != NO_ERROR)
4140  {
4141  return err;
4142  }
4143 
4144  dt_utc2_p = db_get_datetime (dbval_p);
4145 
4146  u1 = ((DB_BIGINT) dt_tz1.datetime.date) * MILLISECONDS_OF_ONE_DAY + dt_tz1.datetime.time;
4147  u2 = ((DB_BIGINT) dt_utc2_p->date) * MILLISECONDS_OF_ONE_DAY + dt_utc2_p->time;
4148 
4149  return db_make_bigint (result_p, u1 - u2);
4150  }
4151 
4152  case DB_TYPE_DATETIMETZ:
4153  {
4154  DB_BIGINT u1, u2;
4155  DB_DATETIMETZ *datetimetz2_p;
4156  DB_DATETIME datetime2;
4157  int err;
4158 
4159  datetimetz2_p = db_get_datetimetz (dbval_p);
4160  err = tz_utc_datetimetz_to_local (&datetimetz2_p->datetime, &datetimetz2_p->tz_id, &datetime2);
4161 
4162  if (err != NO_ERROR)
4163  {
4164  return err;
4165  }
4166 
4167  u1 = ((DB_BIGINT) datetime1_p->date) * MILLISECONDS_OF_ONE_DAY + datetime1_p->time;
4168  u2 = ((DB_BIGINT) datetime2.date) * MILLISECONDS_OF_ONE_DAY + datetime2.time;
4169 
4170  return db_make_bigint (result_p, u1 - u2);
4171  }
4172 
4173  case DB_TYPE_DATE:
4174  {
4175  DB_BIGINT u1, u2;
4176 
4177  u1 = ((DB_BIGINT) datetime1_p->date) * MILLISECONDS_OF_ONE_DAY + datetime1_p->time;
4178  u2 = ((DB_BIGINT) * db_get_date (dbval_p)) * MILLISECONDS_OF_ONE_DAY;
4179 
4180  return db_make_bigint (result_p, u1 - u2);
4181  }
4182 
4183  default:
4184  break;
4185  }
4186 
4187  return NO_ERROR;
4188 }
4189 
4190 static int
4191 qdata_subtract_datetimetz_to_dbval (DB_VALUE * dt_tz_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p,
4192  TP_DOMAIN * domain_p)
4193 {
4194  int err = NO_ERROR;
4195  DB_TYPE type;
4196  DB_DATETIMETZ *dt_tz1_p;
4197  DB_DATETIME *datetime1_p;
4198 
4199  dt_tz1_p = db_get_datetimetz (dt_tz_val_p);
4200  datetime1_p = &(dt_tz1_p->datetime);
4201  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
4202 
4203  switch (type)
4204  {
4205  case DB_TYPE_SHORT:
4206  case DB_TYPE_INTEGER:
4207  case DB_TYPE_BIGINT:
4208  {
4209  DB_VALUE dt_val, dt_val_res;
4210  DB_DATETIMETZ dt_tz, dt_tz_fixed;
4211 
4212  db_make_datetime (&dt_val, datetime1_p);
4213 
4214  err =
4215  qdata_subtract_datetime_to_dbval (&dt_val, dbval_p, &dt_val_res,
4217  if (err != NO_ERROR)
4218  {
4219  break;
4220  }
4221 
4222  dt_tz.datetime = *db_get_datetime (&dt_val_res);
4223  dt_tz.tz_id = dt_tz1_p->tz_id;
4224 
4225  err = tz_datetimetz_fix_zone (&dt_tz, &dt_tz_fixed);
4226  if (err != NO_ERROR)
4227  {
4228  break;
4229  }
4230 
4231  db_make_datetimetz (result_p, &dt_tz_fixed);
4232  break;
4233  }
4234 
4235  case DB_TYPE_TIMESTAMP:
4236  case DB_TYPE_TIMESTAMPLTZ:
4237  case DB_TYPE_TIMESTAMPTZ:
4238  {
4239  DB_BIGINT u1, u2;
4240  DB_DATETIME datetime2;
4241  DB_UTIME *utime2_p;
4242 
4243  /* create a DATETIME in UTC reference */
4244  if (type == DB_TYPE_TIMESTAMPTZ)
4245  {
4246  DB_TIMESTAMPTZ *ts_tz2_p;
4247 
4248  ts_tz2_p = db_get_timestamptz (dbval_p);
4249  utime2_p = &(ts_tz2_p->timestamp);
4250  }
4251  else
4252  {
4253  utime2_p = db_get_timestamp (dbval_p);
4254  }
4255  (void) db_timestamp_decode_utc (utime2_p, &datetime2.date, &datetime2.time);
4256 
4257  u1 = ((DB_BIGINT) dt_tz1_p->datetime.date) * MILLISECONDS_OF_ONE_DAY + dt_tz1_p->datetime.time;
4258  u2 = ((DB_BIGINT) datetime2.date) * MILLISECONDS_OF_ONE_DAY + datetime2.time;
4259 
4260  return db_make_bigint (result_p, u1 - u2);
4261  }
4262 
4263  case DB_TYPE_DATETIME:
4264  {
4265  DB_BIGINT u1, u2;
4266  DB_DATETIME *datetime2_p;
4267  DB_DATETIME datetime1;
4268 
4269  /* from DT with TZ to local */
4270  datetime2_p = db_get_datetime (dbval_p);
4271 
4272  err = tz_utc_datetimetz_to_local (&dt_tz1_p->datetime, &dt_tz1_p->tz_id, &datetime1);
4273  if (err != NO_ERROR)
4274  {
4275  return err;
4276  }
4277 
4278  u1 = ((DB_BIGINT) datetime1.date) * MILLISECONDS_OF_ONE_DAY + datetime1.time;
4279  u2 = ((DB_BIGINT) datetime2_p->date) * MILLISECONDS_OF_ONE_DAY + datetime2_p->time;
4280 
4281  return db_make_bigint (result_p, u1 - u2);
4282  }
4283 
4284  case DB_TYPE_DATETIMETZ:
4285  case DB_TYPE_DATETIMELTZ:
4286  {
4287  DB_BIGINT u1, u2;
4288  DB_DATETIMETZ *dt_tz2_p;
4289  DB_DATETIME *datetime2_p;
4290 
4291  /* both datetimes are in UTC, no need to consider timezones */
4292  if (type == DB_TYPE_DATETIMETZ)
4293  {
4294  dt_tz2_p = db_get_datetimetz (dbval_p);
4295  datetime2_p = &(dt_tz2_p->datetime);
4296  }
4297  else
4298  {
4299  datetime2_p = db_get_datetime (dbval_p);
4300  }
4301 
4302  u1 = ((DB_BIGINT) datetime1_p->date) * MILLISECONDS_OF_ONE_DAY + datetime1_p->time;
4303  u2 = ((DB_BIGINT) datetime2_p->date) * MILLISECONDS_OF_ONE_DAY + datetime2_p->time;
4304 
4305  return db_make_bigint (result_p, u1 - u2);
4306  }
4307 
4308  case DB_TYPE_DATE:
4309  {
4310  DB_BIGINT u1, u2;
4311  DB_DATETIME *datetime2_p;
4312  DB_DATETIME datetime1;
4313 
4314  /* from DT with TZ to local */
4315  datetime2_p = db_get_datetime (dbval_p);
4316 
4317  err = tz_utc_datetimetz_to_local (&dt_tz1_p->datetime, &dt_tz1_p->tz_id, &datetime1);
4318  if (err != NO_ERROR)
4319  {
4320  return err;
4321  }
4322 
4323  u1 = ((DB_BIGINT) datetime1.date) * MILLISECONDS_OF_ONE_DAY + datetime1.time;
4324  u2 = ((DB_BIGINT) * db_get_date (dbval_p)) * MILLISECONDS_OF_ONE_DAY;
4325 
4326  return db_make_bigint (result_p, u1 - u2);
4327  }
4328 
4329  default:
4330  break;
4331  }
4332 
4333  return err;
4334 }
4335 
4336 static int
4337 qdata_subtract_date_to_dbval (DB_VALUE * date_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
4338 {
4339  DB_TYPE type;
4340  DB_DATE *date, *date1;
4341  unsigned int u1, u2, utmp;
4342  short s2;
4343  int i2;
4344  DB_BIGINT bi1, bi2, bitmp;
4345  int day, month, year;
4346 
4347  date = db_get_date (date_val_p);
4348  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
4349 
4350  switch (type)
4351  {
4352  case DB_TYPE_SHORT:
4353  u1 = (unsigned int) *date;
4354  s2 = db_get_short (dbval_p);
4355 
4356  if (s2 < 0)
4357  {
4358  /* We're really adding. */
4359  return qdata_subtract_utime_to_short_asymmetry (date_val_p, s2, date, result_p, domain_p);
4360  }
4361 
4362  u2 = (unsigned int) s2;
4363  utmp = u1 - u2;
4364  if (OR_CHECK_UNS_SUB_UNDERFLOW (u1, u2, utmp) || utmp < DB_DATE_MIN)
4365  {
4367  return ER_QPROC_DATE_UNDERFLOW;
4368  }
4369 
4370  db_date_decode (&utmp, &month, &day, &year);
4371  db_make_date (result_p, month, day, year);
4372  break;
4373 
4374  case DB_TYPE_BIGINT:
4375  bi1 = (DB_BIGINT) * date;
4376  bi2 = db_get_bigint (dbval_p);
4377 
4378  if (bi2 < 0)
4379  {
4380  /* We're really adding. */
4381  return qdata_subtract_utime_to_bigint_asymmetry (date_val_p, bi2, date, result_p, domain_p);
4382  }
4383 
4384  bitmp = bi1 - bi2;
4385  if (OR_CHECK_SUB_UNDERFLOW (bi1, bi2, bitmp) || OR_CHECK_UINT_OVERFLOW (bitmp) || bitmp < DB_DATE_MIN)
4386  {
4388  return ER_FAILED;
4389  }
4390 
4391  utmp = (unsigned int) bitmp;
4392  db_date_decode (&utmp, &month, &day, &year);
4393  db_make_date (result_p, month, day, year);
4394  break;
4395 
4396  case DB_TYPE_INTEGER:
4397  u1 = (unsigned int) *date;
4398  i2 = db_get_int (dbval_p);
4399 
4400  if (i2 < 0)
4401  {
4402  /* We're really adding. */
4403  return qdata_subtract_utime_to_int_asymmetry (date_val_p, i2, date, result_p, domain_p);
4404  }
4405 
4406  u2 = (unsigned int) i2;
4407  utmp = u1 - u2;
4408  if (OR_CHECK_UNS_SUB_UNDERFLOW (u1, u2, utmp) || utmp < DB_DATE_MIN)
4409  {
4411  return ER_QPROC_DATE_UNDERFLOW;
4412  }
4413 
4414  db_date_decode (&utmp, &month, &day, &year);
4415  db_make_date (result_p, month, day, year);
4416  break;
4417 
4418  case DB_TYPE_DATE:
4419  date1 = db_get_date (dbval_p);
4420  db_make_int (result_p, (int) *date - (int) *date1);
4421  break;
4422 
4423  default:
4424  break;
4425  }
4426 
4427  return NO_ERROR;
4428 }
4429 
4430 /*
4431  * qdata_subtract_dbval () -
4432  * return: NO_ERROR, or ER_code
4433  * dbval1(in) : First db_value node
4434  * dbval2(in) : Second db_value node
4435  * res(out) : Resultant db_value node
4436  * domain(in) :
4437  *
4438  * Note: Subtract dbval2 value from dbval1 value.
4439  * Overflow checks are only done when both operand maximums have
4440  * overlapping precision/scale. That is,
4441  * short - integer -> overflow is checked
4442  * float - double -> overflow is not checked. Maximum float
4443  * value does not overlap maximum double
4444  * precision/scale.
4445  * MAX_FLT - MAX_DBL = -MAX_DBL
4446  */
4447 int
4448 qdata_subtract_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
4449 {
4450  DB_TYPE type1;
4451  DB_TYPE type2;
4452  int error = NO_ERROR;
4453  DB_VALUE cast_value1;
4454  DB_VALUE cast_value2;
4455  TP_DOMAIN *cast_dom1 = NULL;
4456  TP_DOMAIN *cast_dom2 = NULL;
4457  TP_DOMAIN_STATUS dom_status;
4458 
4459  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
4460  {
4461  return NO_ERROR;
4462  }
4463 
4464  db_make_null (&cast_value1);
4465  db_make_null (&cast_value2);
4466 
4467  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
4468  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
4469 
4470  if (type1 == DB_TYPE_ENUMERATION)
4471  {
4472  /* The enumeration will always be casted to SMALLINT */
4474  dom_status = tp_value_auto_cast (dbval1_p, &cast_value1, cast_dom1);
4475  if (dom_status != DOMAIN_COMPATIBLE)
4476  {
4477  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval1_p, cast_dom1);
4478  return error;
4479  }
4480  return qdata_subtract_dbval (&cast_value1, dbval2_p, result_p, domain_p);
4481  }
4482  else if (type2 == DB_TYPE_ENUMERATION)
4483  {
4485  dom_status = tp_value_auto_cast (dbval2_p, &cast_value2, cast_dom2);
4486  if (dom_status != DOMAIN_COMPATIBLE)
4487  {
4488  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval2_p, cast_dom2);
4489  return error;
4490  }
4491  return qdata_subtract_dbval (dbval1_p, &cast_value2, result_p, domain_p);
4492  }
4493 
4494  /* number - string : cast string to number, substract as numbers */
4495  if (TP_IS_NUMERIC_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
4496  {
4497  /* cast string to double */
4499  }
4500  /* string - number: cast string to number, substract as numbers */
4501  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_NUMERIC_TYPE (type2))
4502  {
4503  /* cast string to double */
4505  }
4506  /* string - string: cast string to number, substract as numbers */
4507  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
4508  {
4509  /* cast string to double */
4512  }
4513  /* date - number : cast floating point number to bigint, date - bigint = date */
4514  else if (TP_IS_DATE_OR_TIME_TYPE (type1) && TP_IS_FLOATING_NUMBER_TYPE (type2))
4515  {
4516  /* cast number to BIGINT */
4518  }
4519  /* number - date: cast floating point number to bigint, bigint - date= date */
4520  else if (TP_IS_FLOATING_NUMBER_TYPE (type1) && TP_IS_DATE_OR_TIME_TYPE (type2))
4521  {
4522  /* cast number to BIGINT */
4524  }
4525  /* TIME - string : cast string to TIME , date - TIME = bigint */
4526  /* DATE - string : cast string to DATETIME, the other operand to DATETIME DATETIME - DATETIME = bigint */
4527  else if (TP_IS_DATE_OR_TIME_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
4528  {
4529  if (type1 == DB_TYPE_TIME)
4530  {
4532  }
4533  else
4534  {
4536 
4537  if (type1 != DB_TYPE_DATETIME)
4538  {
4540  }
4541  }
4542  }
4543  /* string - TIME : cast string to TIME, TIME - TIME = bigint */
4544  /* string - DATE : cast string to DATETIME, the other operand to DATETIME DATETIME - DATETIME = bigint */
4545  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_DATE_OR_TIME_TYPE (type2))
4546  {
4547  if (type2 == DB_TYPE_TIME)
4548  {
4550  }
4551  else
4552  {
4553  /* cast string to same 'date' */
4555  if (type2 != DB_TYPE_DATETIME)
4556  {
4558  }
4559  }
4560  }
4561 
4562  if (cast_dom1 != NULL)
4563  {
4564  dom_status = tp_value_auto_cast (dbval1_p, &cast_value1, cast_dom1);
4565  if (dom_status != DOMAIN_COMPATIBLE)
4566  {
4567  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval1_p, cast_dom1);
4568  return error;
4569  }
4570  dbval1_p = &cast_value1;
4571  }
4572 
4573  if (cast_dom2 != NULL)
4574  {
4575  dom_status = tp_value_auto_cast (dbval2_p, &cast_value2, cast_dom2);
4576  if (dom_status != DOMAIN_COMPATIBLE)
4577  {
4578  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval2_p, cast_dom2);
4579  return error;
4580  }
4581  dbval2_p = &cast_value2;
4582  }
4583 
4584  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
4585  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
4586 
4587  if (DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
4588  {
4589  return NO_ERROR;
4590  }
4591 
4592  if (qdata_is_zero_value_date (dbval1_p) || qdata_is_zero_value_date (dbval2_p))
4593  {
4594  /* subtract operation with zero date returns null */
4595  db_make_null (result_p);
4597  {
4600  }
4601  return NO_ERROR;
4602  }
4603 
4604  switch (type1)
4605  {
4606  case DB_TYPE_SHORT:
4607  error = qdata_subtract_short_to_dbval (dbval1_p, dbval2_p, result_p);
4608  break;
4609 
4610  case DB_TYPE_BIGINT:
4611  error = qdata_subtract_bigint_to_dbval (dbval1_p, dbval2_p, result_p);
4612  break;
4613 
4614  case DB_TYPE_INTEGER:
4615  error = qdata_subtract_int_to_dbval (dbval1_p, dbval2_p, result_p);
4616  break;
4617 
4618  case DB_TYPE_FLOAT:
4619  error = qdata_subtract_float_to_dbval (dbval1_p, dbval2_p, result_p);
4620  break;
4621 
4622  case DB_TYPE_DOUBLE:
4623  error = qdata_subtract_double_to_dbval (dbval1_p, dbval2_p, result_p);
4624  break;
4625 
4626  case DB_TYPE_NUMERIC:
4627  error = qdata_subtract_numeric_to_dbval (dbval1_p, dbval2_p, result_p);
4628  break;
4629 
4630  case DB_TYPE_MONETARY:
4631  error = qdata_subtract_monetary_to_dbval (dbval1_p, dbval2_p, result_p);
4632  break;
4633 
4634  case DB_TYPE_SET:
4635  case DB_TYPE_MULTISET:
4636  case DB_TYPE_SEQUENCE:
4637  if (!TP_IS_SET_TYPE (type2))
4638  {
4641  }
4642  if (domain_p == NULL)
4643  {
4644  if (type1 == type2 && type1 == DB_TYPE_SET)
4645  {
4646  /* partial resolve : set only basic domain; full domain will be resolved in 'fetch', based on the
4647  * result's value */
4648  domain_p = tp_domain_resolve_default (type1);
4649  }
4650  else
4651  {
4653  }
4654  }
4655  error = qdata_subtract_sequence_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
4656  break;
4657 
4658  case DB_TYPE_TIME:
4659  error = qdata_subtract_time_to_dbval (dbval1_p, dbval2_p, result_p);
4660  break;
4661 
4662  case DB_TYPE_TIMESTAMP:
4663  error = qdata_subtract_utime_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
4664  break;
4665 
4666  case DB_TYPE_TIMESTAMPLTZ:
4667  error = qdata_subtract_timestampltz_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
4668  break;
4669 
4670  case DB_TYPE_TIMESTAMPTZ:
4671  error = qdata_subtract_timestamptz_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
4672  break;
4673 
4674  case DB_TYPE_DATETIME:
4675  error = qdata_subtract_datetime_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
4676  break;
4677 
4678  case DB_TYPE_DATETIMELTZ:
4679  {
4680  /* create a datetime with TZ using session timezone */
4681  DB_VALUE tmp_val;
4682  DB_DATETIMETZ dt_tz1;
4683 
4684  dt_tz1.datetime = *db_get_datetime (dbval1_p);
4685  error = tz_create_session_tzid_for_datetime (&dt_tz1.datetime, true, &dt_tz1.tz_id);
4686  if (error != NO_ERROR)
4687  {
4688  break;
4689  }
4690 
4691  db_make_datetimetz (&tmp_val, &dt_tz1);
4692 
4693  error = qdata_subtract_datetimetz_to_dbval (&tmp_val, dbval2_p, result_p, domain_p);
4694  }
4695  break;
4696 
4697  case DB_TYPE_DATETIMETZ:
4698  error = qdata_subtract_datetimetz_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
4699  break;
4700 
4701  case DB_TYPE_DATE:
4702  error = qdata_subtract_date_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
4703  break;
4704 
4705  case DB_TYPE_STRING:
4706  default:
4708  {
4711  }
4712  }
4713 
4714  if (error != NO_ERROR)
4715  {
4716  return error;
4717  }
4718 
4719  return qdata_coerce_result_to_domain (result_p, domain_p);
4720 }
4721 
4722 static int
4723 qdata_multiply_short (DB_VALUE * short_val_p, short s2, DB_VALUE * result_p)
4724 {
4725  /* NOTE that we need volatile to prevent optimizer from generating division expression as multiplication */
4726  volatile short s1, stmp;
4727 
4728  s1 = db_get_short (short_val_p);
4729  stmp = s1 * s2;
4730 
4731  if (OR_CHECK_MULT_OVERFLOW (s1, s2, stmp))
4732  {
4734  return ER_FAILED;
4735  }
4736 
4737  db_make_short (result_p, stmp);
4738 
4739  return NO_ERROR;
4740 }
4741 
4742 static int
4743 qdata_multiply_int (DB_VALUE * int_val_p, int i2, DB_VALUE * result_p)
4744 {
4745  /* NOTE that we need volatile to prevent optimizer from generating division expression as multiplication */
4746  volatile int i1, itmp;
4747 
4748  i1 = db_get_int (int_val_p);
4749  itmp = i1 * i2;
4750 
4751  if (OR_CHECK_MULT_OVERFLOW (i1, i2, itmp))
4752  {
4754  return ER_FAILED;
4755  }
4756 
4757  db_make_int (result_p, itmp);
4758  return NO_ERROR;
4759 }
4760 
4761 static int
4762 qdata_multiply_bigint (DB_VALUE * bigint_val_p, DB_BIGINT bi2, DB_VALUE * result_p)
4763 {
4764  /* NOTE that we need volatile to prevent optimizer from generating division expression as multiplication */
4765  volatile DB_BIGINT bi1, bitmp;
4766 
4767  bi1 = db_get_bigint (bigint_val_p);
4768  bitmp = bi1 * bi2;
4769 
4770  if (OR_CHECK_MULT_OVERFLOW (bi1, bi2, bitmp))
4771  {
4773  return ER_FAILED;
4774  }
4775 
4776  db_make_bigint (result_p, bitmp);
4777  return NO_ERROR;
4778 }
4779 
4780 static int
4781 qdata_multiply_float (DB_VALUE * float_val_p, float f2, DB_VALUE * result_p)
4782 {
4783  float f1, ftmp;
4784 
4785  f1 = db_get_float (float_val_p);
4786  ftmp = f1 * f2;
4787 
4788  if (OR_CHECK_FLOAT_OVERFLOW (ftmp))
4789  {
4791  return ER_FAILED;
4792  }
4793 
4794  db_make_float (result_p, ftmp);
4795  return NO_ERROR;
4796 }
4797 
4798 static int
4799 qdata_multiply_double (double d1, double d2, DB_VALUE * result_p)
4800 {
4801  double dtmp;
4802 
4803  dtmp = d1 * d2;
4804 
4805  if (OR_CHECK_DOUBLE_OVERFLOW (dtmp))
4806  {
4808  return ER_FAILED;
4809  }
4810 
4811  db_make_double (result_p, dtmp);
4812  return NO_ERROR;
4813 }
4814 
4815 static int
4816 qdata_multiply_numeric (DB_VALUE * numeric_val_p, DB_VALUE * dbval, DB_VALUE * result_p)
4817 {
4818  DB_VALUE dbval_tmp;
4819 
4820  qdata_coerce_dbval_to_numeric (dbval, &dbval_tmp);
4821 
4822  if (numeric_db_value_mul (numeric_val_p, &dbval_tmp, result_p) != NO_ERROR)
4823  {
4825  return ER_FAILED;
4826  }
4827 
4828  return NO_ERROR;
4829 }
4830 
4831 static int
4832 qdata_multiply_monetary (DB_VALUE * monetary_val_p, double d, DB_VALUE * result_p)
4833 {
4834  double dtmp;
4835 
4836  dtmp = (db_get_monetary (monetary_val_p))->amount * d;
4837 
4838  if (OR_CHECK_DOUBLE_OVERFLOW (dtmp))
4839  {
4841  return ER_FAILED;
4842  }
4843 
4844  db_make_monetary (result_p, (db_get_monetary (monetary_val_p))->type, dtmp);
4845 
4846  return NO_ERROR;
4847 }
4848 
4849 static int
4850 qdata_multiply_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
4851 {
4852  short s;
4853  DB_TYPE type2;
4854 
4855  s = db_get_short (short_val_p);
4856  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
4857 
4858  switch (type2)
4859  {
4860  case DB_TYPE_SHORT:
4861  return qdata_multiply_short (dbval_p, s, result_p);
4862 
4863  case DB_TYPE_BIGINT:
4864  return qdata_multiply_bigint (dbval_p, s, result_p);
4865 
4866  case DB_TYPE_INTEGER:
4867  return qdata_multiply_int (dbval_p, s, result_p);
4868 
4869  case DB_TYPE_FLOAT:
4870  return qdata_multiply_float (dbval_p, s, result_p);
4871 
4872  case DB_TYPE_DOUBLE:
4873  return qdata_multiply_double (db_get_double (dbval_p), s, result_p);
4874 
4875  case DB_TYPE_NUMERIC:
4876  return qdata_multiply_numeric (dbval_p, short_val_p, result_p);
4877 
4878  case DB_TYPE_MONETARY:
4879  return qdata_multiply_monetary (dbval_p, s, result_p);
4880 
4881  default:
4882  break;
4883  }
4884 
4885  return NO_ERROR;
4886 }
4887 
4888 static int
4889 qdata_multiply_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
4890 {
4891  DB_TYPE type2;
4892 
4893  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
4894 
4895  switch (type2)
4896  {
4897  case DB_TYPE_SHORT:
4898  return qdata_multiply_int (int_val_p, db_get_short (dbval_p), result_p);
4899 
4900  case DB_TYPE_INTEGER:
4901  return qdata_multiply_int (int_val_p, db_get_int (dbval_p), result_p);
4902 
4903  case DB_TYPE_BIGINT:
4904  return qdata_multiply_bigint (dbval_p, db_get_int (int_val_p), result_p);
4905 
4906  case DB_TYPE_FLOAT:
4907  return qdata_multiply_float (dbval_p, (float) db_get_int (int_val_p), result_p);
4908 
4909  case DB_TYPE_DOUBLE:
4910  return qdata_multiply_double (db_get_double (dbval_p), db_get_int (int_val_p), result_p);
4911 
4912  case DB_TYPE_NUMERIC:
4913  return qdata_multiply_numeric (dbval_p, int_val_p, result_p);
4914 
4915  case DB_TYPE_MONETARY:
4916  return qdata_multiply_monetary (dbval_p, db_get_int (int_val_p), result_p);
4917 
4918  default:
4919  break;
4920  }
4921 
4922  return NO_ERROR;
4923 }
4924 
4925 static int
4926 qdata_multiply_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
4927 {
4928  DB_TYPE type2;
4929 
4930  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
4931 
4932  switch (type2)
4933  {
4934  case DB_TYPE_SHORT:
4935  return qdata_multiply_bigint (bigint_val_p, db_get_short (dbval_p), result_p);
4936 
4937  case DB_TYPE_INTEGER:
4938  return qdata_multiply_bigint (bigint_val_p, db_get_int (dbval_p), result_p);
4939 
4940  case DB_TYPE_BIGINT:
4941  return qdata_multiply_bigint (bigint_val_p, db_get_bigint (dbval_p), result_p);
4942 
4943  case DB_TYPE_FLOAT:
4944  return qdata_multiply_float (dbval_p, (float) db_get_bigint (bigint_val_p), result_p);
4945 
4946  case DB_TYPE_DOUBLE:
4947  return qdata_multiply_double (db_get_double (dbval_p), (double) db_get_bigint (bigint_val_p), result_p);
4948 
4949  case DB_TYPE_NUMERIC:
4950  return qdata_multiply_numeric (dbval_p, bigint_val_p, result_p);
4951 
4952  case DB_TYPE_MONETARY:
4953  return qdata_multiply_monetary (dbval_p, (double) db_get_bigint (bigint_val_p), result_p);
4954 
4955  default:
4956  break;
4957  }
4958 
4959  return NO_ERROR;
4960 }
4961 
4962 static int
4963 qdata_multiply_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
4964 {
4965  DB_TYPE type2;
4966 
4967  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
4968 
4969  switch (type2)
4970  {
4971  case DB_TYPE_SHORT:
4972  return qdata_multiply_float (float_val_p, db_get_short (dbval_p), result_p);
4973 
4974  case DB_TYPE_INTEGER:
4975  return qdata_multiply_float (float_val_p, (float) db_get_int (dbval_p), result_p);
4976 
4977  case DB_TYPE_BIGINT:
4978  return qdata_multiply_float (float_val_p, (float) db_get_bigint (dbval_p), result_p);
4979 
4980  case DB_TYPE_FLOAT:
4981  return qdata_multiply_float (float_val_p, db_get_float (dbval_p), result_p);
4982 
4983  case DB_TYPE_DOUBLE:
4984  return qdata_multiply_double (db_get_float (float_val_p), db_get_double (dbval_p), result_p);
4985 
4986  case DB_TYPE_NUMERIC:
4987  return qdata_multiply_double (db_get_float (float_val_p), qdata_coerce_numeric_to_double (dbval_p), result_p);
4988 
4989  case DB_TYPE_MONETARY:
4990  return qdata_multiply_monetary (dbval_p, db_get_float (float_val_p), result_p);
4991 
4992  default:
4993  break;
4994  }
4995 
4996  return NO_ERROR;
4997 }
4998 
4999 static int
5000 qdata_multiply_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5001 {
5002  double d;
5003  DB_TYPE type2;
5004 
5005  d = db_get_double (double_val_p);
5006  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5007 
5008  switch (type2)
5009 
5010  {
5011  case DB_TYPE_SHORT:
5012  return qdata_multiply_double (d, db_get_short (dbval_p), result_p);
5013 
5014  case DB_TYPE_INTEGER:
5015  return qdata_multiply_double (d, db_get_int (dbval_p), result_p);
5016 
5017  case DB_TYPE_BIGINT:
5018  return qdata_multiply_double (d, (double) db_get_bigint (dbval_p), result_p);
5019 
5020  case DB_TYPE_FLOAT:
5021  return qdata_multiply_double (d, db_get_float (dbval_p), result_p);
5022 
5023  case DB_TYPE_DOUBLE:
5024  return qdata_multiply_double (d, db_get_double (dbval_p), result_p);
5025 
5026  case DB_TYPE_NUMERIC:
5027  return qdata_multiply_double (d, qdata_coerce_numeric_to_double (dbval_p), result_p);
5028 
5029  case DB_TYPE_MONETARY:
5030  return qdata_multiply_monetary (dbval_p, d, result_p);
5031 
5032  default:
5033  break;
5034  }
5035 
5036  return NO_ERROR;
5037 }
5038 
5039 static int
5040 qdata_multiply_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5041 {
5042  DB_TYPE type2;
5043 
5044  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5045 
5046  switch (type2)
5047  {
5048  case DB_TYPE_SHORT:
5049  case DB_TYPE_INTEGER:
5050  case DB_TYPE_BIGINT:
5051  return qdata_multiply_numeric (numeric_val_p, dbval_p, result_p);
5052 
5053  case DB_TYPE_NUMERIC:
5054  if (numeric_db_value_mul (numeric_val_p, dbval_p, result_p) != NO_ERROR)
5055  {
5057  return ER_FAILED;
5058  }
5059  break;
5060 
5061  case DB_TYPE_FLOAT:
5062  return qdata_multiply_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_float (dbval_p), result_p);
5063 
5064  case DB_TYPE_DOUBLE:
5065  return qdata_multiply_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_double (dbval_p), result_p);
5066 
5067  case DB_TYPE_MONETARY:
5068  return qdata_multiply_monetary (dbval_p, qdata_coerce_numeric_to_double (numeric_val_p), result_p);
5069 
5070  default:
5071  break;
5072  }
5073 
5074  return NO_ERROR;
5075 }
5076 
5077 static int
5078 qdata_multiply_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5079 {
5080  DB_TYPE type2;
5081 
5082  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5083 
5084  switch (type2)
5085  {
5086  case DB_TYPE_SHORT:
5087  return qdata_multiply_monetary (monetary_val_p, db_get_short (dbval_p), result_p);
5088 
5089  case DB_TYPE_INTEGER:
5090  return qdata_multiply_monetary (monetary_val_p, db_get_int (dbval_p), result_p);
5091 
5092  case DB_TYPE_BIGINT:
5093  return qdata_multiply_monetary (monetary_val_p, (double) db_get_bigint (dbval_p), result_p);
5094 
5095  case DB_TYPE_FLOAT:
5096  return qdata_multiply_monetary (monetary_val_p, db_get_float (dbval_p), result_p);
5097 
5098  case DB_TYPE_DOUBLE:
5099  return qdata_multiply_monetary (monetary_val_p, db_get_double (dbval_p), result_p);
5100 
5101  case DB_TYPE_NUMERIC:
5102  return qdata_multiply_monetary (monetary_val_p, qdata_coerce_numeric_to_double (dbval_p), result_p);
5103 
5104  case DB_TYPE_MONETARY:
5105  /* Note: we probably should return an error if the two monetaries have different montetary types. */
5106  return qdata_multiply_monetary (monetary_val_p, (db_get_monetary (dbval_p))->amount, result_p);
5107 
5108  default:
5109  break;
5110  }
5111 
5112  return NO_ERROR;
5113 }
5114 
5115 static int
5116 qdata_multiply_sequence_to_dbval (DB_VALUE * seq_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p, TP_DOMAIN * domain_p)
5117 {
5118  DB_SET *set_tmp = NULL;
5119 #if !defined(NDEBUG)
5120  DB_TYPE type1, type2;
5121 #endif
5122 
5123 #if !defined(NDEBUG)
5124  type1 = DB_VALUE_DOMAIN_TYPE (seq_val_p);
5125  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5126 
5127  assert (TP_IS_SET_TYPE (type1));
5128  assert (TP_IS_SET_TYPE (type2));
5129 #endif
5130 
5131  if (set_intersection (db_get_set (seq_val_p), db_get_set (dbval_p), &set_tmp, domain_p) < 0)
5132  {
5133  return ER_FAILED;
5134  }
5135 
5136  set_make_collection (result_p, set_tmp);
5137  return NO_ERROR;
5138 }
5139 
5140 /*
5141  * qdata_multiply_dbval () -
5142  * return: NO_ERROR, or ER_code
5143  * dbval1(in) : First db_value node
5144  * dbval2(in) : Second db_value node
5145  * res(out) : Resultant db_value node
5146  * domain(in) :
5147  *
5148  * Note: Multiply two db_values.
5149  */
5150 int
5151 qdata_multiply_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
5152 {
5153  DB_TYPE type1;
5154  DB_TYPE type2;
5155  int error = NO_ERROR;
5156  DB_VALUE cast_value1;
5157  DB_VALUE cast_value2;
5158  TP_DOMAIN *cast_dom1 = NULL;
5159  TP_DOMAIN *cast_dom2 = NULL;
5160  TP_DOMAIN_STATUS dom_status;
5161 
5162  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
5163  {
5164  return NO_ERROR;
5165  }
5166 
5167  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
5168  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
5169 
5170  db_make_null (&cast_value1);
5171  db_make_null (&cast_value2);
5172 
5173  /* number * string : cast string to DOUBLE, multiply as number * DOUBLE */
5174  if (TP_IS_NUMERIC_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
5175  {
5176  /* cast arg2 to double */
5178  }
5179  /* string * number: cast string to DOUBLE, multiply as DOUBLE * number */
5180  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_NUMERIC_TYPE (type2))
5181  {
5182  /* cast arg1 to double */
5184  }
5185  /* string * string: cast both to DOUBLE, multiply as DOUBLE * DOUBLE */
5186  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
5187  {
5188  /* cast number to DOUBLE */
5191  }
5192 
5193  if (cast_dom2 != NULL)
5194  {
5195  dom_status = tp_value_auto_cast (dbval2_p, &cast_value2, cast_dom2);
5196  if (dom_status != DOMAIN_COMPATIBLE)
5197  {
5198  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval2_p, cast_dom2);
5199  return error;
5200  }
5201  dbval2_p = &cast_value2;
5202  }
5203 
5204  if (cast_dom1 != NULL)
5205  {
5206  dom_status = tp_value_auto_cast (dbval1_p, &cast_value1, cast_dom1);
5207  if (dom_status != DOMAIN_COMPATIBLE)
5208  {
5209  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval1_p, cast_dom1);
5210  return error;
5211  }
5212  dbval1_p = &cast_value1;
5213  }
5214 
5215  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
5216  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
5217 
5218  if (DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
5219  {
5220  return NO_ERROR;
5221  }
5222 
5223  switch (type1)
5224  {
5225  case DB_TYPE_SHORT:
5226  error = qdata_multiply_short_to_dbval (dbval1_p, dbval2_p, result_p);
5227  break;
5228 
5229  case DB_TYPE_INTEGER:
5230  error = qdata_multiply_int_to_dbval (dbval1_p, dbval2_p, result_p);
5231  break;
5232 
5233  case DB_TYPE_BIGINT:
5234  error = qdata_multiply_bigint_to_dbval (dbval1_p, dbval2_p, result_p);
5235  break;
5236 
5237  case DB_TYPE_FLOAT:
5238  error = qdata_multiply_float_to_dbval (dbval1_p, dbval2_p, result_p);
5239  break;
5240 
5241  case DB_TYPE_DOUBLE:
5242  error = qdata_multiply_double_to_dbval (dbval1_p, dbval2_p, result_p);
5243  break;
5244 
5245  case DB_TYPE_NUMERIC:
5246  error = qdata_multiply_numeric_to_dbval (dbval1_p, dbval2_p, result_p);
5247  break;
5248 
5249  case DB_TYPE_MONETARY:
5250  error = qdata_multiply_monetary_to_dbval (dbval1_p, dbval2_p, result_p);
5251  break;
5252 
5253  case DB_TYPE_SET:
5254  case DB_TYPE_MULTISET:
5255  case DB_TYPE_SEQUENCE:
5256  if (!TP_IS_SET_TYPE (type2))
5257  {
5260  }
5261  if (domain_p == NULL)
5262  {
5263  if (type1 == type2 && type1 == DB_TYPE_SET)
5264  {
5265  /* partial resolve : set only basic domain; full domain will be resolved in 'fetch', based on the
5266  * result's value */
5267  domain_p = tp_domain_resolve_default (type1);
5268  }
5269  else
5270  {
5272  }
5273  }
5274  error = qdata_multiply_sequence_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
5275  break;
5276 
5277  case DB_TYPE_TIME:
5278  case DB_TYPE_TIMESTAMP:
5279  case DB_TYPE_TIMESTAMPLTZ:
5280  case DB_TYPE_TIMESTAMPTZ:
5281  case DB_TYPE_DATE:
5282  case DB_TYPE_DATETIME:
5283  case DB_TYPE_DATETIMELTZ:
5284  case DB_TYPE_DATETIMETZ:
5285  case DB_TYPE_STRING:
5286  default:
5288  {
5291  }
5292  }
5293 
5294  if (error != NO_ERROR)
5295  {
5296  return error;
5297  }
5298 
5299  return qdata_coerce_result_to_domain (result_p, domain_p);
5300 }
5301 
5302 static bool
5304 {
5305  DB_TYPE type;
5306 
5307  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
5308 
5309  switch (type)
5310  {
5311  case DB_TYPE_SHORT:
5312  return db_get_short (dbval_p) == 0;
5313 
5314  case DB_TYPE_INTEGER:
5315  return db_get_int (dbval_p) == 0;
5316 
5317  case DB_TYPE_BIGINT:
5318  return db_get_bigint (dbval_p) == 0;
5319 
5320  case DB_TYPE_FLOAT:
5321  return fabs ((double) db_get_float (dbval_p)) <= DBL_EPSILON;
5322 
5323  case DB_TYPE_DOUBLE:
5324  return fabs (db_get_double (dbval_p)) <= DBL_EPSILON;
5325 
5326  case DB_TYPE_MONETARY:
5327  return db_get_monetary (dbval_p)->amount <= DBL_EPSILON;
5328 
5329  case DB_TYPE_NUMERIC:
5330  return numeric_db_value_is_zero (dbval_p);
5331 
5332  default:
5333  break;
5334  }
5335 
5336  return false;
5337 }
5338 
5339 static int
5340 qdata_divide_short (short s1, short s2, DB_VALUE * result_p)
5341 {
5342  short stmp;
5343 
5344  stmp = s1 / s2;
5345  db_make_short (result_p, stmp);
5346 
5347  return NO_ERROR;
5348 }
5349 
5350 static int
5351 qdata_divide_int (int i1, int i2, DB_VALUE * result_p)
5352 {
5353  int itmp;
5354 
5355  itmp = i1 / i2;
5356  db_make_int (result_p, itmp);
5357 
5358  return NO_ERROR;
5359 }
5360 
5361 static int
5363 {
5364  DB_BIGINT bitmp;
5365 
5366  bitmp = bi1 / bi2;
5367  db_make_bigint (result_p, bitmp);
5368 
5369  return NO_ERROR;
5370 }
5371 
5372 static int
5373 qdata_divide_float (float f1, float f2, DB_VALUE * result_p)
5374 {
5375  float ftmp;
5376 
5377  ftmp = f1 / f2;
5378 
5379  if (OR_CHECK_FLOAT_OVERFLOW (ftmp))
5380  {
5382  return ER_FAILED;
5383  }
5384 
5385  db_make_float (result_p, ftmp);
5386  return NO_ERROR;
5387 }
5388 
5389 static int
5390 qdata_divide_double (double d1, double d2, DB_VALUE * result_p, bool is_check_overflow)
5391 {
5392  double dtmp;
5393 
5394  dtmp = d1 / d2;
5395 
5396  if (is_check_overflow && OR_CHECK_DOUBLE_OVERFLOW (dtmp))
5397  {
5399  return ER_FAILED;
5400  }
5401 
5402  db_make_double (result_p, dtmp);
5403  return NO_ERROR;
5404 }
5405 
5406 static int
5407 qdata_divide_monetary (double d1, double d2, DB_CURRENCY currency, DB_VALUE * result_p, bool is_check_overflow)
5408 {
5409  double dtmp;
5410 
5411  dtmp = d1 / d2;
5412 
5413  if (is_check_overflow && OR_CHECK_DOUBLE_OVERFLOW (dtmp))
5414  {
5416  return ER_FAILED;
5417  }
5418 
5419  db_make_monetary (result_p, currency, dtmp);
5420  return NO_ERROR;
5421 }
5422 
5423 static int
5424 qdata_divide_short_to_dbval (DB_VALUE * short_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5425 {
5426  short s;
5427  DB_TYPE type2;
5428  DB_VALUE dbval_tmp;
5429 
5430  s = db_get_short (short_val_p);
5431  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5432 
5433  switch (type2)
5434  {
5435  case DB_TYPE_SHORT:
5436  return qdata_divide_short (s, db_get_short (dbval_p), result_p);
5437 
5438  case DB_TYPE_INTEGER:
5439  return qdata_divide_int (s, db_get_int (dbval_p), result_p);
5440 
5441  case DB_TYPE_BIGINT:
5442  return qdata_divide_bigint (s, db_get_bigint (dbval_p), result_p);
5443 
5444  case DB_TYPE_FLOAT:
5445  return qdata_divide_float (s, db_get_float (dbval_p), result_p);
5446 
5447  case DB_TYPE_DOUBLE:
5448  return qdata_divide_double (s, db_get_double (dbval_p), result_p, true);
5449 
5450  case DB_TYPE_NUMERIC:
5451  qdata_coerce_dbval_to_numeric (short_val_p, &dbval_tmp);
5452  if (numeric_db_value_div (&dbval_tmp, dbval_p, result_p) != NO_ERROR)
5453  {
5455  return ER_FAILED;
5456  }
5457  break;
5458 
5459  case DB_TYPE_MONETARY:
5460  return qdata_divide_monetary (s, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p,
5461  true);
5462 
5463  default:
5464  break;
5465  }
5466 
5467  return NO_ERROR;
5468 }
5469 
5470 static int
5471 qdata_divide_int_to_dbval (DB_VALUE * int_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5472 {
5473  int i;
5474  DB_TYPE type2;
5475  DB_VALUE dbval_tmp;
5476 
5477  i = db_get_int (int_val_p);
5478  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5479 
5480  switch (type2)
5481  {
5482  case DB_TYPE_SHORT:
5483  return qdata_divide_int (i, db_get_short (dbval_p), result_p);
5484 
5485  case DB_TYPE_INTEGER:
5486  return qdata_divide_int (i, db_get_int (dbval_p), result_p);
5487 
5488  case DB_TYPE_BIGINT:
5489  return qdata_divide_bigint (i, db_get_bigint (dbval_p), result_p);
5490 
5491  case DB_TYPE_FLOAT:
5492  return qdata_divide_float ((float) i, db_get_float (dbval_p), result_p);
5493 
5494  case DB_TYPE_DOUBLE:
5495  return qdata_divide_double (i, db_get_double (dbval_p), result_p, true);
5496 
5497  case DB_TYPE_NUMERIC:
5498  qdata_coerce_dbval_to_numeric (int_val_p, &dbval_tmp);
5499  if (numeric_db_value_div (&dbval_tmp, dbval_p, result_p) != NO_ERROR)
5500  {
5502  return ER_FAILED;
5503  }
5504  break;
5505 
5506  case DB_TYPE_MONETARY:
5507  return qdata_divide_monetary (i, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p,
5508  true);
5509 
5510  default:
5511  break;
5512  }
5513 
5514  return NO_ERROR;
5515 }
5516 
5517 static int
5518 qdata_divide_bigint_to_dbval (DB_VALUE * bigint_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5519 {
5520  DB_BIGINT bi;
5521  DB_TYPE type2;
5522  DB_VALUE dbval_tmp;
5523 
5524  bi = db_get_bigint (bigint_val_p);
5525  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5526 
5527  switch (type2)
5528  {
5529  case DB_TYPE_SHORT:
5530  return qdata_divide_bigint (bi, db_get_short (dbval_p), result_p);
5531 
5532  case DB_TYPE_INTEGER:
5533  return qdata_divide_bigint (bi, db_get_int (dbval_p), result_p);
5534 
5535  case DB_TYPE_BIGINT:
5536  return qdata_divide_bigint (bi, db_get_bigint (dbval_p), result_p);
5537 
5538  case DB_TYPE_FLOAT:
5539  return qdata_divide_float ((float) bi, db_get_float (dbval_p), result_p);
5540 
5541  case DB_TYPE_DOUBLE:
5542  return qdata_divide_double ((double) bi, db_get_double (dbval_p), result_p, true);
5543 
5544  case DB_TYPE_NUMERIC:
5545  qdata_coerce_dbval_to_numeric (bigint_val_p, &dbval_tmp);
5546  if (numeric_db_value_div (&dbval_tmp, dbval_p, result_p) != NO_ERROR)
5547  {
5549  return ER_FAILED;
5550  }
5551  break;
5552 
5553  case DB_TYPE_MONETARY:
5554  return qdata_divide_monetary ((double) bi, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type,
5555  result_p, true);
5556 
5557  default:
5558  break;
5559  }
5560 
5561  return NO_ERROR;
5562 }
5563 
5564 static int
5565 qdata_divide_float_to_dbval (DB_VALUE * float_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5566 {
5567  float f;
5568  DB_TYPE type2;
5569 
5570  f = db_get_float (float_val_p);
5571  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5572 
5573  switch (type2)
5574  {
5575  case DB_TYPE_SHORT:
5576  return qdata_divide_float (f, db_get_short (dbval_p), result_p);
5577 
5578  case DB_TYPE_INTEGER:
5579  return qdata_divide_float (f, (float) db_get_int (dbval_p), result_p);
5580 
5581  case DB_TYPE_BIGINT:
5582  return qdata_divide_float (f, (float) db_get_bigint (dbval_p), result_p);
5583 
5584  case DB_TYPE_FLOAT:
5585  return qdata_divide_float (f, db_get_float (dbval_p), result_p);
5586 
5587  case DB_TYPE_DOUBLE:
5588  return qdata_divide_double (f, db_get_double (dbval_p), result_p, true);
5589 
5590  case DB_TYPE_NUMERIC:
5591  return qdata_divide_double (f, qdata_coerce_numeric_to_double (dbval_p), result_p, false);
5592 
5593  case DB_TYPE_MONETARY:
5594  return qdata_divide_monetary (f, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p,
5595  true);
5596 
5597  default:
5598  break;
5599  }
5600 
5601  return NO_ERROR;
5602 }
5603 
5604 static int
5605 qdata_divide_double_to_dbval (DB_VALUE * double_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5606 {
5607  double d;
5608  DB_TYPE type2;
5609 
5610  d = db_get_double (double_val_p);
5611  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5612 
5613  switch (type2)
5614  {
5615  case DB_TYPE_SHORT:
5616  return qdata_divide_double (d, db_get_short (dbval_p), result_p, false);
5617 
5618  case DB_TYPE_INTEGER:
5619  return qdata_divide_double (d, db_get_int (dbval_p), result_p, false);
5620 
5621  case DB_TYPE_BIGINT:
5622  return qdata_divide_double (d, (double) db_get_bigint (dbval_p), result_p, false);
5623 
5624  case DB_TYPE_FLOAT:
5625  return qdata_divide_double (d, db_get_float (dbval_p), result_p, true);
5626 
5627  case DB_TYPE_DOUBLE:
5628  return qdata_divide_double (d, db_get_double (dbval_p), result_p, true);
5629 
5630  case DB_TYPE_NUMERIC:
5631  return qdata_divide_double (d, qdata_coerce_numeric_to_double (dbval_p), result_p, false);
5632 
5633  case DB_TYPE_MONETARY:
5634  return qdata_divide_monetary (d, (db_get_monetary (dbval_p))->amount, (db_get_monetary (dbval_p))->type, result_p,
5635  true);
5636 
5637  default:
5638  break;
5639  }
5640 
5641  return NO_ERROR;
5642 }
5643 
5644 static int
5645 qdata_divide_numeric_to_dbval (DB_VALUE * numeric_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5646 {
5647  DB_TYPE type2;
5648  DB_VALUE dbval_tmp;
5649 
5650  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5651 
5652  switch (type2)
5653  {
5654  case DB_TYPE_SHORT:
5655  case DB_TYPE_INTEGER:
5656  case DB_TYPE_BIGINT:
5657  qdata_coerce_dbval_to_numeric (dbval_p, &dbval_tmp);
5658  if (numeric_db_value_div (numeric_val_p, &dbval_tmp, result_p) != NO_ERROR)
5659  {
5661  return ER_FAILED;
5662  }
5663  break;
5664 
5665  case DB_TYPE_NUMERIC:
5666  if (numeric_db_value_div (numeric_val_p, dbval_p, result_p) != NO_ERROR)
5667  {
5669  return ER_FAILED;
5670  }
5671  break;
5672 
5673  case DB_TYPE_FLOAT:
5674  return qdata_divide_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_float (dbval_p), result_p,
5675  false);
5676 
5677  case DB_TYPE_DOUBLE:
5678  return qdata_divide_double (qdata_coerce_numeric_to_double (numeric_val_p), db_get_double (dbval_p), result_p,
5679  true);
5680 
5681  case DB_TYPE_MONETARY:
5682  return qdata_divide_monetary (qdata_coerce_numeric_to_double (numeric_val_p), (db_get_monetary (dbval_p))->amount,
5683  (db_get_monetary (dbval_p))->type, result_p, true);
5684 
5685  default:
5686  break;
5687  }
5688 
5689  return NO_ERROR;
5690 }
5691 
5692 static int
5693 qdata_divide_monetary_to_dbval (DB_VALUE * monetary_val_p, DB_VALUE * dbval_p, DB_VALUE * result_p)
5694 {
5695  double d;
5696  DB_CURRENCY currency;
5697  DB_TYPE type2;
5698 
5699  d = (db_get_monetary (monetary_val_p))->amount;
5700  currency = (db_get_monetary (monetary_val_p))->type;
5701  type2 = DB_VALUE_DOMAIN_TYPE (dbval_p);
5702 
5703  switch (type2)
5704  {
5705  case DB_TYPE_SHORT:
5706  return qdata_divide_monetary (d, db_get_short (dbval_p), currency, result_p, false);
5707 
5708  case DB_TYPE_INTEGER:
5709  return qdata_divide_monetary (d, db_get_int (dbval_p), currency, result_p, false);
5710 
5711  case DB_TYPE_BIGINT:
5712  return qdata_divide_monetary (d, (double) db_get_bigint (dbval_p), currency, result_p, false);
5713 
5714  case DB_TYPE_FLOAT:
5715  return qdata_divide_monetary (d, db_get_float (dbval_p), currency, result_p, true);
5716 
5717  case DB_TYPE_DOUBLE:
5718  return qdata_divide_monetary (d, db_get_double (dbval_p), currency, result_p, true);
5719 
5720  case DB_TYPE_NUMERIC:
5721  return qdata_divide_monetary (d, qdata_coerce_numeric_to_double (dbval_p), currency, result_p, true);
5722 
5723  case DB_TYPE_MONETARY:
5724  /* Note: we probably should return an error if the two monetaries have different montetary types. */
5725  return qdata_divide_monetary (d, (db_get_monetary (dbval_p))->amount, currency, result_p, true);
5726 
5727  default:
5728  break;
5729  }
5730 
5731  return NO_ERROR;
5732 }
5733 
5734 /*
5735  * qdata_divide_dbval () -
5736  * return: NO_ERROR, or ER_code
5737  * dbval1(in) : First db_value node
5738  * dbval2(in) : Second db_value node
5739  * res(out) : Resultant db_value node
5740  * domain(in) :
5741  *
5742  * Note: Divide dbval1 by dbval2
5743  * Overflow checks are only done when the right operand may be
5744  * smaller than one. That is,
5745  * short / integer -> overflow is not checked. Result will
5746  * always be smaller than the numerand.
5747  * float / short -> overflow is not checked. Minimum float
5748  * representation (e-38) overflows to zero
5749  * which we want.
5750  * Because of zero divide checks, most of the others will not
5751  * overflow but is still being checked in case we are on a
5752  * platform where DBL_EPSILON approaches the value of FLT_MIN.
5753  */
5754 int
5755 qdata_divide_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
5756 {
5757  DB_TYPE type1;
5758  DB_TYPE type2;
5759  int error = NO_ERROR;
5760  DB_VALUE cast_value1;
5761  DB_VALUE cast_value2;
5762  TP_DOMAIN *cast_dom1 = NULL;
5763  TP_DOMAIN *cast_dom2 = NULL;
5764  TP_DOMAIN_STATUS dom_status;
5765 
5766  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
5767  {
5768  return NO_ERROR;
5769  }
5770 
5771  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
5772  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
5773 
5774  db_make_null (&cast_value1);
5775  db_make_null (&cast_value2);
5776 
5777  /* number / string : cast string to DOUBLE, divide as number / DOUBLE */
5778  if (TP_IS_NUMERIC_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
5779  {
5780  /* cast arg2 to double */
5782  }
5783  /* string / number: cast string to DOUBLE, divide as DOUBLE / number */
5784  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_NUMERIC_TYPE (type2))
5785  {
5786  /* cast arg1 to double */
5788  }
5789  /* string / string: cast both to DOUBLE, divide as DOUBLE / DOUBLE */
5790  else if (TP_IS_CHAR_TYPE (type1) && TP_IS_CHAR_TYPE (type2))
5791  {
5792  /* cast number to DOUBLE */
5795  }
5796 
5797  if (cast_dom2 != NULL)
5798  {
5799  dom_status = tp_value_auto_cast (dbval2_p, &cast_value2, cast_dom2);
5800  if (dom_status != DOMAIN_COMPATIBLE)
5801  {
5802  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval2_p, cast_dom2);
5803  return error;
5804  }
5805  dbval2_p = &cast_value2;
5806  }
5807 
5808  if (cast_dom1 != NULL)
5809  {
5810  dom_status = tp_value_auto_cast (dbval1_p, &cast_value1, cast_dom1);
5811  if (dom_status != DOMAIN_COMPATIBLE)
5812  {
5813  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval1_p, cast_dom1);
5814  return error;
5815  }
5816  dbval1_p = &cast_value1;
5817  }
5818 
5819  type1 = DB_VALUE_DOMAIN_TYPE (dbval1_p);
5820  type2 = DB_VALUE_DOMAIN_TYPE (dbval2_p);
5821 
5822  if (DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
5823  {
5824  return NO_ERROR;
5825  }
5826 
5827  if (qdata_is_divided_zero (dbval2_p))
5828  {
5830  return ER_FAILED;
5831  }
5832 
5833  switch (type1)
5834  {
5835  case DB_TYPE_SHORT:
5836  error = qdata_divide_short_to_dbval (dbval1_p, dbval2_p, result_p);
5837  break;
5838 
5839  case DB_TYPE_INTEGER:
5840  error = qdata_divide_int_to_dbval (dbval1_p, dbval2_p, result_p);
5841  break;
5842 
5843  case DB_TYPE_BIGINT:
5844  error = qdata_divide_bigint_to_dbval (dbval1_p, dbval2_p, result_p);
5845  break;
5846 
5847  case DB_TYPE_FLOAT:
5848  error = qdata_divide_float_to_dbval (dbval1_p, dbval2_p, result_p);
5849  break;
5850 
5851  case DB_TYPE_DOUBLE:
5852  error = qdata_divide_double_to_dbval (dbval1_p, dbval2_p, result_p);
5853  break;
5854 
5855  case DB_TYPE_NUMERIC:
5856  error = qdata_divide_numeric_to_dbval (dbval1_p, dbval2_p, result_p);
5857  break;
5858 
5859  case DB_TYPE_MONETARY:
5860  error = qdata_divide_monetary_to_dbval (dbval1_p, dbval2_p, result_p);
5861  break;
5862 
5863  case DB_TYPE_SET:
5864  case DB_TYPE_MULTISET:
5865  case DB_TYPE_SEQUENCE:
5866  case DB_TYPE_TIME:
5867  case DB_TYPE_TIMESTAMP:
5868  case DB_TYPE_TIMESTAMPLTZ:
5869  case DB_TYPE_TIMESTAMPTZ:
5870  case DB_TYPE_DATETIME:
5871  case DB_TYPE_DATETIMELTZ:
5872  case DB_TYPE_DATETIMETZ:
5873  case DB_TYPE_DATE:
5874  case DB_TYPE_STRING:
5875  default:
5877  {
5880  }
5881  }
5882 
5883  if (error != NO_ERROR)
5884  {
5885  return error;
5886  }
5887 
5888  return qdata_coerce_result_to_domain (result_p, domain_p);
5889 }
5890 
5891 /*
5892  * qdata_unary_minus_dbval () -
5893  * return: NO_ERROR, or ER_code
5894  * res(out) : Resultant db_value node
5895  * dbval1(in) : First db_value node
5896  *
5897  * Note: Take unary minus of db_value.
5898  */
5899 int
5901 {
5902  DB_TYPE res_type;
5903  short stmp;
5904  int itmp;
5905  DB_BIGINT bitmp;
5906  double dtmp;
5907  DB_VALUE cast_value;
5908  int er_status = NO_ERROR;
5909 
5910  res_type = DB_VALUE_DOMAIN_TYPE (dbval_p);
5911  if (res_type == DB_TYPE_NULL || DB_IS_NULL (dbval_p))
5912  {
5913  return NO_ERROR;
5914  }
5915 
5916  switch (res_type)
5917  {
5918  case DB_TYPE_INTEGER:
5919  itmp = db_get_int (dbval_p);
5920  if (itmp == INT_MIN)
5921  {
5923  return ER_QPROC_OVERFLOW_UMINUS;
5924  }
5925  db_make_int (result_p, (-1) * itmp);
5926  break;
5927 
5928  case DB_TYPE_BIGINT:
5929  bitmp = db_get_bigint (dbval_p);
5930  if (bitmp == DB_BIGINT_MIN)
5931  {
5933  return ER_QPROC_OVERFLOW_UMINUS;
5934  }
5935  db_make_bigint (result_p, (-1) * bitmp);
5936  break;
5937 
5938  case DB_TYPE_FLOAT:
5939  db_make_float (result_p, (-1) * db_get_float (dbval_p));
5940  break;
5941 
5942  case DB_TYPE_CHAR:
5943  case DB_TYPE_VARCHAR:
5944  case DB_TYPE_NCHAR:
5945  case DB_TYPE_VARNCHAR:
5946  er_status = tp_value_str_auto_cast_to_number (dbval_p, &cast_value, &res_type);
5947  if (er_status != NO_ERROR
5949  {
5950  return er_status;
5951  }
5952 
5953  assert (res_type == DB_TYPE_DOUBLE);
5954 
5955  dbval_p = &cast_value;
5956 
5957  /* fall through */
5958 
5959  case DB_TYPE_DOUBLE:
5960  db_make_double (result_p, (-1) * db_get_double (dbval_p));
5961  break;
5962 
5963  case DB_TYPE_NUMERIC:
5964  db_make_numeric (result_p, db_get_numeric (dbval_p), DB_VALUE_PRECISION (dbval_p), DB_VALUE_SCALE (dbval_p));
5965  if (numeric_db_value_negate (result_p) != NO_ERROR)
5966  {
5967  return ER_FAILED;
5968  }
5969  break;
5970 
5971  case DB_TYPE_MONETARY:
5972  dtmp = (-1) * (db_get_monetary (dbval_p))->amount;
5973  db_make_monetary (result_p, (db_get_monetary (dbval_p))->type, dtmp);
5974  break;
5975 
5976  case DB_TYPE_SHORT:
5977  stmp = db_get_short (dbval_p);
5978  if (stmp == SHRT_MIN)
5979  {
5981  return ER_QPROC_OVERFLOW_UMINUS;
5982  }
5983  db_make_short (result_p, (-1) * stmp);
5984  break;
5985 
5986  default:
5988  {
5989  er_status = ER_QPROC_INVALID_DATATYPE;
5990  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, er_status, 0);
5991  }
5992  break;
5993  }
5994 
5995  return er_status;
5996 }
5997 
5998 /*
5999  * qdata_extract_dbval () -
6000  * return: NO_ERROR, or ER_code
6001  * extr_operand(in) : Specifies datetime field to be extracted
6002  * dbval(in) : Extract source db_value node
6003  * res(out) : Resultant db_value node
6004  * domain(in) :
6005  *
6006  * Note: Extract a datetime field from db_value.
6007  */
6008 int
6009 qdata_extract_dbval (const MISC_OPERAND extr_operand, DB_VALUE * dbval_p, DB_VALUE * result_p, tp_domain * domain_p)
6010 {
6011  if (db_string_extract_dbval (extr_operand, dbval_p, result_p, domain_p) != NO_ERROR)
6012  {
6013  return ER_FAILED;
6014  }
6015  return NO_ERROR;
6016 }
6017 
6018 /*
6019  * qdata_strcat_dbval () -
6020  * return:
6021  * dbval1(in) :
6022  * dbval2(in) :
6023  * res(in) :
6024  * domain(in) :
6025  */
6026 int
6027 qdata_strcat_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
6028 {
6029  DB_TYPE type1, type2;
6030  int error = NO_ERROR;
6031  DB_VALUE cast_value1;
6032  DB_VALUE cast_value2;
6033  TP_DOMAIN *cast_dom1 = NULL;
6034  TP_DOMAIN *cast_dom2 = NULL;
6035  TP_DOMAIN_STATUS dom_status;
6036 
6037  if (domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL)
6038  {
6039  return NO_ERROR;
6040  }
6041 
6042  type1 = dbval1_p ? DB_VALUE_DOMAIN_TYPE (dbval1_p) : DB_TYPE_NULL;
6043  type2 = dbval2_p ? DB_VALUE_DOMAIN_TYPE (dbval2_p) : DB_TYPE_NULL;
6044 
6045  /* string STRCAT date: cast date to string, concat as strings */
6046  /* string STRCAT number: cast number to string, concat as strings */
6047  if (TP_IS_CHAR_TYPE (type1) && (TP_IS_DATE_OR_TIME_TYPE (type2) || TP_IS_NUMERIC_TYPE (type2)))
6048  {
6049  cast_dom2 = tp_domain_resolve_value (dbval1_p, NULL);
6050  }
6051  else if ((TP_IS_DATE_OR_TIME_TYPE (type1) || TP_IS_NUMERIC_TYPE (type1)) && TP_IS_CHAR_TYPE (type2))
6052  {
6053  cast_dom1 = tp_domain_resolve_value (dbval2_p, NULL);
6054  }
6055 
6056  db_make_null (&cast_value1);
6057  db_make_null (&cast_value2);
6058 
6059  if (cast_dom1 != NULL)
6060  {
6061  dom_status = tp_value_auto_cast (dbval1_p, &cast_value1, cast_dom1);
6062  if (dom_status != DOMAIN_COMPATIBLE)
6063  {
6064  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval1_p, cast_dom1);
6065  pr_clear_value (&cast_value1);
6066  pr_clear_value (&cast_value2);
6067  return error;
6068  }
6069  dbval1_p = &cast_value1;
6070  }
6071 
6072  if (cast_dom2 != NULL)
6073  {
6074  dom_status = tp_value_auto_cast (dbval2_p, &cast_value2, cast_dom2);
6075  if (dom_status != DOMAIN_COMPATIBLE)
6076  {
6077  error = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, dbval2_p, cast_dom2);
6078  pr_clear_value (&cast_value1);
6079  pr_clear_value (&cast_value2);
6080  return error;
6081  }
6082  dbval2_p = &cast_value2;
6083  }
6084 
6085  type1 = dbval1_p ? DB_VALUE_DOMAIN_TYPE (dbval1_p) : DB_TYPE_NULL;
6086  type2 = dbval2_p ? DB_VALUE_DOMAIN_TYPE (dbval2_p) : DB_TYPE_NULL;
6087 
6088  if (DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
6089  {
6090  /* ORACLE7 ServerSQL Language Reference Manual 3-4; Although ORACLE treats zero-length character strings as
6091  * nulls, concatenating a zero-length character string with another operand always results in the other operand,
6092  * rather than a null. However, this may not continue to be true in future versions of ORACLE. To concatenate an
6093  * expression that might be null, use the NVL function to explicitly convert the expression to a zero-length
6094  * string. */
6096  {
6097  return NO_ERROR;
6098  }
6099 
6100  if ((DB_IS_NULL (dbval1_p) && QSTR_IS_ANY_CHAR_OR_BIT (type2))
6101  || (DB_IS_NULL (dbval2_p) && QSTR_IS_ANY_CHAR_OR_BIT (type1)))
6102  {
6103  ; /* go ahead */
6104  }
6105  else
6106  {
6107  return NO_ERROR;
6108  }
6109  }
6110 
6111  switch (type1)
6112  {
6113  case DB_TYPE_SHORT:
6114  error = qdata_add_short_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
6115  break;
6116 
6117  case DB_TYPE_INTEGER:
6118  error = qdata_add_int_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
6119  break;
6120 
6121  case DB_TYPE_BIGINT:
6122  error = qdata_add_bigint_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
6123  break;
6124 
6125  case DB_TYPE_FLOAT:
6126  error = qdata_add_float_to_dbval (dbval1_p, dbval2_p, result_p);
6127  break;
6128 
6129  case DB_TYPE_DOUBLE:
6130  error = qdata_add_double_to_dbval (dbval1_p, dbval2_p, result_p);
6131  break;
6132 
6133  case DB_TYPE_NUMERIC:
6134  error = qdata_add_numeric_to_dbval (dbval1_p, dbval2_p, result_p);
6135  break;
6136 
6137  case DB_TYPE_MONETARY:
6138  error = qdata_add_monetary_to_dbval (dbval1_p, dbval2_p, result_p);
6139  break;
6140 
6141  case DB_TYPE_NULL:
6142  case DB_TYPE_CHAR:
6143  case DB_TYPE_VARCHAR:
6144  case DB_TYPE_NCHAR:
6145  case DB_TYPE_VARNCHAR:
6146  case DB_TYPE_BIT:
6147  case DB_TYPE_VARBIT:
6148  if (dbval1_p != NULL && dbval2_p != NULL)
6149  {
6150  error = qdata_add_chars_to_dbval (dbval1_p, dbval2_p, result_p);
6151  }
6152  break;
6153 
6154  case DB_TYPE_SET:
6155  case DB_TYPE_MULTISET:
6156  case DB_TYPE_SEQUENCE:
6157  if (!TP_IS_SET_TYPE (type2))
6158  {
6161  }
6162  error = qdata_add_sequence_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
6163  break;
6164 
6165  case DB_TYPE_TIME:
6166  error = qdata_add_time_to_dbval (dbval1_p, dbval2_p, result_p);
6167  break;
6168 
6169  case DB_TYPE_TIMESTAMP:
6170  case DB_TYPE_TIMESTAMPLTZ:
6171  error = qdata_add_utime_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
6172  if (error == NO_ERROR && type1 == DB_TYPE_TIMESTAMPLTZ)
6173  {
6174  db_make_timestampltz (result_p, *db_get_timestamp (result_p));
6175  }
6176  break;
6177 
6178  case DB_TYPE_TIMESTAMPTZ:
6179  error = qdata_add_timestamptz_to_dbval (dbval1_p, dbval2_p, result_p);
6180  break;
6181 
6182  case DB_TYPE_DATETIME:
6183  case DB_TYPE_DATETIMELTZ:
6184  error = qdata_add_datetime_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
6185  if (error != NO_ERROR && type1 == DB_TYPE_DATETIMELTZ)
6186  {
6187  db_make_datetimeltz (result_p, db_get_datetime (result_p));
6188  }
6189  break;
6190 
6191  case DB_TYPE_DATETIMETZ:
6192  error = qdata_add_datetimetz_to_dbval (dbval1_p, dbval2_p, result_p);
6193  break;
6194 
6195  case DB_TYPE_DATE:
6196  error = qdata_add_date_to_dbval (dbval1_p, dbval2_p, result_p, domain_p);
6197  break;
6198 
6199  default:
6201  error = ER_FAILED;
6202  break;
6203  }
6204 
6205  if (error != NO_ERROR)
6206  {
6207  return error;
6208  }
6209 
6210  if (cast_dom1)
6211  {
6212  pr_clear_value (&cast_value1);
6213  }
6214  if (cast_dom2)
6215  {
6216  pr_clear_value (&cast_value2);
6217  }
6218 
6219  return qdata_coerce_result_to_domain (result_p, domain_p);
6220 }
6221 
6222 /*
6223  * MISCELLANEOUS
6224  */
6225 
6226 /*
6227  * qdata_get_tuple_value_size_from_dbval () - Return the tuple value size
6228  * for the db_value
6229  * return: tuple_value_size or ER_FAILED
6230  * dbval(in) : db_value node
6231  */
6232 int
6234 {
6235  int val_size, align;
6236  int tuple_value_size = 0;
6237  PR_TYPE *type_p;
6238  DB_TYPE dbval_type;
6239 
6240  if (DB_IS_NULL (dbval_p))
6241  {
6242  tuple_value_size = QFILE_TUPLE_VALUE_HEADER_SIZE;
6243  }
6244  else
6245  {
6246  dbval_type = DB_VALUE_DOMAIN_TYPE (dbval_p);
6247  type_p = pr_type_from_id (dbval_type);
6248  if (type_p)
6249  {
6250  val_size = type_p->get_disk_size_of_value (dbval_p);
6251  if (type_p->is_size_computed ())
6252  {
6253  if (pr_is_string_type (dbval_type))
6254  {
6255  int precision = DB_VALUE_PRECISION (dbval_p);
6256  int string_length = db_get_string_length (dbval_p);
6257 
6258  if (precision == TP_FLOATING_PRECISION_VALUE)
6259  {
6260  precision = DB_MAX_STRING_LENGTH;
6261  }
6262 
6263  assert_release (string_length <= precision);
6264 
6265  if (val_size < 0)
6266  {
6267  return ER_FAILED;
6268  }
6269  else if (string_length > precision)
6270  {
6271  /* The size of db_value is greater than it's precision. This case is abnormal (assertion
6272  * failure). Code below is remained for backward compatibility. */
6273  if (db_string_truncate (dbval_p, precision) != NO_ERROR)
6274  {
6275  return ER_FAILED;
6276  }
6278  string_length);
6279 
6280  val_size = type_p->get_disk_size_of_value (dbval_p);
6281  }
6282  }
6283  }
6284 
6285  align = DB_ALIGN (val_size, MAX_ALIGNMENT); /* to align for the next field */
6286  tuple_value_size = QFILE_TUPLE_VALUE_HEADER_SIZE + align;
6287  }
6288  }
6289 
6290  return tuple_value_size;
6291 }
6292 
6293 /*
6294  * qdata_get_single_tuple_from_list_id () -
6295  * return: NO_ERROR or error code
6296  * list_id(in) : List file identifier
6297  * single_tuple(in) : VAL_LIST
6298  */
6299 int
6301 {
6302  QFILE_TUPLE_RECORD tuple_record = { NULL, 0 };
6303  QFILE_LIST_SCAN_ID scan_id;
6304  OR_BUF buf;
6305  PR_TYPE *pr_type_p;
6307  int length;
6308  TP_DOMAIN *domain_p;
6309  char *ptr;
6310  int tuple_count, value_count, i;
6311  QPROC_DB_VALUE_LIST value_list;
6312  int error_code;
6313 
6314  tuple_count = list_id_p->tuple_cnt;
6315  value_count = list_id_p->type_list.type_cnt;
6316 
6317  /* value_count can be greater than single_tuple_p->val_cnt when the subquery has a hidden column. Under normal
6318  * situation, those are same. */
6319  if (tuple_count > 1 || value_count < single_tuple_p->val_cnt)
6320  {
6323  }
6324 
6325  if (tuple_count == 1)
6326  {
6327  error_code = qfile_open_list_scan (list_id_p, &scan_id);
6328  if (error_code != NO_ERROR)
6329  {
6330  return error_code;
6331  }
6332 
6333  if (qfile_scan_list_next (thread_p, &scan_id, &tuple_record, PEEK) != S_SUCCESS)
6334  {
6335  qfile_close_scan (thread_p, &scan_id);
6336  return ER_FAILED;
6337  }
6338 
6339  for (i = 0, value_list = single_tuple_p->valp; i < single_tuple_p->val_cnt; i++, value_list = value_list->next)
6340  {
6341  domain_p = list_id_p->type_list.domp[i];
6342  if (domain_p == NULL || domain_p->type == NULL)
6343  {
6344  qfile_close_scan (thread_p, &scan_id);
6347  }
6348 
6349  if (db_value_domain_init (value_list->val, TP_DOMAIN_TYPE (domain_p), domain_p->precision, domain_p->scale) !=
6350  NO_ERROR)
6351  {
6352  qfile_close_scan (thread_p, &scan_id);
6355  }
6356 
6357  pr_type_p = domain_p->type;
6358  if (pr_type_p == NULL)
6359  {
6360  qfile_close_scan (thread_p, &scan_id);
6361  return ER_FAILED;
6362  }
6363 
6364  flag = (QFILE_TUPLE_VALUE_FLAG) qfile_locate_tuple_value (tuple_record.tpl, i, &ptr, &length);
6365  OR_BUF_INIT (buf, ptr, length);
6366  if (flag == V_BOUND)
6367  {
6368  if (pr_type_p->data_readval (&buf, value_list->val, domain_p, -1, true, NULL, 0) != NO_ERROR)
6369  {
6370  qfile_close_scan (thread_p, &scan_id);
6371  return ER_FAILED;
6372  }
6373  }
6374  else
6375  {
6376  /* If value is NULL, properly initialize the result */
6377  db_value_domain_init (value_list->val, pr_type_p->id, DB_DEFAULT_PRECISION, DB_DEFAULT_SCALE);
6378  }
6379  }
6380 
6381  qfile_close_scan (thread_p, &scan_id);
6382  }
6383 
6384  return NO_ERROR;
6385 }
6386 
6387 /*
6388  * qdata_get_valptr_type_list () -
6389  * return: NO_ERROR, or ER_code
6390  * valptr_list(in) : Value pointer list
6391  * type_list(out) : Set to the result type list
6392  *
6393  * Note: Find the result type list of value pointer list and set to
6394  * type list. Regu variables that are hidden columns are not
6395  * entered as part of the type list because they are not entered
6396  * in the list file.
6397  */
6398 int
6400  qfile_tuple_value_type_list * type_list_p)
6401 {
6402  REGU_VARIABLE_LIST reg_var_p;
6403  int i, count;
6404 
6405  if (type_list_p == NULL)
6406  {
6408  return ER_FAILED;
6409  }
6410 
6411  reg_var_p = valptr_list_p->valptrp;
6412  count = 0;
6413 
6414  for (i = 0; i < valptr_list_p->valptr_cnt; i++)
6415  {
6417  {
6418  count++;
6419  }
6420 
6421  reg_var_p = reg_var_p->next;
6422  }
6423 
6424  type_list_p->type_cnt = count;
6425  type_list_p->domp = NULL;
6426 
6427  if (type_list_p->type_cnt != 0)
6428  {
6429  type_list_p->domp = (TP_DOMAIN **) db_private_alloc (thread_p, sizeof (TP_DOMAIN *) * type_list_p->type_cnt);
6430  if (type_list_p->domp == NULL)
6431  {
6432  return ER_FAILED;
6433  }
6434  }
6435 
6436  reg_var_p = valptr_list_p->valptrp;
6437  for (i = 0; i < type_list_p->type_cnt;)
6438  {
6440  {
6441  type_list_p->domp[i++] = reg_var_p->value.domain;
6442  }
6443 
6444  reg_var_p = reg_var_p->next;
6445  }
6446 
6447  return NO_ERROR;
6448 }
6449 
6450 /*
6451  * qdata_get_dbval_from_constant_regu_variable () -
6452  * return: DB_VALUE *, or NULL
6453  * regu_var(in): Regulator Variable
6454  * vd(in) : Value descriptor
6455  *
6456  * Note: Find the db_value represented by regu_var node and
6457  * return a pointer to it.
6458  *
6459  * Note: Regulator variable should point to only constant values.
6460  */
6461 static DB_VALUE *
6463  VAL_DESCR * val_desc_p)
6464 {
6465  DB_VALUE *peek_value_p;
6466  DB_TYPE dom_type, val_type;
6467  TP_DOMAIN_STATUS dom_status;
6468  int result;
6469  HL_HEAPID save_heapid = 0;
6470 
6471  assert (regu_var_p != NULL);
6472  assert (regu_var_p->domain != NULL);
6473 
6475  {
6477  }
6478 
6479  result = fetch_peek_dbval (thread_p, regu_var_p, val_desc_p, NULL, NULL, NULL, &peek_value_p);
6480  if (result != NO_ERROR)
6481  {
6482  return NULL;
6483  }
6484 
6485  if (!DB_IS_NULL (peek_value_p))
6486  {
6487  val_type = DB_VALUE_TYPE (peek_value_p);
6488  assert (val_type != DB_TYPE_NULL);
6489 
6490  dom_type = TP_DOMAIN_TYPE (regu_var_p->domain);
6491  if (dom_type != DB_TYPE_NULL)
6492  {
6493  assert (dom_type != DB_TYPE_NULL);
6494 
6495  if (val_type == DB_TYPE_OID)
6496  {
6497  assert ((dom_type == DB_TYPE_OID) || (dom_type == DB_TYPE_VOBJ));
6498  }
6499  else if (val_type != dom_type
6500  || (val_type == DB_TYPE_NUMERIC
6501  && (peek_value_p->domain.numeric_info.precision != regu_var_p->domain->precision
6502  || peek_value_p->domain.numeric_info.scale != regu_var_p->domain->scale)))
6503  {
6505  {
6506  /* do not cast at here, is handled at analytic function evaluation later */
6507  ;
6508  }
6509  else
6510  {
6512  {
6513  save_heapid = db_change_private_heap (thread_p, 0);
6514  }
6515 
6516  dom_status = tp_value_auto_cast (peek_value_p, peek_value_p, regu_var_p->domain);
6517  if (save_heapid != 0)
6518  {
6519  (void) db_change_private_heap (thread_p, save_heapid);
6520  save_heapid = 0;
6521  }
6522  if (dom_status != DOMAIN_COMPATIBLE)
6523  {
6524  result = tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_value_p, regu_var_p->domain);
6525  return NULL;
6526  }
6527  assert (dom_type == DB_VALUE_TYPE (peek_value_p)
6529  }
6530  }
6531  }
6532  }
6533 
6534  return peek_value_p;
6535 }
6536 
6537 /*
6538  * qdata_convert_dbvals_to_set () -
6539  * return: NO_ERROR, or ER_code
6540  * stype(in) : set type
6541  * func(in) : regu variable (guaranteed TYPE_FUNC)
6542  * vd(in) : Value descriptor
6543  * obj_oid(in): object identifier
6544  * tpl(in) : list file tuple
6545  *
6546  * Note: Convert a list of vars into a sequence and return a pointer to it.
6547  */
6548 static int
6550  VAL_DESCR * val_desc_p, OID * obj_oid_p, QFILE_TUPLE tuple)
6551 {
6552  DB_VALUE dbval, *result_p = NULL;
6553  DB_COLLECTION *collection_p = NULL;
6554  SETOBJ *setobj_p = NULL;
6555  int n, size;
6556  REGU_VARIABLE_LIST regu_var_p = NULL, operand = NULL;
6557  int error_code = NO_ERROR;
6558  TP_DOMAIN *domain_p = NULL;
6559 
6560  result_p = regu_func_p->value.funcp->value;
6561  operand = regu_func_p->value.funcp->operand;
6562  domain_p = regu_func_p->domain;
6563  db_make_null (&dbval);
6564 
6565  if (stype == DB_TYPE_SET)
6566  {
6567  collection_p = db_set_create_basic (NULL, NULL);
6568  }
6569  else if (stype == DB_TYPE_MULTISET)
6570  {
6571  collection_p = db_set_create_multi (NULL, NULL);
6572  }
6573  else if (stype == DB_TYPE_SEQUENCE || stype == DB_TYPE_VOBJ)
6574  {
6575  size = 0;
6576  for (regu_var_p = operand; regu_var_p; regu_var_p = regu_var_p->next)
6577  {
6578  size++;
6579  }
6580 
6581  collection_p = db_seq_create (NULL, NULL, size);
6582  }
6583  else
6584  {
6585  return ER_FAILED;
6586  }
6587 
6588  error_code = set_get_setobj (collection_p, &setobj_p, 1);
6589  if (error_code != NO_ERROR || !setobj_p)
6590  {
6591  goto error;
6592  }
6593 
6594  /*
6595  * DON'T set the "set"'s domain if it's really a vobj; they don't
6596  * play by quite the same rules. The domain coming in here is some
6597  * flavor of vobj domain, which is definitely *not* what the
6598  * components of the sequence will be. Putting the domain in here
6599  * evidently causes the vobj's to get packed up in list files in some
6600  * way that readers can't cope with.
6601  */
6602  if (stype != DB_TYPE_VOBJ)
6603  {
6604  setobj_put_domain (setobj_p, domain_p);
6605  }
6606 
6607  n = 0;
6608  while (operand)
6609  {
6610  if (fetch_copy_dbval (thread_p, &operand->value, val_desc_p, NULL, obj_oid_p, tuple, &dbval) != NO_ERROR)
6611  {
6612  goto error;
6613  }
6614 
6615  if ((stype == DB_TYPE_VOBJ) && (n == 2))
6616  {
6617  if (DB_IS_NULL (&dbval))
6618  {
6619  set_free (collection_p);
6620  return NO_ERROR;
6621  }
6622  }
6623 
6624  /* using setobj_put_value transfers "ownership" of the db_value memory to the set. This avoids a redundant
6625  * clone/free. */
6626  error_code = setobj_put_value (setobj_p, n, &dbval);
6627 
6628  /*
6629  * if we attempt to add a duplicate value to a set,
6630  * clear the value, but do not set an error code
6631  */
6632  if (error_code == SET_DUPLICATE_VALUE)
6633  {
6634  pr_clear_value (&dbval);
6635  error_code = NO_ERROR;
6636  }
6637 
6638  if (error_code != NO_ERROR)
6639  {
6640  goto error;
6641  }
6642 
6643  operand = operand->next;
6644  n++;
6645  }
6646 
6647  set_make_collection (result_p, collection_p);
6648  if (stype == DB_TYPE_VOBJ)
6649  {
6650  db_value_alter_type (result_p, DB_TYPE_VOBJ);
6651  }
6652 
6653  return NO_ERROR;
6654 
6655 error:
6656  pr_clear_value (&dbval);
6657  if (collection_p != NULL)
6658  {
6659  set_free (collection_p);
6660  }
6661  return ((error_code == NO_ERROR) ? ER_FAILED : error_code);
6662 }
6663 
6664 /*
6665  * qdata_evaluate_generic_function () - Evaluates a generic function.
6666  * return: NO_ERROR, or ER_code
6667  * funcp(in) :
6668  * vd(in) :
6669  * obj_oid(in) :
6670  * tpl(in) :
6671  */
6672 static int
6674  OID * obj_oid_p, QFILE_TUPLE tuple)
6675 {
6677  return ER_FAILED;
6678 }
6679 
6680 /*
6681  * qdata_get_class_of_function () -
6682  * return: NO_ERROR, or ER_code
6683  * funcp(in) :
6684  * vd(in) :
6685  * obj_oid(in) :
6686  * tpl(in) :
6687  *
6688  * Note: This routine returns the class of its argument.
6689  */
6690 static int
6691 qdata_get_class_of_function (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p,
6692  OID * obj_oid_p, QFILE_TUPLE tuple)
6693 {
6694  OID class_oid;
6695  OID *instance_oid_p;
6696  DB_VALUE *val_p, element;
6697  DB_TYPE type;
6698  int err;
6699 
6700  if (fetch_peek_dbval (thread_p, &function_p->operand->value, val_desc_p, NULL, obj_oid_p, tuple, &val_p) != NO_ERROR)
6701  {
6702  return ER_FAILED;
6703  }
6704 
6705  if (DB_IS_NULL (val_p))
6706  {
6707  db_make_null (function_p->value);
6708  return NO_ERROR;
6709  }
6710 
6711  type = DB_VALUE_DOMAIN_TYPE (val_p);
6712  if (type == DB_TYPE_VOBJ)
6713  {
6714  /* grab the real oid */
6715  if (db_seq_get (db_get_set (val_p), 2, &element) != NO_ERROR)
6716  {
6717  return ER_FAILED;
6718  }
6719 
6720  val_p = &element;
6721  type = DB_VALUE_DOMAIN_TYPE (val_p);
6722  }
6723 
6724  if (type != DB_TYPE_OID)
6725  {
6726  return ER_FAILED;
6727  }
6728 
6729  instance_oid_p = db_get_oid (val_p);
6730  err = heap_get_class_oid (thread_p, instance_oid_p, &class_oid);
6731  if (err != S_SUCCESS)
6732  {
6733  ASSERT_ERROR_AND_SET (err);
6734  return err;
6735  }
6736 
6737  db_make_oid (function_p->value, &class_oid);
6738 
6739  return NO_ERROR;
6740 }
6741 
6742 /*
6743  * qdata_evaluate_function () -
6744  * return: NO_ERROR, or ER_code
6745  * func(in) :
6746  * vd(in) :
6747  * obj_oid(in) :
6748  * tpl(in) :
6749  *
6750  * Note: Evaluate given function.
6751  */
6752 int
6753 qdata_evaluate_function (THREAD_ENTRY * thread_p, regu_variable_node * function_p, val_descr * val_desc_p,
6754  OID * obj_oid_p, QFILE_TUPLE tuple)
6755 {
6756  FUNCTION_TYPE *funcp;
6757 
6758  /* should sync with fetch_peek_dbval () */
6759 
6760  funcp = function_p->value.funcp;
6761  /* clear any value from a previous iteration */
6762  pr_clear_value (funcp->value);
6763 
6764  switch (funcp->ftype)
6765  {
6766  case F_SET:
6767  return qdata_convert_dbvals_to_set (thread_p, DB_TYPE_SET, function_p, val_desc_p, obj_oid_p, tuple);
6768 
6769  case F_MULTISET:
6770  return qdata_convert_dbvals_to_set (thread_p, DB_TYPE_MULTISET, function_p, val_desc_p, obj_oid_p, tuple);
6771 
6772  case F_SEQUENCE:
6773  return qdata_convert_dbvals_to_set (thread_p, DB_TYPE_SEQUENCE, function_p, val_desc_p, obj_oid_p, tuple);
6774 
6775  case F_VID:
6776  return qdata_convert_dbvals_to_set (thread_p, DB_TYPE_VOBJ, function_p, val_desc_p, obj_oid_p, tuple);
6777 
6778  case F_TABLE_SET:
6779  return qdata_convert_table_to_set (thread_p, DB_TYPE_SET, function_p, val_desc_p);
6780 
6781  case F_TABLE_MULTISET:
6782  return qdata_convert_table_to_set (thread_p, DB_TYPE_MULTISET, function_p, val_desc_p);
6783 
6784  case F_TABLE_SEQUENCE:
6785  return qdata_convert_table_to_set (thread_p, DB_TYPE_SEQUENCE, function_p, val_desc_p);
6786 
6787  case F_GENERIC:
6788  return qdata_evaluate_generic_function (thread_p, funcp, val_desc_p, obj_oid_p, tuple);
6789 
6790  case F_CLASS_OF:
6791  return qdata_get_class_of_function (thread_p, funcp, val_desc_p, obj_oid_p, tuple);
6792 
6793  case F_INSERT_SUBSTRING:
6794  return qdata_insert_substring_function (thread_p, funcp, val_desc_p, obj_oid_p, tuple);
6795 
6796  case F_ELT:
6797  return qdata_elt (thread_p, funcp, val_desc_p, obj_oid_p, tuple);
6798 
6799  case F_BENCHMARK:
6800  return qdata_benchmark (thread_p, funcp, val_desc_p, obj_oid_p, tuple);
6801 
6802  case F_JSON_ARRAY:
6803  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6805 
6806  case F_JSON_ARRAY_APPEND:
6807  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6809 
6810  case F_JSON_ARRAY_INSERT:
6811  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6813 
6814  case F_JSON_CONTAINS:
6815  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6817 
6818  case F_JSON_CONTAINS_PATH:
6819  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6821 
6822  case F_JSON_DEPTH:
6823  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6825 
6826  case F_JSON_EXTRACT:
6827  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6829 
6830  case F_JSON_GET_ALL_PATHS:
6831  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6833 
6834  case F_JSON_INSERT:
6835  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6837 
6838  case F_JSON_KEYS:
6839  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6841 
6842  case F_JSON_LENGTH:
6843  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6845 
6846  case F_JSON_MERGE:
6847  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6849 
6850  case F_JSON_MERGE_PATCH:
6851  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6853 
6854  case F_JSON_OBJECT:
6855  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6857 
6858  case F_JSON_PRETTY:
6859  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6861 
6862  case F_JSON_QUOTE:
6863  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6865 
6866  case F_JSON_REMOVE:
6867  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6869 
6870  case F_JSON_REPLACE:
6871  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6873 
6874  case F_JSON_SEARCH:
6875  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6877 
6878  case F_JSON_SET:
6879  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6881 
6882  case F_JSON_TYPE:
6883  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6885 
6886  case F_JSON_UNQUOTE:
6887  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6889 
6890  case F_JSON_VALID:
6891  return qdata_convert_operands_to_value_and_call (thread_p, funcp, val_desc_p, obj_oid_p, tuple,
6893 
6894  case F_REGEXP_COUNT:
6895  case F_REGEXP_INSTR:
6896  case F_REGEXP_LIKE:
6897  case F_REGEXP_REPLACE:
6898  case F_REGEXP_SUBSTR:
6899  return qdata_regexp_function (thread_p, funcp, val_desc_p, obj_oid_p, tuple);
6900 
6901  default:
6903  return ER_FAILED;
6904  }
6905 }
6906 
6907 /*
6908  * qdata_convert_table_to_set () -
6909  * return: NO_ERROR, or ER_code
6910  * stype(in) : set type
6911  * func(in) : regu variable (guaranteed TYPE_FUNC)
6912  * vd(in) : Value descriptor
6913  *
6914  * Note: Convert a list file into a set/sequence and return a pointer to it.
6915  */
6916 static int
6917 qdata_convert_table_to_set (THREAD_ENTRY * thread_p, DB_TYPE stype, REGU_VARIABLE * function_p, VAL_DESCR * val_desc_p)
6918 {
6919  QFILE_LIST_SCAN_ID scan_id;
6920  QFILE_TUPLE_RECORD tuple_record = {
6921  NULL, 0
6922  };
6923  SCAN_CODE scan_code;
6924  QFILE_LIST_ID *list_id_p;
6925  int i, seq_pos;
6926  int val_size;
6927  OR_BUF buf;
6928  DB_VALUE dbval, *result_p;
6929  DB_COLLECTION *collection_p = NULL;
6930  SETOBJ *setobj_p;
6931  DB_TYPE type;
6932  PR_TYPE *pr_type_p;
6933  int error;
6934  REGU_VARIABLE_LIST operand;
6935  TP_DOMAIN *domain_p;
6936  char *ptr;
6937 
6938  result_p = function_p->value.funcp->value;
6939  operand = function_p->value.funcp->operand;
6940 
6941  /* execute linked query */
6942  EXECUTE_REGU_VARIABLE_XASL (thread_p, &(operand->value), val_desc_p);
6943 
6944  if (CHECK_REGU_VARIABLE_XASL_STATUS (&(operand->value)) != XASL_SUCCESS)
6945  {
6946  return ER_FAILED;
6947  }
6948 
6949  domain_p = function_p->domain;
6950  list_id_p = operand->value.value.srlist_id->list_id;
6951  db_make_null (&dbval);
6952 
6953  if (stype == DB_TYPE_SET)
6954  {
6955  collection_p = db_set_create_basic (NULL, NULL);
6956  }
6957  else if (stype == DB_TYPE_MULTISET)
6958  {
6959  collection_p = db_set_create_multi (NULL, NULL);
6960  }
6961  else if (stype == DB_TYPE_SEQUENCE || stype == DB_TYPE_VOBJ)
6962  {
6963  collection_p = db_seq_create (NULL, NULL, (list_id_p->tuple_cnt * list_id_p->type_list.type_cnt));
6964  }
6965  else
6966  {
6967  return ER_FAILED;
6968  }
6969 
6970  error = set_get_setobj (collection_p, &setobj_p, 1);
6971  if (error != NO_ERROR || !setobj_p)
6972  {
6973  set_free (collection_p);
6974  return ER_FAILED;
6975  }
6976 
6977  /*
6978  * Don't need to worry about the vobj case here; this function can't
6979  * be called in a context where it's expected to produce a vobj. See
6980  * xd_dbvals_to_set for the contrasting case.
6981  */
6982  setobj_put_domain (setobj_p, domain_p);
6983  if (qfile_open_list_scan (list_id_p, &scan_id) != NO_ERROR)
6984  {
6985  return ER_FAILED;
6986  }
6987 
6988  seq_pos = 0;
6989  while (true)
6990  {
6991  scan_code = qfile_scan_list_next (thread_p, &scan_id, &tuple_record, PEEK);
6992  if (scan_code != S_SUCCESS)
6993  {
6994  break;
6995  }
6996 
6997  for (i = 0; i < list_id_p->type_list.type_cnt; i++)
6998  {
6999  /* grab column i and add it to the col */
7000  type = TP_DOMAIN_TYPE (list_id_p->type_list.domp[i]);
7001  pr_type_p = pr_type_from_id (type);
7002  if (pr_type_p == NULL)
7003  {
7004  qfile_close_scan (thread_p, &scan_id);
7005  return ER_FAILED;
7006  }
7007 
7008  if (qfile_locate_tuple_value (tuple_record.tpl, i, &ptr, &val_size) == V_BOUND)
7009  {
7010  or_init (&buf, ptr, val_size);
7011 
7012  if (pr_type_p->data_readval (&buf, &dbval, list_id_p->type_list.domp[i], -1, true, NULL, 0) != NO_ERROR)
7013  {
7014  qfile_close_scan (thread_p, &scan_id);
7015  return ER_FAILED;
7016  }
7017  }
7018 
7019  /*
7020  * using setobj_put_value transfers "ownership" of the
7021  * db_value memory to the set. This avoids a redundant clone/free.
7022  */
7023  error = setobj_put_value (setobj_p, seq_pos++, &dbval);
7024 
7025  /*
7026  * if we attempt to add a duplicate value to a set,
7027  * clear the value, but do not set an error
7028  */
7029  if (error == SET_DUPLICATE_VALUE)
7030  {
7031  pr_clear_value (&dbval);
7032  error = NO_ERROR;
7033  }
7034 
7035  if (error != NO_ERROR)
7036  {
7037  set_free (collection_p);
7038  pr_clear_value (&dbval);
7039  qfile_close_scan (thread_p, &scan_id);
7040  return ER_FAILED;
7041  }
7042  }
7043  }
7044 
7045  qfile_close_scan (thread_p, &scan_id);
7046  set_make_collection (result_p, collection_p);
7047 
7048  return NO_ERROR;
7049 }
7050 
7051 /*
7052  * qdata_evaluate_connect_by_root () - CONNECT_BY_ROOT operator evaluation func
7053  * return:
7054  * xasl_p(in):
7055  * regu_p(in):
7056  * result_val_p(in/out):
7057  * vd(in):
7058  */
7059 bool
7061  DB_VALUE * result_val_p, val_descr * vd)
7062 {
7063  QFILE_TUPLE tpl;
7064  QFILE_LIST_ID *list_id_p;
7065  QFILE_LIST_SCAN_ID s_id;
7066  QFILE_TUPLE_RECORD tuple_rec = { (QFILE_TUPLE) NULL, 0 };
7067  const QFILE_TUPLE_POSITION *bitval = NULL;
7068  QFILE_TUPLE_POSITION p_pos;
7069  QPROC_DB_VALUE_LIST valp;
7070  DB_VALUE p_pos_dbval;
7071  XASL_NODE *xasl, *xptr;
7072  int length, i;
7073 
7074  /* sanity checks */
7075  if (regu_p->type != TYPE_CONSTANT)
7076  {
7077  return false;
7078  }
7079 
7080  xasl = (XASL_NODE *) xasl_p;
7081  if (!xasl)
7082  {
7083  return false;
7084  }
7085 
7086  if (!XASL_IS_FLAGED (xasl, XASL_HAS_CONNECT_BY))
7087  {
7088  return false;
7089  }
7090 
7091  xptr = xasl->connect_by_ptr;
7092  if (!xptr)
7093  {
7094  return false;
7095  }
7096 
7097  tpl = xptr->proc.connect_by.curr_tuple;
7098 
7099  /* walk the parents up to root */
7100 
7101  list_id_p = xptr->list_id;
7102 
7103  if (qfile_open_list_scan (list_id_p, &s_id) != NO_ERROR)
7104  {
7105  return false;
7106  }
7107 
7108  /* we start with tpl itself */
7109  tuple_rec.tpl = tpl;
7110 
7111  do
7112  {
7113  /* get the parent node */
7115  &p_pos_dbval, &tp_Bit_domain) != NO_ERROR)
7116  {
7117  qfile_close_scan (thread_p, &s_id);
7118  return false;
7119  }
7120 
7121  bitval = REINTERPRET_CAST (const QFILE_TUPLE_POSITION *, db_get_bit (&p_pos_dbval, &length));
7122 
7123  if (bitval)
7124  {
7125  p_pos.status = s_id.status;
7126  p_pos.position = S_ON;
7127  p_pos.vpid = bitval->vpid;
7128  p_pos.offset = bitval->offset;
7129  p_pos.tpl = NULL;
7130  p_pos.tplno = bitval->tplno;
7131 
7132  if (qfile_jump_scan_tuple_position (thread_p, &s_id, &p_pos, &tuple_rec, PEEK) != S_SUCCESS)
7133  {
7134  qfile_close_scan (thread_p, &s_id);
7135  return false;
7136  }
7137  }
7138  }
7139  while (bitval); /* the parent tuple pos is null for the root node */
7140 
7141  qfile_close_scan (thread_p, &s_id);
7142 
7143  /* here tuple_rec.tpl is the root tuple; get the required column */
7144 
7145  for (i = 0, valp = xptr->val_list->valp; valp; i++, valp = valp->next)
7146  {
7147  if (valp->val == regu_p->value.dbvalptr)
7148  {
7149  break;
7150  }
7151  }
7152 
7153  if (i < xptr->val_list->val_cnt)
7154  {
7155  if (qexec_get_tuple_column_value (tuple_rec.tpl, i, result_val_p, regu_p->domain) != NO_ERROR)
7156  {
7157  return false;
7158  }
7159  }
7160  else
7161  {
7162  /* TYPE_CONSTANT but not in val_list, check if it is inst_num() (orderby_num() is not allowed) */
7163  if (regu_p->value.dbvalptr == xasl->instnum_val)
7164  {
7165  if (pr_clone_value (xasl->instnum_val, result_val_p) != NO_ERROR)
7166  {
7167  return false;
7168  }
7169  }
7170  else
7171  {
7172  return false;
7173  }
7174  }
7175 
7176  return true;
7177 }
7178 
7179 /*
7180  * qdata_evaluate_qprior () - PRIOR in SELECT list evaluation func
7181  * return:
7182  * xasl_p(in):
7183  * regu_p(in):
7184  * result_val_p(in/out):
7185  * vd(in):
7186  */
7187 bool
7188 qdata_evaluate_qprior (THREAD_ENTRY * thread_p, void *xasl_p, regu_variable_node * regu_p, DB_VALUE * result_val_p,
7189  val_descr * vd)
7190 {
7191  QFILE_TUPLE tpl;
7192  QFILE_LIST_ID *list_id_p;
7193  QFILE_LIST_SCAN_ID s_id;
7194  QFILE_TUPLE_RECORD tuple_rec = { (QFILE_TUPLE) NULL, 0 };
7195  const QFILE_TUPLE_POSITION *bitval = NULL;
7196  QFILE_TUPLE_POSITION p_pos;
7197  DB_VALUE p_pos_dbval;
7198  XASL_NODE *xasl, *xptr;
7199  int length;
7200 
7201  xasl = (XASL_NODE *) xasl_p;
7202 
7203  /* sanity checks */
7204  if (!xasl)
7205  {
7206  return false;
7207  }
7208 
7209  if (!XASL_IS_FLAGED (xasl, XASL_HAS_CONNECT_BY))
7210  {
7211  return false;
7212  }
7213 
7214  xptr = xasl->connect_by_ptr;
7215  if (!xptr)
7216  {
7217  return false;
7218  }
7219 
7220  tpl = xptr->proc.connect_by.curr_tuple;
7221 
7222  list_id_p = xptr->list_id;
7223 
7224  if (qfile_open_list_scan (list_id_p, &s_id) != NO_ERROR)
7225  {
7226  return false;
7227  }
7228 
7229  tuple_rec.tpl = tpl;
7230 
7231  /* get the parent node */
7233  &p_pos_dbval, &tp_Bit_domain) != NO_ERROR)
7234  {
7235  qfile_close_scan (thread_p, &s_id);
7236  return false;
7237  }
7238 
7239  bitval = REINTERPRET_CAST (const QFILE_TUPLE_POSITION *, db_get_bit (&p_pos_dbval, &length));
7240 
7241  if (bitval)
7242  {
7243  p_pos.status = s_id.status;
7244  p_pos.position = S_ON;
7245  p_pos.vpid = bitval->vpid;
7246  p_pos.offset = bitval->offset;
7247  p_pos.tpl = NULL;
7248  p_pos.tplno = bitval->tplno;
7249 
7250  if (qfile_jump_scan_tuple_position (thread_p, &s_id, &p_pos, &tuple_rec, PEEK) != S_SUCCESS)
7251  {
7252  qfile_close_scan (thread_p, &s_id);
7253  return false;
7254  }
7255  }
7256  else
7257  {
7258  /* the parent tuple pos is null for the root node */
7259  tuple_rec.tpl = NULL;
7260  }
7261 
7262  qfile_close_scan (thread_p, &s_id);
7263 
7264  if (tuple_rec.tpl != NULL)
7265  {
7266  /* fetch val list from the parent tuple */
7267  if (fetch_val_list (thread_p, xptr->proc.connect_by.prior_regu_list_pred, vd, NULL, NULL, tuple_rec.tpl, PEEK) !=
7268  NO_ERROR)
7269  {
7270  return false;
7271  }
7272  if (fetch_val_list (thread_p, xptr->proc.connect_by.prior_regu_list_rest, vd, NULL, NULL, tuple_rec.tpl, PEEK) !=
7273  NO_ERROR)
7274  {
7275  return false;
7276  }
7277 
7278  /* replace values in T_QPRIOR argument with values from parent tuple */
7279  qexec_replace_prior_regu_vars_prior_expr (thread_p, regu_p, xptr, xptr);
7280 
7281  /* evaluate the modified regu_p */
7282  if (fetch_copy_dbval (thread_p, regu_p, vd, NULL, NULL, tuple_rec.tpl, result_val_p) != NO_ERROR)
7283  {
7284  return false;
7285  }
7286  }
7287  else
7288  {
7289  db_make_null (result_val_p);
7290  }
7291 
7292  return true;
7293 }
7294 
7295 /*
7296  * qdata_evaluate_sys_connect_by_path () - SYS_CONNECT_BY_PATH function
7297  * evaluation func
7298  * return:
7299  * select_xasl(in):
7300  * regu_p1(in): column
7301  * regu_p2(in): character
7302  * result_val_p(in/out):
7303  */
7304 bool
7306  DB_VALUE * value_char, DB_VALUE * result_p, val_descr * vd)
7307 {
7308  QFILE_TUPLE tpl;
7309  QFILE_LIST_ID *list_id_p;
7310  QFILE_LIST_SCAN_ID s_id;
7311  QFILE_TUPLE_RECORD tuple_rec = { (QFILE_TUPLE) NULL, 0 };
7312  const QFILE_TUPLE_POSITION *bitval = NULL;
7313  QFILE_TUPLE_POSITION p_pos;
7314  QPROC_DB_VALUE_LIST valp;
7315  DB_VALUE p_pos_dbval, cast_value, arg_dbval;
7316  XASL_NODE *xasl, *xptr;
7317  int length, i;
7318  char *result_path = NULL, *path_tmp = NULL;
7319  int len_result_path;
7320  size_t len_tmp = 0, len;
7321  char *sep = NULL;
7322  DB_VALUE *arg_dbval_p = NULL;
7323  DB_VALUE **save_values = NULL;
7324  bool use_extended = false; /* flag for using extended form, accepting an expression as the first argument of
7325  * SYS_CONNECT_BY_PATH() */
7326  bool need_clear_arg_dbval = false;
7327 
7328  assert (DB_IS_NULL (result_p));
7329 
7330  /* sanity checks */
7331  xasl = (XASL_NODE *) xasl_p;
7332  if (!xasl)
7333  {
7334  return false;
7335  }
7336 
7337  if (!XASL_IS_FLAGED (xasl, XASL_HAS_CONNECT_BY))
7338  {
7339  return false;
7340  }
7341 
7342  xptr = xasl->connect_by_ptr;
7343  if (!xptr)
7344  {
7345  return false;
7346  }
7347 
7348  tpl = xptr->proc.connect_by.curr_tuple;
7349 
7350  /* column */
7351  if (regu_p->type != TYPE_CONSTANT)
7352  {
7353  /* NOTE: if the column is non-string, a cast will be made (see T_CAST). This is specific to sys_connect_by_path
7354  * because the result is always varchar (by comparison to connect_by_root which has the result of the root
7355  * specifiec column). The cast is propagated from the parser tree into the regu variabile, which has the
7356  * TYPE_INARITH type with arithptr with type T_CAST and right argument the real column, which will be further
7357  * used for column retrieving in the xasl->val_list->valp. */
7358 
7359  if (regu_p->type == TYPE_INARITH)
7360  {
7361  if (regu_p->value.arithptr && regu_p->value.arithptr->opcode == T_CAST)
7362  {
7363  /* correct column */
7364  regu_p = regu_p->value.arithptr->rightptr;
7365  }
7366  }
7367  }
7368 
7369  /* set the flag for using extended form, but keep the single-column argument code too for being faster for its
7370  * particular case */
7371  if (regu_p->type != TYPE_CONSTANT)
7372  {
7373  use_extended = true;
7374  }
7375  else
7376  {
7377  arg_dbval_p = &arg_dbval;
7378  db_make_null (arg_dbval_p);
7379  }
7380 
7381  /* character */
7382  i = (int) strlen (DB_GET_STRING_SAFE (value_char));
7383  sep = (char *) db_private_alloc (thread_p, sizeof (char) * (i + 1));
7384  if (sep == NULL)
7385  {
7386  return false;
7387  }
7388  sep[0] = 0;
7389  if (i > 0)
7390  {
7391  strcpy (sep, DB_GET_STRING_SAFE (value_char));
7392  }
7393 
7394  /* walk the parents up to root */
7395 
7396  list_id_p = xptr->list_id;
7397 
7398  if (qfile_open_list_scan (list_id_p, &s_id) != NO_ERROR)
7399  {
7400  goto error2;
7401  }
7402 
7403  if (!use_extended)
7404  {
7405  /* column index */
7406  for (i = 0, valp = xptr->val_list->valp; valp; i++, valp = valp->next)
7407  {
7408  if (valp->val == regu_p->value.dbvalptr)
7409  {
7410  break;
7411  }
7412  }
7413 
7414  if (i >= xptr->val_list->val_cnt)
7415  {
7416  /* TYPE_CONSTANT but not in val_list, check if it is inst_num() (orderby_num() is not allowed) */
7417  if (regu_p->value.dbvalptr == xasl->instnum_val)
7418  {
7419  arg_dbval_p = xasl->instnum_val;
7420  }
7421  else
7422  {
7423  goto error;
7424  }
7425  }
7426  }
7427  else
7428  {
7429  /* save val_list */
7430  if (xptr->val_list->val_cnt > 0)
7431  {
7432  save_values = (DB_VALUE **) db_private_alloc (thread_p, sizeof (DB_VALUE *) * xptr->val_list->val_cnt);
7433  if (save_values == NULL)
7434  {
7435  goto error;
7436  }
7437 
7438  memset (save_values, 0, sizeof (DB_VALUE *) * xptr->val_list->val_cnt);
7439  for (i = 0, valp = xptr->val_list->valp; valp && i < xptr->val_list->val_cnt; i++, valp = valp->next)
7440  {
7441  save_values[i] = db_value_copy (valp->val);
7442  }
7443  }
7444  }
7445 
7446  /* we start with tpl itself */
7447  tuple_rec.tpl = tpl;
7448 
7449  len_result_path = SYS_CONNECT_BY_PATH_MEM_STEP;
7450  result_path = (char *) db_private_alloc (thread_p, sizeof (char) * len_result_path);
7451  if (result_path == NULL)
7452  {
7453  goto error;
7454  }
7455 
7456  strcpy (result_path, "");
7457 
7458  do
7459  {
7460  need_clear_arg_dbval = false;
7461  if (!use_extended)
7462  {
7463  /* get the required column */
7464  if (i < xptr->val_list->val_cnt)
7465  {
7466  if (qexec_get_tuple_column_value (tuple_rec.tpl, i, arg_dbval_p, regu_p->domain) != NO_ERROR)
7467  {
7468  goto error;
7469  }
7470  need_clear_arg_dbval = true;
7471  }
7472  }
7473  else
7474  {
7475  /* fetch value list */
7476  if (fetch_val_list (thread_p, xptr->proc.connect_by.regu_list_pred, vd, NULL, NULL, tuple_rec.tpl, PEEK) !=
7477  NO_ERROR)
7478  {
7479  goto error;
7480  }
7481  if (fetch_val_list (thread_p, xptr->proc.connect_by.regu_list_rest, vd, NULL, NULL, tuple_rec.tpl, PEEK) !=
7482  NO_ERROR)
7483  {
7484  goto error;
7485  }
7486 
7487  /* evaluate argument expression */
7488  if (fetch_peek_dbval (thread_p, regu_p, vd, NULL, NULL, tuple_rec.tpl, &arg_dbval_p) != NO_ERROR)
7489  {
7490  goto error;
7491  }
7492  }
7493 
7494  if (DB_IS_NULL (arg_dbval_p))
7495  {
7496  db_make_null (&cast_value);
7497  }
7498  else
7499  {
7500  /* cast result to string; this call also allocates the container */
7501  if (qdata_cast_to_domain (arg_dbval_p, &cast_value, &tp_String_domain) != NO_ERROR)
7502  {
7503  goto error;
7504  }
7505 
7506  if (need_clear_arg_dbval)
7507  {
7508  pr_clear_value (arg_dbval_p);
7509  need_clear_arg_dbval = false;
7510  }
7511  }
7512 
7513  len = (strlen (sep) + (DB_IS_NULL (&cast_value) ? 0 : db_get_string_size (&cast_value))
7514  + strlen (result_path) + 1);
7515  if (len > len_tmp || path_tmp == NULL)
7516  {
7517  /* free previously alloced */
7518  if (path_tmp)
7519  {
7520  db_private_free_and_init (thread_p, path_tmp);
7521  }
7522 
7523  len_tmp = len;
7524  path_tmp = (char *) db_private_alloc (thread_p, sizeof (char) * len_tmp);
7525  if (path_tmp == NULL)
7526  {
7527  pr_clear_value (&cast_value);
7528  goto error;
7529  }
7530  }
7531 
7532  strcpy (path_tmp, sep);
7533  strcat (path_tmp, DB_GET_STRING_SAFE (&cast_value));
7534 
7535  strcat (path_tmp, result_path);
7536 
7537  /* free the container for cast_value */
7538  if (pr_clear_value (&cast_value) != NO_ERROR)
7539  {
7540  goto error;
7541  }
7542 
7543  while ((int) strlen (path_tmp) + 1 > len_result_path)
7544  {
7545  len_result_path += SYS_CONNECT_BY_PATH_MEM_STEP;
7546  db_private_free_and_init (thread_p, result_path);
7547  result_path = (char *) db_private_alloc (thread_p, sizeof (char) * len_result_path);
7548  if (result_path == NULL)
7549  {
7550  goto error;
7551  }
7552  }
7553 
7554  strcpy (result_path, path_tmp);
7555 
7556  /* get the parent node */
7558  &p_pos_dbval, &tp_Bit_domain) != NO_ERROR)
7559  {
7560  goto error;
7561  }
7562 
7563  bitval = REINTERPRET_CAST (const QFILE_TUPLE_POSITION *, db_get_bit (&p_pos_dbval, &length));
7564 
7565  if (bitval)
7566  {
7567  p_pos.status = s_id.status;
7568  p_pos.position = S_ON;
7569  p_pos.vpid = bitval->vpid;
7570  p_pos.offset = bitval->offset;
7571  p_pos.tpl = NULL;
7572  p_pos.tplno = bitval->tplno;
7573 
7574  if (qfile_jump_scan_tuple_position (thread_p, &s_id, &p_pos, &tuple_rec, PEEK) != S_SUCCESS)
7575  {
7576  goto error;
7577  }
7578  }
7579  }
7580  while (bitval); /* the parent tuple pos is null for the root node */
7581 
7582  qfile_close_scan (thread_p, &s_id);
7583 
7584  db_make_string (result_p, result_path);
7585  result_p->need_clear = true;
7586 
7587  if (use_extended)
7588  {
7589  /* restore val_list */
7590  if (xptr->val_list->val_cnt > 0)
7591  {
7592  for (i = 0, valp = xptr->val_list->valp; valp && i < xptr->val_list->val_cnt; i++, valp = valp->next)
7593  {
7594  if (pr_clear_value (valp->val) != NO_ERROR)
7595  {
7596  goto error2;
7597  }
7598  if (pr_clone_value (save_values[i], valp->val) != NO_ERROR)
7599  {
7600  goto error2;
7601  }
7602  }
7603 
7604  for (i = 0; i < xptr->val_list->val_cnt; i++)
7605  {
7606  if (save_values[i])
7607  {
7608  if (pr_free_ext_value (save_values[i]) != NO_ERROR)
7609  {
7610  goto error2;
7611  }
7612  save_values[i] = NULL;
7613  }
7614  }
7615  db_private_free_and_init (thread_p, save_values);
7616  }
7617  }
7618 
7619  if (path_tmp)
7620  {
7621  db_private_free_and_init (thread_p, path_tmp);
7622  }
7623 
7624  if (sep)
7625  {
7626  db_private_free_and_init (thread_p, sep);
7627  }
7628 
7629  if (need_clear_arg_dbval)
7630  {
7631  pr_clear_value (arg_dbval_p);
7632  }
7633 
7634  return true;
7635 
7636 error:
7637  qfile_close_scan (thread_p, &s_id);
7638 
7639  if (save_values)
7640  {
7641  for (i = 0; i < xptr->val_list->val_cnt; i++)
7642  {
7643  if (save_values[i])
7644  {
7645  pr_free_ext_value (save_values[i]);
7646  }
7647  }
7648  db_private_free_and_init (thread_p, save_values);
7649  }
7650 
7651 error2:
7652  if (result_path)
7653  {
7654  db_private_free_and_init (thread_p, result_path);
7655  result_p->need_clear = false;
7656  }
7657 
7658  if (path_tmp)
7659  {
7660  db_private_free_and_init (thread_p, path_tmp);
7661  }
7662 
7663  if (sep)
7664  {
7665  db_private_free_and_init (thread_p, sep);
7666  }
7667 
7668  if (need_clear_arg_dbval)
7669  {
7670  pr_clear_value (arg_dbval_p);
7671  }
7672 
7673  return false;
7674 }
7675 
7676 /*
7677  * qdata_bit_not_dbval () - bitwise not
7678  * return: NO_ERROR, or ER_code
7679  * dbval_p(in) : db_value node
7680  * result_p(out) : resultant db_value node
7681  * domain_p(in) :
7682  *
7683  */
7684 int
7685 qdata_bit_not_dbval (DB_VALUE * dbval_p, DB_VALUE * result_p, tp_domain * domain_p)
7686 {
7687  DB_TYPE type;
7688 
7689  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval_p))
7690  {
7691  return NO_ERROR;
7692  }
7693 
7694  type = DB_VALUE_DOMAIN_TYPE (dbval_p);
7695 
7696  switch (type)
7697  {
7698  case DB_TYPE_NULL:
7699  db_make_null (result_p);
7700  break;
7701 
7702  case DB_TYPE_INTEGER:
7703  db_make_bigint (result_p, ~((INT64) db_get_int (dbval_p)));
7704  break;
7705 
7706  case DB_TYPE_BIGINT:
7707  db_make_bigint (result_p, ~db_get_bigint (dbval_p));
7708  break;
7709 
7710  case DB_TYPE_SHORT:
7711  db_make_bigint (result_p, ~((INT64) db_get_short (dbval_p)));
7712  break;
7713 
7714  default:
7717  }
7718 
7719  return NO_ERROR;
7720 }
7721 
7722 /*
7723  * qdata_bit_and_dbval () - bitwise and
7724  * return: NO_ERROR, or ER_code
7725  * dbval1_p(in) : first db_value node
7726  * dbval2_p(in) : second db_value node
7727  * result_p(out) : resultant db_value node
7728  * domain_p(in) :
7729  *
7730  */
7731 int
7732 qdata_bit_and_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
7733 {
7734  DB_TYPE type[2];
7735  DB_BIGINT bi[2];
7736  DB_VALUE *dbval[2];
7737  int i;
7738 
7739  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
7740  {
7741  return NO_ERROR;
7742  }
7743 
7744  type[0] = DB_VALUE_DOMAIN_TYPE (dbval1_p);
7745  type[1] = DB_VALUE_DOMAIN_TYPE (dbval2_p);
7746 
7747  dbval[0] = dbval1_p;
7748  dbval[1] = dbval2_p;
7749 
7750  for (i = 0; i < 2; i++)
7751  {
7752  switch (type[i])
7753  {
7754  case DB_TYPE_NULL:
7755  db_make_null (result_p);
7756  break;
7757 
7758  case DB_TYPE_INTEGER:
7759  bi[i] = (DB_BIGINT) db_get_int (dbval[i]);
7760  break;
7761 
7762  case DB_TYPE_BIGINT:
7763  bi[i] = db_get_bigint (dbval[i]);
7764  break;
7765 
7766  case DB_TYPE_SHORT:
7767  bi[i] = (DB_BIGINT) db_get_short (dbval[i]);
7768  break;
7769 
7770  default:
7773  }
7774  }
7775 
7776  if (type[0] != DB_TYPE_NULL && type[1] != DB_TYPE_NULL)
7777  {
7778  db_make_bigint (result_p, bi[0] & bi[1]);
7779  }
7780 
7781  return NO_ERROR;
7782 }
7783 
7784 /*
7785  * qdata_bit_or_dbval () - bitwise or
7786  * return: NO_ERROR, or ER_code
7787  * dbval1_p(in) : first db_value node
7788  * dbval2_p(in) : second db_value node
7789  * result_p(out) : resultant db_value node
7790  * domain_p(in) :
7791  *
7792  */
7793 int
7794 qdata_bit_or_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
7795 {
7796  DB_TYPE type[2];
7797  DB_BIGINT bi[2];
7798  DB_VALUE *dbval[2];
7799  int i;
7800 
7801  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
7802  {
7803  return NO_ERROR;
7804  }
7805 
7806  type[0] = DB_VALUE_DOMAIN_TYPE (dbval1_p);
7807  type[1] = DB_VALUE_DOMAIN_TYPE (dbval2_p);
7808 
7809  dbval[0] = dbval1_p;
7810  dbval[1] = dbval2_p;
7811 
7812  for (i = 0; i < 2; i++)
7813  {
7814  switch (type[i])
7815  {
7816  case DB_TYPE_NULL:
7817  db_make_null (result_p);
7818  break;
7819 
7820  case DB_TYPE_INTEGER:
7821  bi[i] = (DB_BIGINT) db_get_int (dbval[i]);
7822  break;
7823 
7824  case DB_TYPE_BIGINT:
7825  bi[i] = db_get_bigint (dbval[i]);
7826  break;
7827 
7828  case DB_TYPE_SHORT:
7829  bi[i] = (DB_BIGINT) db_get_short (dbval[i]);
7830  break;
7831 
7832  default:
7835  }
7836  }
7837 
7838  if (type[0] != DB_TYPE_NULL && type[1] != DB_TYPE_NULL)
7839  {
7840  db_make_bigint (result_p, bi[0] | bi[1]);
7841  }
7842 
7843  return NO_ERROR;
7844 }
7845 
7846 /*
7847  * qdata_bit_xor_dbval () - bitwise xor
7848  * return: NO_ERROR, or ER_code
7849  * dbval1_p(in) : first db_value node
7850  * dbval2_p(in) : second db_value node
7851  * result_p(out) : resultant db_value node
7852  * domain_p(in) :
7853  *
7854  */
7855 int
7856 qdata_bit_xor_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, DB_VALUE * result_p, tp_domain * domain_p)
7857 {
7858  DB_TYPE type[2];
7859  DB_BIGINT bi[2];
7860  DB_VALUE *dbval[2];
7861  int i;
7862 
7863  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
7864  {
7865  return NO_ERROR;
7866  }
7867 
7868  type[0] = DB_VALUE_DOMAIN_TYPE (dbval1_p);
7869  type[1] = DB_VALUE_DOMAIN_TYPE (dbval2_p);
7870 
7871  dbval[0] = dbval1_p;
7872  dbval[1] = dbval2_p;
7873 
7874  for (i = 0; i < 2; i++)
7875  {
7876  switch (type[i])
7877  {
7878  case DB_TYPE_NULL:
7879  db_make_null (result_p);
7880  break;
7881 
7882  case DB_TYPE_INTEGER:
7883  bi[i] = (DB_BIGINT) db_get_int (dbval[i]);
7884  break;
7885 
7886  case DB_TYPE_BIGINT:
7887  bi[i] = db_get_bigint (dbval[i]);
7888  break;
7889 
7890  case DB_TYPE_SHORT:
7891  bi[i] = (DB_BIGINT) db_get_short (dbval[i]);
7892  break;
7893 
7894  default:
7897  }
7898  }
7899 
7900  if (type[0] != DB_TYPE_NULL && type[1] != DB_TYPE_NULL)
7901  {
7902  db_make_bigint (result_p, bi[0] ^ bi[1]);
7903  }
7904 
7905  return NO_ERROR;
7906 }
7907 
7908 /*
7909  * qdata_bit_shift_dbval () - bitshift
7910  * return: NO_ERROR, or ER_code
7911  * dbval1_p(in) : first db_value node
7912  * dbval2_p(in) : second db_value node
7913  * result_p(out) : resultant db_value node
7914  * domain_p(in) :
7915  *
7916  */
7917 int
7918 qdata_bit_shift_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, OPERATOR_TYPE op, DB_VALUE * result_p,
7919  tp_domain * domain_p)
7920 {
7921  DB_TYPE type[2];
7922  DB_BIGINT bi[2];
7923  DB_VALUE *dbval[2];
7924  int i;
7925 
7926  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
7927  {
7928  return NO_ERROR;
7929  }
7930 
7931  type[0] = DB_VALUE_DOMAIN_TYPE (dbval1_p);
7932  type[1] = DB_VALUE_DOMAIN_TYPE (dbval2_p);
7933 
7934  dbval[0] = dbval1_p;
7935  dbval[1] = dbval2_p;
7936 
7937  for (i = 0; i < 2; i++)
7938  {
7939  switch (type[i])
7940  {
7941  case DB_TYPE_NULL:
7942  db_make_null (result_p);
7943  break;
7944 
7945  case DB_TYPE_INTEGER:
7946  bi[i] = (DB_BIGINT) db_get_int (dbval[i]);
7947  break;
7948 
7949  case DB_TYPE_BIGINT:
7950  bi[i] = db_get_bigint (dbval[i]);
7951  break;
7952 
7953  case DB_TYPE_SHORT:
7954  bi[i] = (DB_BIGINT) db_get_short (dbval[i]);
7955  break;
7956 
7957  default:
7960  }
7961  }
7962 
7963  if (type[0] != DB_TYPE_NULL && type[1] != DB_TYPE_NULL)
7964  {
7965  if (bi[1] < (DB_BIGINT) (sizeof (DB_BIGINT) * 8) && bi[1] >= 0)
7966  {
7967  if (op == T_BITSHIFT_LEFT)
7968  {
7969  db_make_bigint (result_p, ((UINT64) bi[0]) << ((UINT64) bi[1]));
7970  }
7971  else
7972  {
7973  db_make_bigint (result_p, ((UINT64) bi[0]) >> ((UINT64) bi[1]));
7974  }
7975  }
7976  else
7977  {
7978  db_make_bigint (result_p, 0);
7979  }
7980  }
7981 
7982  return NO_ERROR;
7983 }
7984 
7985 /*
7986  * qdata_divmod_dbval () - DIV/MOD operator
7987  * return: NO_ERROR, or ER_code
7988  * dbval1_p(in) : first db_value node
7989  * dbval2_p(in) : second db_value node
7990  * result_p(out) : resultant db_value node
7991  * domain_p(in) :
7992  *
7993  */
7994 int
7995 qdata_divmod_dbval (DB_VALUE * dbval1_p, DB_VALUE * dbval2_p, OPERATOR_TYPE op, DB_VALUE * result_p,
7996  tp_domain * domain_p)
7997 {
7998  DB_TYPE type[2];
7999  DB_BIGINT bi[2];
8000  DB_VALUE *dbval[2];
8001  int i;
8002 
8003  if ((domain_p != NULL && TP_DOMAIN_TYPE (domain_p) == DB_TYPE_NULL) || DB_IS_NULL (dbval1_p) || DB_IS_NULL (dbval2_p))
8004  {
8005  return NO_ERROR;
8006  }
8007 
8008  type[0] = DB_VALUE_DOMAIN_TYPE (dbval1_p);
8009  type[1] = DB_VALUE_DOMAIN_TYPE (dbval2_p);
8010 
8011  dbval[0] = dbval1_p;
8012  dbval[1] = dbval2_p;
8013 
8014  for (i = 0; i < 2; i++)
8015  {
8016  switch (type[i])
8017  {
8018  case DB_TYPE_NULL:
8019  db_make_null (result_p);
8020  break;
8021 
8022  case DB_TYPE_INTEGER:
8023  bi[i] = (DB_BIGINT) db_get_int (dbval[i]);
8024  break;
8025 
8026  case DB_TYPE_BIGINT:
8027  bi[i] = db_get_bigint (dbval[i]);
8028  break;
8029 
8030  case DB_TYPE_SHORT:
8031  bi[i] = (DB_BIGINT) db_get_short (dbval[i]);
8032  break;
8033 
8034  default:
8037  }
8038  }
8039 
8040  if (type[0] != DB_TYPE_NULL && type[1] != DB_TYPE_NULL)
8041  {
8042  if (bi[1] != 0)
8043  {
8044  if (op == T_INTDIV)
8045  {
8046  if (type[0] == DB_TYPE_INTEGER)
8047  {
8048  if (OR_CHECK_INT_DIV_OVERFLOW (bi[0], bi[1]))
8049  {
8052  }
8053  db_make_int (result_p, (INT32) (bi[0] / bi[1]));
8054  }
8055  else if (type[0] == DB_TYPE_BIGINT)
8056  {
8057  if (OR_CHECK_BIGINT_DIV_OVERFLOW (bi[0], bi[1]))
8058  {
8061  }
8062  db_make_bigint (result_p, bi[0] / bi[1]);
8063  }
8064  else
8065  {
8066  if (OR_CHECK_SHORT_DIV_OVERFLOW (bi[0], bi[1]))
8067  {
8070  }
8071  db_make_short (result_p, (INT16) (bi[0] / bi[1]));
8072  }
8073  }
8074  else
8075  {
8076  if (type[0] == DB_TYPE_INTEGER)
8077  {
8078  db_make_int (result_p, (INT32) (bi[0] % bi[1]));
8079  }
8080  else if (type[0] == DB_TYPE_BIGINT)
8081  {
8082  db_make_bigint (result_p, bi[0] % bi[1]);
8083  }
8084  else
8085  {
8086  db_make_short (result_p, (INT16) (bi[0] % bi[1]));
8087  }
8088  }
8089  }
8090  else
8091  {
8093  return ER_QPROC_ZERO_DIVIDE;
8094  }
8095  }
8096 
8097  return NO_ERROR;
8098 }
8099 
8100 /*
8101  * qdata_list_dbs () - lists all databases names
8102  * return: NO_ERROR, or ER_code
8103  * result_p(out) : resultant db_value node
8104  * domain(in): domain
8105  */
8106 int
8107 qdata_list_dbs (THREAD_ENTRY * thread_p, DB_VALUE * result_p, tp_domain * domain_p)
8108 {
8109  DB_INFO *db_info_p;
8110 
8111  if (cfg_read_directory (&db_info_p, false) != NO_ERROR)
8112  {
8113  if (er_errid () == NO_ERROR)
8114  {
8116  }
8117  goto error;
8118  }
8119 
8120  if (db_info_p)
8121  {
8122  DB_INFO *list_p;
8123  char *name_list;
8124  size_t name_list_size = 0;
8125  bool is_first;
8126 
8127  for (list_p = db_info_p; list_p != NULL; list_p = list_p->next)
8128  {
8129  if (list_p->name)
8130  {
8131  name_list_size += strlen (list_p->name) + 1;
8132  }
8133  }
8134 
8135  if (name_list_size != 0)
8136  {
8137  name_list = (char *) db_private_alloc (thread_p, name_list_size);
8138  if (name_list == NULL)
8139  {
8140  cfg_free_directory (db_info_p);
8141  goto error;
8142  }
8143  strcpy (name_list, "");
8144 
8145  for (list_p = db_info_p, is_first = true; list_p != NULL; list_p = list_p->next)
8146  {
8147  if (list_p->name)
8148  {
8149  if (!is_first)
8150  {
8151  strcat (name_list, " ");
8152  }
8153  else
8154  {
8155  is_first = false;
8156  }
8157  strcat (name_list, list_p->name);
8158  }
8159  }
8160 
8161  cfg_free_directory (db_info_p);
8162 
8163  if (db_make_string (result_p, name_list) != NO_ERROR)
8164  {
8165  goto error;
8166  }
8167  result_p->need_clear = true;
8168  }
8169  else
8170  {
8171  cfg_free_directory (db_info_p);
8172  db_make_null (result_p);
8173  }
8174 
8175  if (domain_p != NULL)
8176  {
8177  assert (TP_DOMAIN_TYPE (domain_p) == DB_VALUE_TYPE (result_p));
8178 
8179  db_string_put_cs_and_collation (result_p, TP_DOMAIN_CODESET (domain_p), TP_DOMAIN_COLLATION (domain_p));
8180  }
8181  }
8182  else
8183  {
8184  db_make_null (result_p);
8185  }
8186 
8187  return NO_ERROR;
8188 
8189 error:
8190  assert (er_errid () != NO_ERROR);
8191  return er_errid ();
8192 }
8193 
8194 /*
8195  * qdata_regu_list_to_regu_array () - extracts the regu variables from
8196  * function list to an array. Array must be
8197  * allocated by caller
8198  * return: NO_ERROR, or ER_FAILED code
8199  * funcp(in) : function structure pointer
8200  * array_size(in) : max size of array (in number of entries)
8201  * regu_array(out) : array of pointers to regu-vars
8202  * num_regu : number of regu vars actually found in list
8203  */
8204 
8205 int
8206 qdata_regu_list_to_regu_array (function_node * function_p, const int array_size, regu_variable_node * regu_array[],
8207  int *num_regu)
8208 {
8209  REGU_VARIABLE_LIST operand = function_p->operand;
8210  int i, num_args = 0;
8211 
8212 
8213  assert (array_size > 0);
8214  assert (regu_array != NULL);
8215  assert (function_p != NULL);
8216  assert (num_regu != NULL);
8217 
8218  *num_regu = 0;
8219  /* initialize the argument array */
8220  for (i = 0; i < array_size; i++)
8221  {
8222  regu_array[i] = NULL;
8223  }
8224 
8225  while (operand)
8226  {
8227  if (num_args >= array_size)
8228  {
8229  return ER_FAILED;
8230  }
8231 
8232  regu_array[num_args] = &operand->value;
8233  *num_regu = ++num_args;
8234  operand = operand->next;
8235  }
8236  return NO_ERROR;
8237 }
8238 
8239 /*
8240  * qdata_insert_substring_function () - Evaluates insert() function.
8241  * return: NO_ERROR, or ER_FAILED code
8242  * thread_p : thread context
8243  * funcp(in) : function structure pointer
8244  * vd(in) : value descriptor
8245  * obj_oid(in): object identifier
8246  * tpl(in) : tuple
8247  */
8248 static int
8250  OID * obj_oid_p, QFILE_TUPLE tuple)
8251 {
8254  int i, error_status = NO_ERROR;
8255  int num_regu = 0;
8256 
8257  /* initialize the argument array */
8258  for (i = 0; i < NUM_F_INSERT_SUBSTRING_ARGS; i++)
8259  {
8260  args[i] = NULL;
8261  regu_array[i] = NULL;
8262  }
8263 
8264  error_status = qdata_regu_list_to_regu_array (function_p, NUM_F_INSERT_SUBSTRING_ARGS, regu_array, &num_regu);
8265  if (num_regu != NUM_F_INSERT_SUBSTRING_ARGS)
8266  {
8267  assert (false);
8269  goto error;
8270  }
8271  if (error_status != NO_ERROR)
8272  {
8273  goto error;
8274  }
8275 
8276  for (i = 0; i < NUM_F_INSERT_SUBSTRING_ARGS; i++)
8277  {
8278  error_status = fetch_peek_dbval (thread_p, regu_array[i], val_desc_p, NULL, obj_oid_p, tuple, &args[i]);
8279  if (error_status != NO_ERROR)
8280  {
8281  goto error;
8282  }
8283  }
8284 
8285  error_status = db_string_insert_substring (args[0], args[1], args[2], args[3], function_p->value);
8286  if (error_status != NO_ERROR)
8287  {
8288  goto error;
8289  }
8290 
8291  return NO_ERROR;
8292 
8293 error:
8294  /* no error message set, keep message already set */
8295  return ER_FAILED;
8296 }
8297 
8298 /*
8299  * qdata_elt() - returns the argument with the index in the parameter list
8300  * equal to the value passed in the first argument. Returns
8301  * NULL if the first arguments is NULL, is 0, is negative or is
8302  * greater than the number of the other arguments.
8303  */
8304 static int
8305 qdata_elt (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p, OID * obj_oid_p,
8306  QFILE_TUPLE tuple)
8307 {
8308  DB_VALUE *index = NULL;
8309  REGU_VARIABLE_LIST operand;
8310  int error_status = NO_ERROR;
8311  DB_TYPE index_type;
8312  DB_BIGINT idx = 0;
8313  DB_VALUE *operand_value = NULL;
8314 
8315  /* should sync with fetch_peek_dbval () */
8316 
8317  assert (function_p);
8318  assert (function_p->value);
8319  assert (function_p->operand);
8320 
8321  error_status = fetch_peek_dbval (thread_p, &function_p->operand->value, val_desc_p, NULL, obj_oid_p, tuple, &index);
8322  if (error_status != NO_ERROR)
8323  {
8324  goto error_exit;
8325  }
8326 
8327  index_type = DB_VALUE_DOMAIN_TYPE (index);
8328 
8329  switch (index_type)
8330  {
8331  case DB_TYPE_SMALLINT:
8332  idx = db_get_short (index);
8333  break;
8334  case DB_TYPE_INTEGER:
8335  idx = db_get_int (index);
8336  break;
8337  case DB_TYPE_BIGINT:
8338  idx = db_get_bigint (index);
8339  break;
8340  case DB_TYPE_NULL:
8341  db_make_null (function_p->value);
8342  goto fast_exit;
8343  default:
8345  error_status = ER_QPROC_INVALID_DATATYPE;
8346  goto error_exit;
8347  }
8348 
8349  if (idx <= 0)
8350  {
8351  /* index is 0 or is negative */
8352  db_make_null (function_p->value);
8353  goto fast_exit;
8354  }
8355 
8356  idx--;
8357  operand = function_p->operand->next;
8358 
8359  while (idx > 0 && operand != NULL)
8360  {
8361  operand = operand->next;
8362  idx--;
8363  }
8364 
8365  if (operand == NULL)
8366  {
8367  /* index greater than number of arguments */
8368  db_make_null (function_p->value);
8369  goto fast_exit;
8370  }
8371 
8372  error_status = fetch_peek_dbval (thread_p, &operand->value, val_desc_p, NULL, obj_oid_p, tuple, &operand_value);
8373  if (error_status != NO_ERROR)
8374  {
8375  goto error_exit;
8376  }
8377 
8378  /*
8379  * operand should already be cast to the right type (CHAR
8380  * or NCHAR VARYING)
8381  */
8382  error_status = pr_clone_value (operand_value, function_p->value);
8383 
8384 fast_exit:
8385  return error_status;
8386 
8387 error_exit:
8388  return error_status;
8389 }
8390 
8391 //
8392 // qdata_benchmark () - "benchmark" function execution; repeatedly run nested operation
8393 //
8394 static int
8395 qdata_benchmark (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p, OID * obj_oid_p,
8396  QFILE_TUPLE tuple)
8397 {
8398  assert (function_p);
8399 
8400  if (function_p == NULL || function_p->operand == NULL || function_p->operand->next == NULL)
8401  {
8402  assert_release (false);
8403  return ER_FAILED;
8404  }
8405 
8406  if (function_p->value == NULL)
8407  {
8408  assert_release (false);
8409  return ER_FAILED;
8410  }
8411 
8412  db_make_null (function_p->value);
8413 
8414  REGU_VARIABLE *count_reguvar = &function_p->operand->value;
8415  REGU_VARIABLE *target_reguvar = &function_p->operand->next->value;
8416 
8417  DB_VALUE *count_value = NULL;
8418  DB_VALUE *target_value = NULL;
8419 
8420  int error = fetch_peek_dbval (thread_p, count_reguvar, val_desc_p, NULL, obj_oid_p, tuple, &count_value);
8421  if (error != NO_ERROR)
8422  {
8423  ASSERT_ERROR ();
8424  return error;
8425  }
8426 
8427  if (db_value_is_null (count_value))
8428  {
8429  return NO_ERROR;
8430  }
8431 
8432  INT64 count = 0;
8433 
8434  switch (db_value_domain_type (count_value))
8435  {
8436  case DB_TYPE_SMALLINT:
8437  count = STATIC_CAST (INT64, db_get_short (count_value));
8438  break;
8439  case DB_TYPE_INTEGER:
8440  count = STATIC_CAST (INT64, db_get_int (count_value));
8441  break;
8442  case DB_TYPE_BIGINT:
8443  count = db_get_bigint (count_value);
8444  break;
8445  default:
8446  assert (false);
8447  return ER_FAILED;
8448  }
8449 
8450  if (count <= 0)
8451  {
8453  return ER_OBJ_INVALID_ARGUMENTS;
8454  }
8455 
8456  using bench_clock = std::chrono::system_clock;
8457  bench_clock::time_point start_timept = bench_clock::now ();
8458 
8459  for (INT64 step = 0; step < count; step++)
8460  {
8461  // we're trying to benchmark the expression in target reguvar by running it many times. even if all operands are
8462  // constant, we still have to repeat the operations. for that, we need to make sure nested regu variables are not
8463  // flagged as constants
8464  //
8465  // node that they still may be other optimizations that are not so easily disabled
8466  fetch_force_not_const_recursive (*target_reguvar);
8467  error = fetch_peek_dbval (thread_p, target_reguvar, val_desc_p, NULL, obj_oid_p, tuple, &target_value);
8468  if (error != NO_ERROR)
8469  {
8470  ASSERT_ERROR ();
8471  return error;
8472  }
8473  pr_clear_value (target_value);
8474  }
8475 
8476  bench_clock::time_point end_timept = bench_clock::now ();
8477  std::chrono::duration < double >secs = end_timept - start_timept;
8478 
8479  db_make_double (function_p->value, secs.count ());
8480  return NO_ERROR;
8481 }
8482 
8483 /*
8484  * qdata_regexp_function () - Evaluates regexp related functions.
8485  * return: NO_ERROR, or ER_FAILED code
8486  * thread_p : thread context
8487  * funcp(in) : function structure pointer
8488  * vd(in) : value descriptor
8489  * obj_oid(in): object identifier
8490  * tpl(in) : tuple
8491  */
8492 static int
8493 qdata_regexp_function (THREAD_ENTRY * thread_p, FUNCTION_TYPE * function_p, VAL_DESCR * val_desc_p,
8494  OID * obj_oid_p, QFILE_TUPLE tuple)
8495 {
8496  DB_VALUE *value;
8497  REGU_VARIABLE_LIST operand;
8498  int error_status = NO_ERROR;
8499  int no_args = 0, index = 0;
8500  DB_VALUE **args;
8501 
8502  {
8503  assert (function_p != NULL);
8504  assert (function_p->value != NULL);
8505  assert (function_p->operand != NULL);
8506 
8507  operand = function_p->operand;
8508 
8509  while (operand != NULL)
8510  {
8511  no_args++;
8512  operand = operand->next;
8513  }
8514 
8515  args = (DB_VALUE **) db_private_alloc (thread_p, sizeof (DB_VALUE *) * no_args);
8516 
8517  operand = function_p->operand;
8518  while (operand != NULL)
8519  {
8520  error_status = fetch_peek_dbval (thread_p, &operand->value, val_desc_p, NULL, obj_oid_p, tuple, &value);
8521  if (error_status != NO_ERROR)
8522  {
8523  goto exit;
8524  }
8525 
8526  args[index++] = value;
8527 
8528  operand = operand->next;
8529  }
8530 
8531  assert (index == no_args);
8532 
8533  // *INDENT-OFF*
8534  std::function<int(DB_VALUE*, DB_VALUE*[], const int, cub_regex_object**, char**)> regexp_func;
8535  switch (function_p->ftype)
8536  {
8537  case F_REGEXP_COUNT:
8538  regexp_func = db_string_regexp_count;
8539  break;
8540  case F_REGEXP_INSTR:
8541  regexp_func = db_string_regexp_instr;
8542  break;
8543  case F_REGEXP_LIKE:
8544  regexp_func = db_string_regexp_like;
8545  break;
8546  case F_REGEXP_REPLACE:
8547  regexp_func = db_string_regexp_replace;
8548  break;
8549  case F_REGEXP_SUBSTR:
8550  regexp_func = db_string_regexp_substr;
8551  break;
8552  default:
8553  assert (false);
8554  break;
8555  }
8556  // *INDENT-ON*
8557 
8558  if (function_p->tmp_obj == NULL)
8559  {
8560  function_p->tmp_obj = new function_tmp_obj;
8561  function_p->tmp_obj->compiled_regex = new cub_compiled_regex ();
8562  }
8563 
8564  cub_compiled_regex *compiled_regex = function_p->tmp_obj->compiled_regex;
8565  error_status = regexp_func (function_p->value, args, no_args, &compiled_regex->regex, &compiled_regex->pattern);
8566  if (error_status != NO_ERROR)
8567  {
8568  goto exit;
8569  }
8570  }
8571 
8572 exit:
8573  db_private_free (thread_p, args);
8574  return error_status;
8575 }
8576 
8577 static int
8579  OID * obj_oid_p, QFILE_TUPLE tuple,
8580  int (*function_to_call) (DB_VALUE *, DB_VALUE * const *, int const))
8581 {
8582  DB_VALUE *value;
8583  REGU_VARIABLE_LIST operand;
8584  int error_status = NO_ERROR;
8585  int no_args = 0, index = 0;
8586  DB_VALUE **args;
8587 
8588  /* should sync with fetch_peek_dbval () */
8589 
8590  assert (function_p != NULL);
8591  assert (function_p->value != NULL);
8592  assert (function_p->operand != NULL);
8593 
8594  operand = function_p->operand;
8595 
8596  while (operand != NULL)
8597  {
8598  no_args++;
8599  operand = operand->next;
8600  }
8601 
8602  args = (DB_VALUE **) db_private_alloc (thread_p, sizeof (DB_VALUE *) * no_args);
8603 
8604  operand = function_p->operand;
8605  while (operand != NULL)
8606  {
8607  error_status = fetch_peek_dbval (thread_p, &operand->value, val_desc_p, NULL, obj_oid_p, tuple, &value);
8608  if (error_status != NO_ERROR)
8609  {
8610  goto exit;
8611  }
8612 
8613  args[index++] = value;
8614 
8615  operand = operand->next;
8616  }
8617 
8618  assert (index == no_args);
8619 
8620  error_status = function_to_call (function_p->value, args, no_args);
8621  if (error_status != NO_ERROR)
8622  {
8623  goto exit;
8624  }
8625 
8626 exit:
8627  db_private_free (thread_p, args);
8628  return error_status;
8629 }
8630 
8631 /*
8632  * qdata_get_cardinality () - gets the cardinality of an index using its name
8633  * and partial key count
8634  * return: NO_ERROR, or error code
8635  * thread_p(in) : thread context
8636  * db_class_name(in): string DB_VALUE holding name of class
8637  * db_index_name(in): string DB_VALUE holding name of index (as it appears
8638  * in '_db_index' system catalog table
8639  * db_key_position(in): integer DB_VALUE holding the partial key index
8640  * result_p(out) : cardinality (integer or NULL DB_VALUE)
8641  */
8642 int
8643 qdata_get_cardinality (THREAD_ENTRY * thread_p, DB_VALUE * db_class_name, DB_VALUE * db_index_name,
8644  DB_VALUE * db_key_position, DB_VALUE * result_p)
8645 {
8646  char class_name[SM_MAX_IDENTIFIER_LENGTH];
8647  char index_name[SM_MAX_IDENTIFIER_LENGTH];
8648  int key_pos = 0;
8649  int cardinality = 0;
8650  int error = NO_ERROR;
8651  DB_TYPE cl_name_arg_type;
8652  DB_TYPE idx_name_arg_type;
8653  DB_TYPE key_pos_arg_type;
8654  int str_class_name_len;
8655  int str_index_name_len;
8656 
8657  db_make_null (result_p);
8658 
8659  cl_name_arg_type = DB_VALUE_DOMAIN_TYPE (db_class_name);
8660  idx_name_arg_type = DB_VALUE_DOMAIN_TYPE (db_index_name);
8661  key_pos_arg_type = DB_VALUE_DOMAIN_TYPE (db_key_position);
8662 
8663  if (DB_IS_NULL (db_class_name) || DB_IS_NULL (db_index_name) || DB_IS_NULL (db_key_position))
8664  {
8665  goto exit;
8666  }
8667 
8668  if (!QSTR_IS_CHAR (cl_name_arg_type) || !QSTR_IS_CHAR (idx_name_arg_type) || key_pos_arg_type != DB_TYPE_INTEGER)
8669  {
8670  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_UNEXPECTED, 1, "Arguments type mismatching.");
8671  error = ER_UNEXPECTED;
8672  goto exit;
8673  }
8674 
8675  str_class_name_len = MIN (SM_MAX_IDENTIFIER_LENGTH - 1, db_get_string_size (db_class_name));
8676  strncpy (class_name, db_get_string (db_class_name), str_class_name_len);
8677  class_name[str_class_name_len] = '\0';
8678 
8679  str_index_name_len = MIN (SM_MAX_IDENTIFIER_LENGTH - 1, db_get_string_size (db_index_name));
8680  strncpy (index_name, db_get_string (db_index_name), str_index_name_len);
8681  index_name[str_index_name_len] = '\0';
8682 
8683  key_pos = db_get_int (db_key_position);
8684 
8685  error = catalog_get_cardinality_by_name (thread_p, class_name, index_name, key_pos, &cardinality);
8686  if (error == NO_ERROR)
8687  {
8688  if (cardinality < 0)
8689  {
8690  db_make_null (result_p);
8691  }
8692  else
8693  {
8694  db_make_int (result_p, cardinality);
8695  }
8696  }
8697 
8698 exit:
8699  return error;
8700 }
8701 
8702 /*
8703  * qdata_tuple_to_values_array () - construct an array of values from a
8704  * tuple descriptor
8705  * return : error code or NO_ERROR
8706  * thread_p (in) : thread entry
8707  * tuple (in) : tuple descriptor
8708  * values (in/out) : values array
8709  *
8710  * Note: Values are cloned in the values array
8711  */
8712 int
8714 {
8715  DB_VALUE *vals;
8716  int error = NO_ERROR, i;
8717 
8718  assert_release (tuple != NULL);
8719  assert_release (values != NULL);
8720 
8721  vals = (DB_VALUE *) db_private_alloc (thread_p, tuple->f_cnt * sizeof (DB_VALUE));
8722  if (vals == NULL)
8723  {
8724  error = ER_FAILED;
8725  goto error_return;
8726  }
8727 
8728  for (i = 0; i < tuple->f_cnt; i++)
8729  {
8730  error = pr_clone_value (tuple->f_valp[i], &vals[i]);
8731  if (error != NO_ERROR)
8732  {
8733  goto error_return;
8734  }
8735  }
8736 
8737  *values = vals;
8738  return NO_ERROR;
8739 
8740 error_return:
8741  if (vals != NULL)
8742  {
8743  int j;
8744  for (j = 0; j < i; j++)
8745  {
8746  pr_clear_value (&vals[j]);
8747  }
8748  db_private_free (thread_p, vals);
8749  }
8750  *values = NULL;
8751  return error;
8752 }
8753 
8754 /*
8755  * qdata_apply_interpolation_function_coercion () - coerce input value for use in
8756  * MEDIAN function evaluation
8757  * returns: error code or NO_ERROR
8758  * f_value(in): input value
8759  * result_dom(in/out): result domain
8760  * d_result(out): result as double precision floating point value
8761  * result(out): result as DB_VALUE
8762  */
8763 int
8765  FUNC_TYPE function)
8766 {
8767  DB_TYPE type;
8768  double d_result = 0;
8769  int error = NO_ERROR;
8770 
8771  assert (f_value != NULL && result_dom != NULL && result != NULL);
8772 
8773  /* update result */
8774  type = db_value_type (f_value);
8775  switch (type)
8776  {
8777  case DB_TYPE_SHORT:
8778  case DB_TYPE_INTEGER:
8779  case DB_TYPE_BIGINT:
8780  case DB_TYPE_FLOAT:
8781  case DB_TYPE_DOUBLE:
8782  case DB_TYPE_MONETARY:
8783  case DB_TYPE_NUMERIC:
8784  /* percentile_disc returns the same type as operand while median and percentile_cont return double */
8785  if (function != PT_PERCENTILE_DISC)
8786  {
8787  if (type == DB_TYPE_SHORT)
8788  {
8789  d_result = (double) db_get_short (f_value);
8790  }
8791  else if (type == DB_TYPE_INTEGER)
8792  {
8793  d_result = (double) db_get_int (f_value);
8794  }
8795  else if (type == DB_TYPE_BIGINT)
8796  {
8797  d_result = (double) db_get_bigint (f_value);
8798  }
8799  else if (type == DB_TYPE_FLOAT)
8800  {
8801  d_result = (double) db_get_float (f_value);
8802  }
8803  else if (type == DB_TYPE_DOUBLE)
8804  {
8805  d_result = (double) db_get_double (f_value);
8806  }
8807  else if (type == DB_TYPE_MONETARY)
8808  {
8809  d_result = (db_get_monetary (f_value))->amount;
8810  }
8811  else if (type == DB_TYPE_NUMERIC)
8812  {
8813  numeric_coerce_num_to_double (db_locate_numeric (f_value), DB_VALUE_SCALE (f_value), &d_result);
8814  }
8815 
8816  db_make_double (result, d_result);
8817  }
8818  else
8819  {
8820  pr_clone_value (f_value, result);
8821  }
8822 
8823  break;
8824 
8825  case DB_TYPE_DATE:
8826  case DB_TYPE_DATETIME:
8827  case DB_TYPE_DATETIMELTZ:
8828  case DB_TYPE_DATETIMETZ:
8829  case DB_TYPE_TIMESTAMP:
8830  case DB_TYPE_TIMESTAMPLTZ:
8831  case DB_TYPE_TIMESTAMPTZ:
8832  case DB_TYPE_TIME:
8833  pr_clone_value (f_value, result);
8834  break;
8835 
8836  default:
8837  type = TP_DOMAIN_TYPE (*result_dom);
8838  if (!TP_IS_NUMERIC_TYPE (type) && !TP_IS_DATE_OR_TIME_TYPE (type))
8839  {
8840  error = qdata_update_interpolation_func_value_and_domain (f_value, result, result_dom);
8841  if (error != NO_ERROR)
8842  {
8844 
8846  "DOUBLE, DATETIME, TIME");
8847 
8848  error = ER_FAILED;
8849  goto end;
8850  }
8851  }
8852  else
8853  {
8854  error = db_value_coerce (f_value, result, *result_dom);
8855  if (error != NO_ERROR)
8856  {
8857  error = ER_FAILED;
8858  goto end;
8859  }
8860  }
8861  }
8862 
8863 end:
8864  return error;
8865 }
8866 
8867 /*
8868  * qdata_interpolation_function_values () - interpolate two values for use
8869  * in MEDIAN function evaluation
8870  * returns: error code or NO_ERROR
8871  * f_value(in): "floor" value (i.e. first value in tuple order)
8872  * c_value(in): "ceiling" value (i.e. second value in tuple order)
8873  * row_num_d(in): row number as floating point value
8874  * f_row_num_d(in): row number of f_value as floating point value
8875  * c_row_num_d(in): row number of c_value as floating point value
8876  * result_dom(in/out): result domain
8877  * d_result(out): result as double precision floating point value
8878  * result(out): result as DB_VALUE
8879  */
8880 int
8881 qdata_interpolation_function_values (DB_VALUE * f_value, DB_VALUE * c_value, double row_num_d, double f_row_num_d,
8882  double c_row_num_d, tp_domain ** result_dom, DB_VALUE * result, FUNC_TYPE function)
8883 {
8884  DB_DATE date;
8885  DB_DATETIME datetime;
8886  DB_TIMESTAMP utime;
8887  DB_TIME time;
8888  DB_TYPE type;
8889  double d1, d2;
8890  double d_result;
8891  int error = NO_ERROR;
8892 
8893  assert (f_value != NULL && c_value != NULL && result_dom != NULL && result != NULL);
8894 
8895  /* calculate according to type The formular bellow is from Oracle's MEDIAN manual result = (CRN - RN) * (value for
8896  * row at FRN) + (RN - FRN) * (value for row at CRN) */
8897  type = db_value_type (f_value);
8898  if (!TP_IS_NUMERIC_TYPE (type) && !TP_IS_DATE_OR_TIME_TYPE (type))
8899  {
8900  type = TP_DOMAIN_TYPE (*result_dom);
8901  if (!TP_IS_NUMERIC_TYPE (type) && !TP_IS_DATE_OR_TIME_TYPE (type))
8902  {
8903  /* try to coerce f_value to double, datetime then time and save domain for next coerce */
8904  error = qdata_update_interpolation_func_value_and_domain (f_value, f_value, result_dom);
8905  if (error != NO_ERROR)
8906  {
8908 
8910  "DOUBLE, DATETIME, TIME");
8911 
8912  error = ER_FAILED;
8913  goto end;
8914  }
8915  }
8916  else
8917  {
8918  error = db_value_coerce (f_value, f_value, *result_dom);
8919  if (error != NO_ERROR)
8920  {
8921  error = ER_FAILED;
8922  goto end;
8923  }
8924  }
8925 
8926  /* coerce c_value */
8927  error = db_value_coerce (c_value, c_value, *result_dom);
8928  if (error != NO_ERROR)
8929  {
8930  error = ER_FAILED;
8931  goto end;
8932  }
8933  }
8934 
8935  type = db_value_type (f_value);
8936  switch (type)
8937  {
8938  case DB_TYPE_SHORT:
8939  d1 = (double) db_get_short (f_value);
8940  d2 = (double) db_get_short (c_value);
8941 
8942  /* calculate */
8943  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
8944 
8945  db_make_double (result, d_result);
8946 
8947  break;
8948 
8949  case DB_TYPE_INTEGER:
8950  d1 = (double) db_get_int (f_value);
8951  d2 = (double) db_get_int (c_value);
8952 
8953  /* calculate */
8954  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
8955 
8956  db_make_double (result, d_result);
8957 
8958  break;
8959 
8960  case DB_TYPE_BIGINT:
8961  d1 = (double) db_get_bigint (f_value);
8962  d2 = (double) db_get_bigint (c_value);
8963 
8964  /* calculate */
8965  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
8966 
8967  db_make_double (result, d_result);
8968 
8969  break;
8970 
8971  case DB_TYPE_FLOAT:
8972  d1 = (double) db_get_float (f_value);
8973  d2 = (double) db_get_float (c_value);
8974 
8975  /* calculate */
8976  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
8977 
8978  db_make_double (result, d_result);
8979 
8980  break;
8981 
8982  case DB_TYPE_DOUBLE:
8983  d1 = db_get_double (f_value);
8984  d2 = db_get_double (c_value);
8985 
8986  /* calculate */
8987  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
8988 
8989  db_make_double (result, d_result);
8990 
8991  break;
8992 
8993  case DB_TYPE_MONETARY:
8994  d1 = (db_get_monetary (f_value))->amount;
8995  d2 = (db_get_monetary (c_value))->amount;
8996 
8997  /* calculate */
8998  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
8999 
9000  db_make_double (result, d_result);
9001 
9002  break;
9003 
9004  case DB_TYPE_NUMERIC:
9007 
9008  /* calculate */
9009  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
9010 
9011  db_make_double (result, d_result);
9012 
9013  break;
9014 
9015  case DB_TYPE_DATE:
9016  d1 = (double) *(db_get_date (f_value));
9017  d2 = (double) *(db_get_date (c_value));
9018  d_result = (c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2;
9019 
9020  date = (DB_DATE) floor (d_result);
9021 
9022  db_value_put_encoded_date (result, &date);
9023 
9024  break;
9025 
9026  case DB_TYPE_DATETIME:
9027  case DB_TYPE_DATETIMELTZ:
9028  case DB_TYPE_DATETIMETZ:
9029  if (type == DB_TYPE_DATETIMETZ)
9030  {
9031  datetime = db_get_datetimetz (f_value)->datetime;
9032  }
9033  else
9034  {
9035  datetime = *(db_get_datetime (f_value));
9036  }
9037 
9038  d1 = ((double) datetime.date) * MILLISECONDS_OF_ONE_DAY + datetime.time;
9039 
9040  if (type == DB_TYPE_DATETIMETZ)
9041  {
9042  datetime = db_get_datetimetz (c_value)->datetime;
9043  }
9044  else
9045  {
9046  datetime = *(db_get_datetime (c_value));
9047  }
9048 
9049  d2 = ((double) datetime.date) * MILLISECONDS_OF_ONE_DAY + datetime.time;
9050 
9051  d_result = floor ((c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2);
9052 
9053  datetime.date = (unsigned int) (d_result / MILLISECONDS_OF_ONE_DAY);
9054  datetime.time = (unsigned int) (((DB_BIGINT) d_result) % MILLISECONDS_OF_ONE_DAY);
9055 
9056  if (type == DB_TYPE_DATETIME)
9057  {
9058  db_make_datetime (result, &datetime);
9059  }
9060  else if (type == DB_TYPE_DATETIMELTZ)
9061  {
9062  db_make_datetimeltz (result, &datetime);
9063  }
9064  else
9065  {
9066  DB_DATETIMETZ dttz1, dttz2;
9067 
9068  /* if the two timezones are different, we use the first timezone */
9069  dttz1.datetime = datetime;
9070  dttz1.tz_id = db_get_datetimetz (f_value)->tz_id;
9071 
9072  error = tz_datetimetz_fix_zone (&dttz1, &dttz2);
9073  if (error != NO_ERROR)
9074  {
9075  error = ER_FAILED;
9076  goto end;
9077  }
9078 
9079  db_make_datetimetz (result, &dttz2);
9080  }
9081 
9082  break;
9083 
9084  case DB_TYPE_TIMESTAMP:
9085  case DB_TYPE_TIMESTAMPLTZ:
9086  case DB_TYPE_TIMESTAMPTZ:
9087  if (type == DB_TYPE_TIMESTAMPTZ)
9088  {
9089  db_timestamp_decode_utc (&db_get_timestamptz (f_value)->timestamp, &date, &time);
9090  }
9091  else
9092  {
9093  db_timestamp_decode_utc (db_get_timestamp (f_value), &date, &time);
9094  }
9095 
9096  d1 = ((double) date) * MILLISECONDS_OF_ONE_DAY + time * 1000;
9097 
9098  if (type == DB_TYPE_TIMESTAMPTZ)
9099  {
9100  db_timestamp_decode_utc (&db_get_timestamptz (c_value)->timestamp, &date, &time);
9101  }
9102  else
9103  {
9104  db_timestamp_decode_utc (db_get_timestamp (c_value), &date, &time);
9105  }
9106 
9107  d2 = ((double) date) * MILLISECONDS_OF_ONE_DAY + time * 1000;
9108 
9109  d_result = floor ((c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2);
9110 
9111  date = (unsigned int) (d_result / MILLISECONDS_OF_ONE_DAY);
9112  time = (unsigned int) (((DB_BIGINT) d_result) % MILLISECONDS_OF_ONE_DAY);
9113  time /= 1000;
9114 
9115  error = db_timestamp_encode_utc (&date, &time, &utime);
9116  if (error != NO_ERROR)
9117  {
9118  error = ER_FAILED;
9119  goto end;
9120  }
9121 
9122  if (type == DB_TYPE_TIMESTAMP)
9123  {
9124  db_make_timestamp (result, utime);
9125  }
9126  else if (type == DB_TYPE_TIMESTAMPLTZ)
9127  {
9128  db_make_timestampltz (result, utime);
9129  }
9130  else
9131  {
9132  DB_TIMESTAMPTZ tstz1, tstz2;
9133 
9134  /* if the two timezones are different, we use the first timezone */
9135  tstz1.timestamp = utime;
9136  tstz1.tz_id = db_get_timestamptz (f_value)->tz_id;
9137 
9138  error = tz_timestamptz_fix_zone (&tstz1, &tstz2);
9139  if (error != NO_ERROR)
9140  {
9141  error = ER_FAILED;
9142  goto end;
9143  }
9144 
9145  db_make_timestamptz (result, &tstz2);
9146  }
9147 
9148  break;
9149 
9150  case DB_TYPE_TIME:
9151  d1 = (double) (*db_get_time (f_value));
9152  d2 = (double) (*db_get_time (c_value));
9153 
9154  d_result = floor ((c_row_num_d - row_num_d) * d1 + (row_num_d - f_row_num_d) * d2);
9155 
9156  time = (DB_TIME) d_result;
9157 
9158  db_value_put_encoded_time (result, &time);
9159  break;
9160 
9161  default:
9162  /* never be here! */
9163  assert (false);
9164  }
9165 
9166 end:
9167  return error;
9168 }
9169 
9170 /*
9171  * qdata_get_interpolation_function_result () -
9172  * return : error code or NO_ERROR
9173  * thread_p (in) : thread entry
9174  * scan_id (in) :
9175  * domain (in) :
9176  * pos (in) : the pos for REGU_VAR
9177  * f_number_d (in) :
9178  * c_number_d (in) :
9179  * result (out) :
9180  * result_dom(in/out):
9181  *
9182  */
9183 int
9185  int pos, double row_num_d, double f_row_num_d, double c_row_num_d,
9186  DB_VALUE * result, tp_domain ** result_dom, FUNC_TYPE function)
9187 {
9188  int error = NO_ERROR;
9189  QFILE_TUPLE_RECORD tuple_record = { NULL, 0 };
9190  DB_VALUE *f_value, *c_value;
9191  DB_VALUE f_fetch_value, c_fetch_value;
9192  REGU_VARIABLE regu_var;
9193  SCAN_CODE scan_code;
9194  DB_BIGINT bi;
9195 
9196  assert (scan_id != NULL && domain != NULL && result != NULL && result_dom != NULL);
9197 
9198  db_make_null (&f_fetch_value);
9199  db_make_null (&c_fetch_value);
9200 
9201  /* overflow check */
9202  if (OR_CHECK_BIGINT_OVERFLOW (f_row_num_d))
9203  {
9205 
9206  error = ER_FAILED;
9207  goto end;
9208  }
9209 
9210  for (bi = (DB_BIGINT) f_row_num_d; bi >= 0; --bi)
9211  {
9212  scan_code = qfile_scan_list_next (thread_p, scan_id, &tuple_record, PEEK);
9213  if (scan_code != S_SUCCESS)
9214  {
9215  error = ER_FAILED;
9216  goto end;
9217  }
9218  }
9219 
9220  regu_var.type = TYPE_POSITION;
9221  regu_var.flags = 0;
9222  regu_var.xasl = NULL;
9223  regu_var.domain = domain;
9224  regu_var.value.pos_descr.pos_no = pos;
9225  regu_var.value.pos_descr.dom = domain;
9226  regu_var.vfetch_to = &f_fetch_value;
9227 
9228  error = fetch_peek_dbval (thread_p, &regu_var, NULL, NULL, NULL, tuple_record.tpl, &f_value);
9229  if (error != NO_ERROR)
9230  {
9231  error = ER_FAILED;
9232  goto end;
9233  }
9234 
9235  pr_clear_value (result);
9236  if (f_row_num_d == c_row_num_d)
9237  {
9238  error = qdata_apply_interpolation_function_coercion (f_value, result_dom, result, function);
9239  if (error != NO_ERROR)
9240  {
9241  goto end;
9242  }
9243  }
9244  else
9245  {
9246  /* move to next tuple */
9247  scan_code = qfile_scan_list_next (thread_p, scan_id, &tuple_record, PEEK);
9248  if (scan_code != S_SUCCESS)
9249  {
9250  error = ER_FAILED;
9251  goto end;
9252  }
9253 
9254  regu_var.vfetch_to = &c_fetch_value;
9255 
9256  /* get value */
9257  error = fetch_peek_dbval (thread_p, &regu_var, NULL, NULL, NULL, tuple_record.tpl, &c_value);
9258  if (error != NO_ERROR)
9259  {
9260  error = ER_FAILED;
9261  goto end;
9262  }
9263 
9264  error =
9265  qdata_interpolation_function_values (f_value, c_value, row_num_d, f_row_num_d, c_row_num_d, result_dom, result,
9266  function);
9267  if (error != NO_ERROR)
9268  {
9269  goto end;
9270  }
9271  }
9272 
9273 end:
9274 
9275  pr_clear_value (&f_fetch_value);
9276  pr_clear_value (&c_fetch_value);
9277 
9278  return error;
9279 }
9280 
9281 /*
9282  * qdata_update_interpolation_func_value_and_domain () -
9283  * return: NO_ERROR or ER_ARG_CAN_NOT_BE_CASTED_TO_DESIRED_DOMAIN
9284  * src_val(in):
9285  * dest_val(out):
9286  * domain(in/out):
9287  *
9288  */
9289 int
9291 {
9292  int error = NO_ERROR;
9293  DB_DOMAIN *tmp_domain = NULL;
9294  TP_DOMAIN_STATUS status;
9295 
9296  assert (src_val != NULL && dest_val != NULL && domain != NULL);
9297 
9299 
9300  status = tp_value_cast (src_val, dest_val, tmp_domain, false);
9301  if (status != DOMAIN_COMPATIBLE)
9302  {
9303  /* try datetime */
9305  status = tp_value_cast (src_val, dest_val, tmp_domain, false);
9306  }
9307 
9308  /* try time */
9309  if (status != DOMAIN_COMPATIBLE)
9310  {
9311  tmp_domain = tp_domain_resolve_default (DB_TYPE_TIME);
9312  status = tp_value_cast (src_val, dest_val, tmp_domain, false);
9313  }
9314 
9315  if (status != DOMAIN_COMPATIBLE)
9316  {
9318  goto end;
9319  }
9320 
9321  *domain = tmp_domain;
9322 
9323 end:
9324 
9325  return error;
9326 }
#define QFILE_TUPLE_VALUE_HEADER_SIZE
Definition: query_list.h:229
void REGU_VARIABLE_SET_FLAG(regu_variable_node *regu, int flag)
Definition: regu_var.hpp:259
TP_DOMAIN tp_String_domain
int qdata_list_dbs(THREAD_ENTRY *thread_p, DB_VALUE *result_p, tp_domain *domain_p)
int db_evaluate_json_extract(DB_VALUE *result, DB_VALUE *const *args, int num_args)
Definition: arithmetic.c:5511
DB_C_FLOAT db_get_float(const DB_VALUE *value)
OUTPTR_LIST * outptr_list
Definition: xasl.h:968
static int qdata_subtract_datetime(DB_DATETIME *dt1, DB_DATETIME *dt2, DB_VALUE *result_p)
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 qdata_get_valptr_type_list(THREAD_ENTRY *thread_p, valptr_list_node *valptr_list_p, qfile_tuple_value_type_list *type_list_p)
REGU_VARIABLE_LIST prior_regu_list_pred
Definition: xasl.h:427
int set_difference(DB_COLLECTION *collection1, DB_COLLECTION *collection2, DB_COLLECTION **result, DB_DOMAIN *domain)
Definition: set_object.c:3905
#define TP_IS_DATE_OR_TIME_TYPE(typeid)
static int qdata_add_int_to_utime_asymmetry(DB_VALUE *utime_val_p, int i, unsigned int *utime, DB_VALUE *result_p, TP_DOMAIN *domain_p)
Definition: query_opfunc.c:923
TP_DOMAIN_STATUS tp_value_coerce(const DB_VALUE *src, DB_VALUE *dest, const TP_DOMAIN *desired_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)
int db_evaluate_json_replace(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5721
static int qdata_cast_to_domain(DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
int db_make_datetime(DB_VALUE *value, const DB_DATETIME *datetime)
int db_value_coerce(const DB_VALUE *src, DB_VALUE *dest, const DB_DOMAIN *desired_domain)
Definition: db_macro.c:1779
#define NO_ERROR
Definition: error_code.h:46
int db_evaluate_json_merge_preserve(DB_VALUE *result, DB_VALUE *const *arg, const int num_args)
Definition: arithmetic.c:6163
static int qdata_multiply_short(DB_VALUE *short_val_p, short s2, DB_VALUE *result_p)
static int qdata_subtract_short_to_dbval(DB_VALUE *short_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
DB_COLLECTION * db_get_set(const DB_VALUE *value)
int pr_data_writeval_disk_size(DB_VALUE *value)
const int REGU_VARIABLE_ANALYTIC_WINDOW
Definition: regu_var.hpp:161
REGU_VARIABLE_LIST operand
Definition: regu_var.hpp:143
int tz_timestamptz_fix_zone(const DB_TIMESTAMPTZ *src_ts_tz, DB_TIMESTAMPTZ *dest_ts_tz)
Definition: tz_support.c:1843
static int qdata_add_time_to_dbval(DB_VALUE *time_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int qdata_divmod_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, OPERATOR_TYPE op, DB_VALUE *result_p, tp_domain *domain_p)
#define ASSERT_ERROR()
SCAN_CODE
static int qdata_add_monetary(double d1, double d2, DB_CURRENCY type, DB_VALUE *result_p)
Definition: query_opfunc.c:797
int qdata_get_single_tuple_from_list_id(THREAD_ENTRY *thread_p, qfile_list_id *list_id_p, val_list_node *single_tuple_p)
QFILE_TUPLE_VALUE_TYPE_LIST type_list
Definition: query_list.h:428
#define db_locate_numeric(value)
static int qdata_multiply_monetary_to_dbval(DB_VALUE *monetary_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
static void qdata_coerce_dbval_to_numeric(DB_VALUE *dbval_p, DB_VALUE *result_p)
Definition: query_opfunc.c:757
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
int data_writeval(struct or_buf *buf, const DB_VALUE *value) const
static int qdata_divide_bigint(DB_BIGINT bi1, DB_BIGINT bi2, DB_VALUE *result_p)
REGU_VARIABLE * rightptr
Definition: regu_var.hpp:129
#define OR_CHECK_BIGINT_OVERFLOW(i)
#define QFILE_PUT_TUPLE_VALUE_FLAG(ptr, val)
Definition: query_list.h:256
static int qdata_subtract_datetimetz_to_dbval(DB_VALUE *dt_tz_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
void qstr_make_typed_string(const DB_TYPE db_type, DB_VALUE *value, const int precision, DB_CONST_C_CHAR src, const int s_unit, const int codeset, const int collation_id)
DB_SET * db_seq_create(MOP classop, const char *name, int size)
Definition: db_set.c:252
DB_CONST_C_BIT db_get_bit(const DB_VALUE *value, int *length)
static int qdata_divide_float_to_dbval(DB_VALUE *float_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
#define TP_IS_SET_TYPE(typenum)
#define ER_TF_BUFFER_OVERFLOW
Definition: error_code.h:388
static int qdata_insert_substring_function(THREAD_ENTRY *thread_p, FUNCTION_TYPE *function_p, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
#define DB_MAX_STRING_LENGTH
Definition: dbtype_def.h:516
void set_free(DB_COLLECTION *set)
Definition: set_object.c:2560
#define DB_GET_STRING_SAFE(v)
Definition: dbtype.h:122
int db_add_int_to_datetime(DB_DATETIME *datetime, DB_BIGINT bi2, DB_DATETIME *result_datetime)
Definition: db_date.c:4656
int val_cnt
Definition: xasl.h:208
#define XASL_HAS_CONNECT_BY
Definition: xasl.h:483
int qdata_strcat_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
int db_seq_get(DB_SET *set, int index, DB_VALUE *value)
Definition: db_set.c:712
static int qdata_add_short_to_utime_asymmetry(DB_VALUE *utime_val_p, short s, unsigned int *utime, DB_VALUE *result_p, TP_DOMAIN *domain_p)
Definition: query_opfunc.c:901
int db_get_int(const DB_VALUE *value)
int db_make_bigint(DB_VALUE *value, const DB_BIGINT num)
size_t align(size_t v)
Definition: align.h:19
DB_TIMESTAMP timestamp
Definition: dbtype_def.h:766
int db_string_insert_substring(DB_VALUE *src_string, const DB_VALUE *position, const DB_VALUE *length, DB_VALUE *sub_string, DB_VALUE *result)
int db_string_regexp_replace(DB_VALUE *result, DB_VALUE *args[], int const num_args, cub_regex_object **comp_regex, char **comp_pattern)
int qdata_get_tuple_value_size_from_dbval(DB_VALUE *dbval_p)
DB_TYPE
Definition: dbtype_def.h:670
int tz_create_datetimetz_from_ses(const DB_DATETIME *dt, DB_DATETIMETZ *dt_tz)
Definition: tz_support.c:1493
DB_C_DOUBLE db_get_double(const DB_VALUE *value)
#define ER_FAILED
Definition: error_code.h:47
void numeric_coerce_num_to_double(DB_C_NUMERIC num, int scale, double *adouble)
REGU_VARIABLE_LIST next
Definition: regu_var.hpp:221
const int REGU_VARIABLE_HIDDEN_COLUMN
Definition: regu_var.hpp:156
int db_seq_put(DB_SET *set, int index, DB_VALUE *value)
Definition: db_set.c:745
static int qdata_add_int_to_datetime(DB_VALUE *datetime_val_p, int i, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define CHECK_REGU_VARIABLE_XASL_STATUS(r)
Definition: xasl.h:528
int db_get_string_collation(const DB_VALUE *value)
int db_evaluate_json_object(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5569
static int qdata_add_float_to_dbval(DB_VALUE *float_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int numeric_db_value_div(const DB_VALUE *dbv1, const DB_VALUE *dbv2, DB_VALUE *answer)
int numeric_db_value_negate(DB_VALUE *answer)
static int qdata_subtract_bigint_to_dbval(DB_VALUE *bigint_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int db_evaluate_json_keys(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5855
union xasl_node::@155 proc
SCAN_CODE qfile_scan_list_next(THREAD_ENTRY *thread_p, QFILE_LIST_SCAN_ID *scan_id_p, QFILE_TUPLE_RECORD *tuple_record_p, int peek)
Definition: list_file.c:4724
static int qdata_add_bigint(DB_BIGINT i1, DB_BIGINT i2, DB_VALUE *result_p)
Definition: query_opfunc.c:694
void set_make_collection(DB_VALUE *value, DB_COLLECTION *col)
Definition: set_object.c:3965
#define OR_BUF_INIT(buf, data, size)
TP_DOMAIN_STATUS tp_value_auto_cast(const DB_VALUE *src, DB_VALUE *dest, const TP_DOMAIN *desired_domain)
#define ER_QPROC_INVALID_XASLNODE
Definition: error_code.h:532
int qdata_set_valptr_list_unbound(THREAD_ENTRY *thread_p, valptr_list_node *valptr_list_p, val_descr *val_desc_p)
Definition: query_opfunc.c:622
#define SECONDS_OF_ONE_DAY
static int qdata_add_timestamptz_to_dbval(DB_VALUE *ts_tz_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int db_make_numeric(DB_VALUE *value, const DB_C_NUMERIC num, const int precision, const int scale)
void qexec_replace_prior_regu_vars_prior_expr(THREAD_ENTRY *thread_p, regu_variable_node *regu, xasl_node *xasl, xasl_node *connect_by_ptr)
static int qdata_multiply_numeric(DB_VALUE *numeric_val_p, DB_VALUE *dbval, DB_VALUE *result_p)
#define ASSERT_ERROR_AND_SET(error_code)
bool numeric_db_value_is_zero(const DB_VALUE *arg)
#define assert_release(e)
Definition: error_manager.h:96
#define SM_MAX_IDENTIFIER_LENGTH
int db_subtract_int_from_datetime(DB_DATETIME *dt1, DB_BIGINT bi2, DB_DATETIME *result_datetime)
Definition: db_date.c:4612
static int qdata_subtract_monetary_to_dbval(DB_VALUE *monetary_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
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
DB_C_NUMERIC db_get_numeric(const DB_VALUE *value)
#define ER_DATA_IS_TRUNCATED_TO_PRECISION
Definition: error_code.h:1406
FUNC_TYPE
#define OR_CHECK_SHORT_DIV_OVERFLOW(a, b)
union regu_variable_node::regu_data_value value
#define DB_DATE_MIN
Definition: dbtype_def.h:649
static int qdata_divide_double(double d1, double d2, DB_VALUE *result_p, bool is_check_overflow)
static int qdata_divide_short_to_dbval(DB_VALUE *short_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
void setobj_put_domain(COL *set, TP_DOMAIN *domain)
Definition: set_object.c:6193
static int qdata_subtract_datetime_to_int_asymmetry(DB_VALUE *datetime_val_p, DB_BIGINT i, DB_DATETIME *datetime, DB_VALUE *result_p, TP_DOMAIN *domain_p)
int db_evaluate_json_quote(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5294
static int qdata_divide_monetary_to_dbval(DB_VALUE *monetary_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
static int qdata_divide_short(short s1, short s2, DB_VALUE *result_p)
int db_make_date(DB_VALUE *value, const int month, const int day, const int year)
static int qdata_multiply_bigint(DB_VALUE *bigint_val_p, DB_BIGINT bi2, DB_VALUE *result_p)
DB_DATETIMETZ * db_get_datetimetz(const DB_VALUE *value)
int db_make_datetimeltz(DB_VALUE *value, const DB_DATETIME *datetime)
#define OR_CHECK_ADD_OVERFLOW(a, b, c)
TP_DOMAIN * tp_domain_resolve_value(const DB_VALUE *val, TP_DOMAIN *dbuf)
int qdata_unary_minus_dbval(DB_VALUE *result_p, DB_VALUE *dbval_p)
static int qdata_subtract_utime_to_bigint_asymmetry(DB_VALUE *utime_val_p, DB_BIGINT bi, unsigned int *utime, DB_VALUE *result_p, TP_DOMAIN *domain_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
#define TP_IS_FLOATING_NUMBER_TYPE(typeid)
int qdata_update_interpolation_func_value_and_domain(DB_VALUE *src_val, DB_VALUE *dest_val, TP_DOMAIN **domain)
int numeric_db_value_coerce_to_num(DB_VALUE *src, DB_VALUE *dest, DB_DATA_STATUS *data_status)
static int qdata_divide_bigint_to_dbval(DB_VALUE *bigint_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int er_errid(void)
int qdata_copy_valptr_list_to_tuple(THREAD_ENTRY *thread_p, valptr_list_node *valptr_list_p, val_descr *val_desc_p, qfile_tuple_record *tuple_record_p)
Definition: query_opfunc.c:434
void qdata_set_value_list_to_null(val_list_node *val_list_p)
Definition: query_opfunc.c:280
void fetch_force_not_const_recursive(REGU_VARIABLE &reguvar)
Definition: fetch.c:4856
static int qdata_add_int_to_dbval(DB_VALUE *int_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
DB_SET * db_set_create_multi(MOP classop, const char *name)
Definition: db_set.c:192
int numeric_db_value_sub(const DB_VALUE *dbv1, const DB_VALUE *dbv2, DB_VALUE *answer)
#define DB_VALUE_PRECISION(value)
Definition: dbtype.h:73
bool * clear_f_val_at_clone_decache
Definition: query_list.h:373
static int qdata_subtract_float(float f1, float f2, DB_VALUE *result_p)
enum tp_domain_status TP_DOMAIN_STATUS
int qdata_subtract_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
cub_compiled_regex * compiled_regex
Definition: regu_var.hpp:152
HL_HEAPID db_change_private_heap(THREAD_ENTRY *thread_p, HL_HEAPID heap_id)
Definition: memory_alloc.c:337
#define DATABASES_FILENAME
#define ER_QPROC_OVERFLOW_DIVISION
Definition: error_code.h:907
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)
static int qdata_subtract_float_to_dbval(DB_VALUE *float_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int qdata_bit_and_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
static int qdata_multiply_int(DB_VALUE *int_val_p, int i2, DB_VALUE *result_p)
static int qdata_subtract_datetime_to_dbval(DB_VALUE *datetime_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define MAX_ALIGNMENT
Definition: memory_alloc.h:70
static int qdata_divide_int_to_dbval(DB_VALUE *int_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
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
DB_DOMAIN_INFO domain
Definition: dbtype_def.h:1082
#define DB_VALUE_SCALE(value)
Definition: dbtype.h:74
static int qdata_subtract_bigint(DB_BIGINT i1, DB_BIGINT i2, DB_VALUE *result_p)
VAL_LIST * val_list
Definition: xasl.h:972
int qdata_multiply_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
static int qdata_multiply_double_to_dbval(DB_VALUE *double_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
void THREAD_ENTRY
static int qdata_add_utime_to_dbval(DB_VALUE *utime_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define QSTR_IS_CHAR(s)
Definition: string_opfunc.h:40
#define OR_CHECK_BIGINT_DIV_OVERFLOW(a, b)
DB_VALUE * val
Definition: xasl.h:196
#define REINTERPRET_CAST(dest_type, expr)
Definition: porting.h:1080
int db_evaluate_json_valid(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5178
static int qdata_add_short_to_utime(DB_VALUE *utime_val_p, short s, DB_VALUE *result_p, TP_DOMAIN *domain_p)
Definition: query_opfunc.c:967
DB_TIMESTAMPTZ * db_get_timestamptz(const DB_VALUE *value)
static int qdata_add_monetary_to_dbval(DB_VALUE *monetary_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int db_make_short(DB_VALUE *value, const DB_C_SHORT num)
int db_evaluate_json_depth(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5269
static int qdata_add_chars_to_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p)
int qdata_divide_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
int pr_free_ext_value(DB_VALUE *value)
OPERATOR_TYPE opcode
Definition: regu_var.hpp:131
int db_make_string(DB_VALUE *value, DB_CONST_C_CHAR str)
DB_MONETARY * db_get_monetary(const DB_VALUE *value)
#define ER_UNEXPECTED
Definition: error_code.h:1254
const int REGU_VARIABLE_UPD_INS_LIST
Definition: regu_var.hpp:166
bool pr_is_set_type(DB_TYPE type)
DB_DATA data
Definition: dbtype_def.h:1083
static int qdata_subtract_timestamptz_to_dbval(DB_VALUE *utime_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define QFILE_MAX_TUPLE_SIZE_IN_PAGE
Definition: query_list.h:217
DB_CURRENCY
Definition: dbtype_def.h:799
static int qdata_divide_int(int i1, int i2, DB_VALUE *result_p)
unsigned int DB_TIMESTAMP
Definition: dbtype_def.h:759
PR_TYPE * pr_type_from_id(DB_TYPE id)
#define OR_CHECK_DOUBLE_OVERFLOW(i)
int set_union(DB_COLLECTION *collection1, DB_COLLECTION *collection2, DB_COLLECTION **result, DB_DOMAIN *domain)
Definition: set_object.c:3928
TP_DOMAIN * tp_domain_resolve_default(DB_TYPE type)
int db_string_concatenate(const DB_VALUE *string1, const DB_VALUE *string2, DB_VALUE *result, DB_DATA_STATUS *data_status)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
Definition: db_set.h:35
DB_TIMESTAMP utime
Definition: dbtype_def.h:1058
static int qdata_multiply_bigint_to_dbval(DB_VALUE *bigint_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
QFILE_TUPLE curr_tuple
Definition: xasl.h:432
static int qdata_subtract_timestampltz_to_dbval(DB_VALUE *ts_ltz_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
int db_evaluate_json_array(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5626
#define ER_QPROC_OVERFLOW_MULTIPLICATION
Definition: error_code.h:906
int db_value_put_encoded_time(DB_VALUE *value, const DB_TIME *time)
Definition: db_macro.c:1357
static int qdata_add_short_to_dbval(DB_VALUE *short_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define DB_INT32_MIN
Definition: dbtype_def.h:632
#define assert(x)
static int qdata_elt(THREAD_ENTRY *thread_p, FUNCTION_TYPE *function_p, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
int set_get_setobj(DB_COLLECTION *ref, COL **setptr, int for_write)
Definition: set_object.c:2175
int db_make_monetary(DB_VALUE *value, const DB_CURRENCY type, const double amount)
clock::time_point time_point
Definition: perf_def.hpp:40
QPROC_TPLDESCR_STATUS qdata_generate_tuple_desc_for_valptr_list(THREAD_ENTRY *thread_p, valptr_list_node *valptr_list_p, val_descr *val_desc_p, qfile_tuple_descriptor *tuple_desc_p)
Definition: query_opfunc.c:538
CONNECTBY_PROC_NODE connect_by
Definition: xasl.h:1025
int tz_create_session_tzid_for_datetime(const DB_DATETIME *src_dt, bool src_is_utc, TZ_ID *tz_id)
Definition: tz_support.c:1037
static int qdata_subtract_double(double d1, double d2, DB_VALUE *result_p)
static int qdata_divide_numeric_to_dbval(DB_VALUE *numeric_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
DB_TYPE db_value_domain_type(const DB_VALUE *value)
#define OR_CHECK_INT_DIV_OVERFLOW(a, b)
OPERATOR_TYPE
struct db_domain_info::numeric_info numeric_info
static int qdata_add_bigint_to_utime_asymmetry(DB_VALUE *utime_val_p, DB_BIGINT bi, unsigned int *utime, DB_VALUE *result_p, TP_DOMAIN *domain_p)
Definition: query_opfunc.c:945
int prm_get_integer_value(PARAM_ID prm_id)
QPROC_TPLDESCR_STATUS
Definition: query_opfunc.h:47
#define ER_GENERIC_ERROR
Definition: error_code.h:49
int db_string_regexp_like(DB_VALUE *result, DB_VALUE *args[], int const num_args, cub_regex_object **comp_regex, char **comp_pattern)
int db_timestamp_encode_utc(const DB_DATE *date, const DB_TIME *timeval, DB_TIMESTAMP *utime)
Definition: db_date.c:635
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)
static int qdata_subtract_utime_to_dbval(DB_VALUE *utime_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
static int qdata_add_bigint_to_time(DB_VALUE *time_val_p, DB_BIGINT add_time, DB_VALUE *result_p)
Definition: query_opfunc.c:857
#define OR_CHECK_UNS_ADD_OVERFLOW(a, b, c)
#define ER_QPROC_OVERFLOW_SUBTRACTION
Definition: error_code.h:905
#define ER_IT_DATA_OVERFLOW
Definition: error_code.h:505
int db_seq_size(DB_SET *set)
Definition: db_set.c:848
REGU_VARIABLE value
Definition: regu_var.hpp:222
DB_TYPE db_value_type(const DB_VALUE *value)
static bool qdata_is_divided_zero(DB_VALUE *dbval_p)
static int qdata_add_bigint_to_utime(DB_VALUE *utime_val_p, DB_BIGINT bi, DB_VALUE *result_p, TP_DOMAIN *domain_p)
QFILE_LIST_ID * list_id
Definition: xasl.h:955
const int REGU_VARIABLE_CLEAR_AT_CLONE_DECACHE
Definition: regu_var.hpp:165
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
DB_DATETIME datetime
Definition: dbtype_def.h:783
static int qdata_subtract_numeric_to_dbval(DB_VALUE *numeric_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
static int qdata_subtract_utime(DB_UTIME u1, DB_UTIME u2, DB_VALUE *result_p)
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 numeric_db_value_coerce_from_num(DB_VALUE *src, DB_VALUE *dest, DB_DATA_STATUS *data_status)
#define DB_VALUE_DOMAIN_TYPE(value)
Definition: dbtype.h:70
static int qdata_add_int_to_date(DB_VALUE *date_val_p, int i, DB_VALUE *result_p, TP_DOMAIN *domain_p)
struct function_node * funcp
Definition: regu_var.hpp:190
#define TP_DOMAIN_COLLATION(dom)
#define TP_IS_NUMERIC_TYPE(typeid)
static int qdata_add_numeric(DB_VALUE *numeric_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
Definition: query_opfunc.c:766
int qdata_get_interpolation_function_result(THREAD_ENTRY *thread_p, QFILE_LIST_SCAN_ID *scan_id, tp_domain *domain, int pos, double row_num_d, double f_row_num_d, double c_row_num_d, DB_VALUE *result, tp_domain **result_dom, FUNC_TYPE function)
#define ER_QPROC_OVERFLOW_ADDITION
Definition: error_code.h:538
#define NUM_F_INSERT_SUBSTRING_ARGS
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)
#define OR_CHECK_UINT_OVERFLOW(i)
#define ER_QPROC_SIZE_STRING_TRUNCATED
Definition: error_code.h:1299
#define ER_QPROC_ZERO_DIVIDE
Definition: error_code.h:630
int db_make_timestamptz(DB_VALUE *value, const DB_C_TIMESTAMPTZ *ts_tz_val)
int db_evaluate_json_pretty(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5345
int db_string_put_cs_and_collation(DB_VALUE *value, const int codeset, const int collation_id)
Definition: db_macro.c:4164
DB_VALUE * db_value_copy(DB_VALUE *value)
Definition: db_macro.c:1537
TP_DOMAIN_STATUS tp_value_cast(const DB_VALUE *src, DB_VALUE *dest, const TP_DOMAIN *desired_domain, bool implicit_coercion)
static int qdata_subtract_monetary(double d1, double d2, DB_CURRENCY currency, DB_VALUE *result_p)
#define TP_DOMAIN_TYPE(dom)
int db_evaluate_json_unquote(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5305
SCAN_CODE qfile_jump_scan_tuple_position(THREAD_ENTRY *thread_p, QFILE_LIST_SCAN_ID *scan_id_p, QFILE_TUPLE_POSITION *tuple_position_p, QFILE_TUPLE_RECORD *tuple_record_p, int peek)
Definition: list_file.c:4552
int qexec_get_tuple_column_value(QFILE_TUPLE tpl, int index, DB_VALUE *valp, tp_domain *domain)
#define DB_DATE_MAX
Definition: dbtype_def.h:650
#define NULL
Definition: freelistheap.h:34
int db_string_truncate(DB_VALUE *value, const int precision)
Definition: db_macro.c:962
#define QFILE_TUPLE_LENGTH_SIZE
Definition: query_list.h:224
#define XASL_IS_FLAGED(x, f)
Definition: xasl.h:495
XASL_NODE * connect_by_ptr
Definition: xasl.h:987
FUNC_TYPE ftype
Definition: regu_var.hpp:144
struct pr_type * type
Definition: object_domain.h:76
#define SYS_CONNECT_BY_PATH_MEM_STEP
Definition: query_opfunc.c:67
REGU_VARIABLE_LIST regu_list_rest
Definition: xasl.h:424
int tz_datetimeltz_to_local(const DB_DATETIME *dt_ltz, DB_DATETIME *dt_local)
Definition: tz_support.c:1628
REGU_VARIABLE_LIST regu_list_pred
Definition: xasl.h:423
static int qdata_add_bigint_to_dbval(DB_VALUE *bigint_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
static int qdata_subtract_time_to_dbval(DB_VALUE *time_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
static int qdata_subtract_int_to_dbval(DB_VALUE *int_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int qdata_add_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p)
static int qdata_add_short_to_timestamptz(DB_VALUE *ts_tz_val_p, short s, DB_VALUE *result_p, TP_DOMAIN *domain_p)
static int qdata_add_double(double d1, double d2, DB_VALUE *result_p)
Definition: query_opfunc.c:728
int setobj_put_value(COL *col, int index, DB_VALUE *value)
Definition: set_object.c:6211
#define ER_QPROC_OVERFLOW_UMINUS
Definition: error_code.h:908
#define MILLISECONDS_OF_ONE_DAY
#define err(fd,...)
Definition: porting.h:431
#define db_private_free_and_init(thrd, ptr)
Definition: memory_alloc.h:141
static int qdata_multiply_monetary(DB_VALUE *monetary_val_p, double d, DB_VALUE *result_p)
int db_value_put_encoded_date(DB_VALUE *value, const DB_DATE *date)
Definition: db_macro.c:1383
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_timestamp_decode_w_tz_id(const DB_TIMESTAMP *utime, const TZ_ID *tz_id, DB_DATE *date, DB_TIME *timeval)
Definition: db_date.c:902
DB_SET * db_set_create_basic(MOP classop, const char *name)
Definition: db_set.c:134
static int qdata_subtract_int(int i1, int i2, DB_VALUE *result_p)
#define db_private_free(thrd, ptr)
Definition: memory_alloc.h:229
void or_init(OR_BUF *buf, char *data, int length)
int qdata_bit_shift_dbval(DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, OPERATOR_TYPE op, DB_VALUE *result_p, tp_domain *domain_p)
#define db_private_alloc(thrd, size)
Definition: memory_alloc.h:227
static int qdata_multiply_sequence_to_dbval(DB_VALUE *seq_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define OR_CHECK_SUB_UNDERFLOW(a, b, c)
static int qdata_add_numeric_to_monetary(DB_VALUE *numeric_val_p, DB_VALUE *monetary_val_p, DB_VALUE *result_p)
Definition: query_opfunc.c:782
static int qdata_add_date_to_dbval(DB_VALUE *date_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
int numeric_db_value_mul(const DB_VALUE *dbv1, const DB_VALUE *dbv2, DB_VALUE *answer)
need_clear_type need_clear
Definition: dbtype_def.h:1084
static int qdata_add_short_to_date(DB_VALUE *date_val_p, short s, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define QFILE_PUT_TUPLE_VALUE_LENGTH(ptr, val)
Definition: query_list.h:259
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
int pr_clear_value(DB_VALUE *value)
int qfile_open_list_scan(QFILE_LIST_ID *list_id_p, QFILE_LIST_SCAN_ID *scan_id_p)
Definition: list_file.c:4658
static int qdata_subtract_time(DB_TIME u1, DB_TIME u2, DB_VALUE *result_p)
static bool qdata_is_zero_value_date(DB_VALUE *dbval_p)
Definition: query_opfunc.c:228
int db_timestamp_decode_ses(const DB_TIMESTAMP *utime, DB_DATE *date, DB_TIME *timeval)
Definition: db_date.c:764
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_make_time(DB_VALUE *value, const int hour, const int minute, const int second)
static int qdata_add_int(int i1, int i2, DB_VALUE *result_p)
Definition: query_opfunc.c:677
#define DB_DEFAULT_SCALE
Definition: dbtype_def.h:561
int db_string_limit_size_string(DB_VALUE *src_string, DB_VALUE *result, const int new_size, int *spare_bytes)
int db_make_datetimetz(DB_VALUE *value, const DB_DATETIMETZ *datetimetz)
int64_t DB_BIGINT
Definition: dbtype_def.h:751
#define d1
#define PCOL_PARENTPOS_TUPLE_OFFSET
Definition: xasl.h:541
int db_evaluate_json_array_insert(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:6032
static int qdata_divide_float(float f1, float f2, DB_VALUE *result_p)
static int qdata_multiply_float_to_dbval(DB_VALUE *float_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
#define TP_IS_CHAR_TYPE(typeid)
#define OR_CHECK_UNS_SUB_UNDERFLOW(a, b, c)
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
static int qdata_add_sequence_to_dbval(DB_VALUE *seq_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
int db_make_float(DB_VALUE *value, const DB_C_FLOAT num)
static double qdata_coerce_numeric_to_double(DB_VALUE *numeric_val_p)
Definition: query_opfunc.c:745
static int qdata_add_int_to_utime(DB_VALUE *utime_val_p, int i, DB_VALUE *result_p, TP_DOMAIN *domain_p)
static int rc
Definition: serial.c:50
#define DB_DEFAULT_PRECISION
Definition: dbtype_def.h:558
int db_evaluate_json_insert(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5653
void qfile_close_scan(THREAD_ENTRY *thread_p, QFILE_LIST_SCAN_ID *scan_id_p)
Definition: list_file.c:4774
SCAN_CODE heap_get_class_oid(THREAD_ENTRY *thread_p, const OID *oid, OID *class_oid)
Definition: heap_file.c:9285
#define OR_CHECK_FLOAT_OVERFLOW(i)
int tz_utc_datetimetz_to_local(const DB_DATETIME *dt_utc, const TZ_ID *tz_id, DB_DATETIME *dt_local)
Definition: tz_support.c:1571
bool db_value_is_null(const DB_VALUE *value)
#define ARG_FILE_LINE
Definition: error_manager.h:44
#define ER_QPROC_TIME_UNDERFLOW
Definition: error_code.h:653
#define SET_DUPLICATE_VALUE
Definition: set_object.h:40
int db_evaluate_json_contains_path(DB_VALUE *result, DB_VALUE *const *arg, const int num_args)
Definition: arithmetic.c:6100
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)
static int qdata_add_datetime_to_dbval(DB_VALUE *datetime_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
QFILE_TUPLE_VALUE_FLAG
Definition: query_list.h:291
SCAN_STATUS status
Definition: query_list.h:483
static int qdata_evaluate_generic_function(THREAD_ENTRY *thread_p, FUNCTION_TYPE *function_p, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
int db_evaluate_json_contains(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5069
unsigned int DB_TIME
Definition: dbtype_def.h:754
int cfg_read_directory(DB_INFO **info_p, bool write_flag)
SCAN_POSITION position
Definition: query_list.h:484
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)
static int qdata_add_datetimetz_to_dbval(DB_VALUE *datetimetz_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
static int qdata_multiply_short_to_dbval(DB_VALUE *short_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
#define DB_BIGINT_MIN
Definition: dbtype_def.h:641
DB_DATA_STATUS
static int qdata_divide_monetary(double d1, double d2, DB_CURRENCY currency, DB_VALUE *result_p, bool is_check_overflow)
#define DB_ALIGN(offset, align)
Definition: memory_alloc.h:84
#define strlen(s1)
Definition: intl_support.c:43
static int qdata_add_numeric_to_dbval(DB_VALUE *numeric_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
static int qdata_multiply_float(DB_VALUE *float_val_p, float f2, DB_VALUE *result_p)
int db_make_timestampltz(DB_VALUE *value, const DB_C_TIMESTAMP ts_val)
static int qdata_multiply_int_to_dbval(DB_VALUE *int_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
DB_DATE * db_get_date(const DB_VALUE *value)
int db_evaluate_json_remove(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5912
TP_DOMAIN tp_Bit_domain
#define ER_QPROC_DATE_UNDERFLOW
Definition: error_code.h:652
int db_evaluate_json_get_all_paths(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:6419
#define ER_OBJ_INVALID_ARGUMENTS
Definition: error_code.h:275
#define DB_PAGESIZE
static int qdata_convert_table_to_set(THREAD_ENTRY *thread_p, DB_TYPE stype, REGU_VARIABLE *func, VAL_DESCR *val_desc_p)
SCAN_STATUS status
Definition: query_list.h:498
unsigned int date
Definition: dbtype_def.h:776
QPROC_DB_VALUE_LIST valp
Definition: xasl.h:207
char * QFILE_TUPLE
Definition: query_list.h:281
bool prm_get_bool_value(PARAM_ID prm_id)
#define QSTR_IS_ANY_CHAR_OR_BIT(s)
Definition: string_opfunc.h:47
class regu_variable_node REGU_VARIABLE
Definition: regu_var.hpp:64
DB_TIMESTAMP * db_get_timestamp(const DB_VALUE *value)
int pr_clear_compressed_string(DB_VALUE *value)
int db_get_string_size(const DB_VALUE *value)
DB_C_SHORT db_get_short(const DB_VALUE *value)
bool is_size_computed() const
int db_evaluate_json_merge_patch(DB_VALUE *result, DB_VALUE *const *arg, const int num_args)
Definition: arithmetic.c:6215
static int qdata_add_short(short s, DB_VALUE *dbval_p, DB_VALUE *result_p)
Definition: query_opfunc.c:659
#define TP_IS_DATE_TYPE(typeid)
int set_intersection(DB_COLLECTION *collection1, DB_COLLECTION *collection2, DB_COLLECTION **result, DB_DOMAIN *domain)
Definition: set_object.c:3951
void db_timestamp_decode_utc(const DB_TIMESTAMP *utime, DB_DATE *date, DB_TIME *timeval)
Definition: db_date.c:781
int db_string_regexp_instr(DB_VALUE *result, DB_VALUE *args[], int const num_args, cub_regex_object **comp_regex, char **comp_pattern)
int db_string_regexp_count(DB_VALUE *result, DB_VALUE *args[], int const num_args, cub_regex_object **comp_regex, char **comp_pattern)
#define TP_FLOATING_PRECISION_VALUE
#define DB_VALUE_TYPE(value)
Definition: dbtype.h:72
int i
Definition: dynamic_load.c:954
int db_make_null(DB_VALUE *value)
static int qdata_subtract_date_to_dbval(DB_VALUE *date_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
DB_TYPE id
int tp_value_str_auto_cast_to_number(DB_VALUE *src, DB_VALUE *dest, DB_TYPE *val_type)
#define DB_IS_NULL(value)
Definition: dbtype.h:63
static int qdata_add_bigint_to_datetime(DB_VALUE *datetime_val_p, DB_BIGINT bi, DB_VALUE *result_p, TP_DOMAIN *domain_p)
QPROC_DB_VALUE_LIST next
Definition: xasl.h:195
REGU_VARIABLE_LIST prior_regu_list_rest
Definition: xasl.h:428
#define STATIC_CAST(dest_type, expr)
Definition: porting.h:1050
static int qdata_add_bigint_to_timestamptz(DB_VALUE *ts_tz_val_p, DB_BIGINT bi, DB_VALUE *result_p, TP_DOMAIN *domain_p)
int db_make_double(DB_VALUE *value, const DB_C_DOUBLE num)
static int qdata_benchmark(THREAD_ENTRY *thread_p, FUNCTION_TYPE *function_p, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
static int qdata_divide_double_to_dbval(DB_VALUE *double_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
#define ER_ARG_CAN_NOT_BE_CASTED_TO_DESIRED_DOMAIN
Definition: error_code.h:1419
bool qdata_copy_db_value(DB_VALUE *dest_p, const DB_VALUE *src_p)
Definition: query_opfunc.c:310
int catalog_get_cardinality_by_name(THREAD_ENTRY *thread_p, const char *class_name, const char *index_name, const int key_pos, int *cardinality)
static int qdata_add_int_to_timestamptz(DB_VALUE *ts_tz_val_p, int i, DB_VALUE *result_p, TP_DOMAIN *domain_p)
void db_date_decode(const DB_DATE *date, int *monthp, int *dayp, int *yearp)
Definition: db_date.c:338
#define EXECUTE_REGU_VARIABLE_XASL(thread_p, r, v)
Definition: xasl.h:499
DB_DATETIME * db_get_datetime(const DB_VALUE *value)
int qdata_apply_interpolation_function_coercion(DB_VALUE *f_value, tp_domain **result_dom, DB_VALUE *result, FUNC_TYPE function)
int db_string_regexp_substr(DB_VALUE *result, DB_VALUE *args[], int const num_args, cub_regex_object **comp_regex, char **comp_pattern)
static int qdata_subtract_utime_to_short_asymmetry(DB_VALUE *utime_val_p, short s, unsigned int *utime, DB_VALUE *result_p, TP_DOMAIN *domain_p)
static int qdata_subtract_short(short s1, short s2, DB_VALUE *result_p)
int db_make_timestamp(DB_VALUE *value, const DB_C_TIMESTAMP timeval)
int setval(DB_VALUE *dest, const DB_VALUE *src, bool copy) const
int db_make_int(DB_VALUE *value, const int num)
int db_get_string_length(const DB_VALUE *value)
static int qdata_subtract_utime_to_int_asymmetry(DB_VALUE *utime_val_p, int i, unsigned int *utime, DB_VALUE *result_p, TP_DOMAIN *domain_p)
int qdata_tuple_to_values_array(THREAD_ENTRY *thread_p, qfile_tuple_descriptor *tuple, DB_VALUE **values)
DB_INFO * next
union function_tmp_obj * tmp_obj
Definition: regu_var.hpp:145
int db_make_oid(DB_VALUE *value, const OID *oid)
int db_evaluate_json_length(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5212
int db_evaluate_json_type_dbval(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5145
int numeric_db_value_add(const DB_VALUE *dbv1, const DB_VALUE *dbv2, DB_VALUE *answer)
DB_TIMESTAMP DB_UTIME
Definition: dbtype_def.h:761
#define TP_DOMAIN_CODESET(dom)
int qdata_copy_db_value_to_tuple_value(DB_VALUE *dbval_p, bool clear_compressed_string, char *tuple_val_p, int *tuple_val_size)
Definition: query_opfunc.c:353
static int qdata_convert_operands_to_value_and_call(THREAD_ENTRY *thread_p, FUNCTION_TYPE *function_p, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple, int(*function_to_call)(DB_VALUE *, DB_VALUE *const *, int const))
static DB_VALUE * qdata_get_dbval_from_constant_regu_variable(THREAD_ENTRY *thread_p, REGU_VARIABLE *regu_var, VAL_DESCR *val_desc_p)
DB_TIME * db_get_time(const DB_VALUE *value)
#define ER_QPROC_INVALID_DATATYPE
Definition: error_code.h:534
int db_evaluate_json_set(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5788
void db_time_decode(DB_TIME *timeval, int *hourp, int *minutep, int *secondp)
Definition: db_date.c:432
static int qdata_multiply_double(double d1, double d2, DB_VALUE *result_p)
static int qdata_convert_dbvals_to_set(THREAD_ENTRY *thread_p, DB_TYPE stype, REGU_VARIABLE *func, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
static int qdata_subtract_sequence_to_dbval(DB_VALUE *seq_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
static int qdata_add_float(float f1, float f2, DB_VALUE *result_p)
Definition: query_opfunc.c:711
int tz_create_session_tzid_for_timestamp(const DB_UTIME *src_ts, TZ_ID *tz_id)
Definition: tz_support.c:1068
#define DB_INT16_MIN
Definition: dbtype_def.h:629
int db_evaluate_json_search(DB_VALUE *result, DB_VALUE *const *args, const int num_args)
Definition: arithmetic.c:6268
#define db_private_realloc(thrd, ptr, size)
Definition: memory_alloc.h:231
#define ER_CFG_NO_FILE
Definition: error_code.h:238
#define PEEK
Definition: file_io.h:74
int db_string_extract_dbval(const MISC_OPERAND extr_operand, DB_VALUE *dbval_p, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define ER_QPROC_INVALID_QRY_SINGLE_TUPLE
Definition: error_code.h:539
int db_evaluate_json_array_append(DB_VALUE *result, DB_VALUE *const *arg, int const num_args)
Definition: arithmetic.c:5964
#define QFILE_PUT_TUPLE_LENGTH(tpl, val)
Definition: query_list.h:244
TP_DOMAIN * domain
Definition: regu_var.hpp:175
double amount
Definition: dbtype_def.h:831
static int qdata_regexp_function(THREAD_ENTRY *thread_p, FUNCTION_TYPE *function_p, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
int qdata_increment_dbval(DB_VALUE *dbval_p, DB_VALUE *result_p, int inc_val)
#define OR_CHECK_MULT_OVERFLOW(a, b, c)
static int qdata_subtract_datetime_to_int(DB_DATETIME *dt1, DB_BIGINT i2, DB_VALUE *result_p)
REGU_VARIABLE_LIST valptrp
Definition: regu_var.hpp:116
static int qdata_subtract_double_to_dbval(DB_VALUE *double_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
void cfg_free_directory(DB_INFO *databases)
int db_get_string_codeset(const DB_VALUE *value)
DB_VALUE * instnum_val
Definition: xasl.h:980
static int qdata_add_bigint_to_date(DB_VALUE *date_val_p, DB_BIGINT i, DB_VALUE *result_p, TP_DOMAIN *domain_p)
#define TP_IS_CHAR_BIT_TYPE(typeid)
static int qdata_add_short_to_datetime(DB_VALUE *datetime_val_p, short s, DB_VALUE *result_p, TP_DOMAIN *domain_p)
static int qdata_get_class_of_function(THREAD_ENTRY *thread_p, FUNCTION_TYPE *function_p, VAL_DESCR *val_desc_p, OID *obj_oid_p, QFILE_TUPLE tuple)
DB_CONST_C_CHAR db_get_string(const DB_VALUE *value)
MISC_OPERAND
#define DB_UINT32_MAX
Definition: dbtype_def.h:635
const char * fcode_get_uppercase_name(FUNC_TYPE ftype)
unsigned int time
Definition: dbtype_def.h:777
static int qdata_multiply_numeric_to_dbval(DB_VALUE *numeric_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int get_disk_size_of_value(const DB_VALUE *value) const
#define ER_QPROC_GENERIC_FUNCTION_FAILURE
Definition: error_code.h:861
int db_value_domain_init(DB_VALUE *value, const DB_TYPE type, const int precision, const int scale)
Definition: db_macro.c:153
int qdata_concatenate_dbval(THREAD_ENTRY *thread_p, DB_VALUE *dbval1_p, DB_VALUE *dbval2_p, DB_VALUE *result_p, tp_domain *domain_p, const int max_allowed_size, const char *warning_context)
static int qdata_add_double_to_dbval(DB_VALUE *double_val_p, DB_VALUE *dbval_p, DB_VALUE *result_p)
int qdata_interpolation_function_values(DB_VALUE *f_value, DB_VALUE *c_value, double row_num_d, double f_row_num_d, double c_row_num_d, tp_domain **result_dom, DB_VALUE *result, FUNC_TYPE function)
int db_value_alter_type(DB_VALUE *value, const DB_TYPE type)
Definition: db_macro.c:1225
DB_VALUE * value
Definition: regu_var.hpp:142
int tz_datetimetz_fix_zone(const DB_DATETIMETZ *src_dt_tz, DB_DATETIMETZ *dest_dt_tz)
Definition: tz_support.c:1815
static int qdata_coerce_result_to_domain(DB_VALUE *result_p, TP_DOMAIN *domain_p)