CUBRID Engine  latest
db_macro.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  * db_macro.c - API functions related to db_make and DB_GET
21  *
22  */
23 
24 #ident "$Id$"
25 
26 #include "config.h"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <ctype.h>
32 #include <string.h>
33 #include <assert.h>
34 
35 #include "system_parameter.h"
36 #include "error_manager.h"
37 #include "db.h"
38 #include "db_value_printer.hpp"
39 #include "string_opfunc.h"
40 #include "set_object.h"
41 #include "cnv.h"
42 #include "tz_support.h"
43 #if !defined(SERVER_MODE)
44 #include "object_accessor.h"
45 #endif
46 #include "elo.h"
47 #include "db_elo.h"
48 #include "db_set_function.h"
49 #include "numeric_opfunc.h"
50 #include "object_primitive.h"
51 #include "object_representation.h"
52 #include "db_json.hpp"
53 
54 #if defined (SUPPRESS_STRLEN_WARNING)
55 #define strlen(s1) ((int) strlen(s1))
56 #endif /* defined (SUPPRESS_STRLEN_WARNING) */
57 
58 #include "dbtype.h"
59 
60 #define DB_NUMBER_ZERO 0
61 
62 #define VALCNV_TOO_BIG_TO_MATTER 1024
63 
64 enum
65 {
70 };
71 
74 {
75  size_t length;
76  unsigned char *bytes;
77 };
78 
80 
82 
83 static int valcnv_Max_set_elements = 10;
84 
85 #if defined(SERVER_MODE)
87 #else
89 #endif
91 
92 static int transfer_string (char *dst, int *xflen, int *outlen,
93  const int dstlen, const char *src,
94  const int srclen, const DB_TYPE_C type, const INTL_CODESET codeset);
95 static int transfer_bit_string (char *buf, int *xflen, int *outlen,
96  const int buflen, const DB_VALUE * src, const DB_TYPE_C c_type);
97 static int coerce_char_to_dbvalue (DB_VALUE * value, char *buf, const int buflen);
98 static int coerce_numeric_to_dbvalue (DB_VALUE * value, char *buf, const DB_TYPE_C c_type);
99 static int coerce_binary_to_dbvalue (DB_VALUE * value, char *buf, const int buflen);
100 static int coerce_date_to_dbvalue (DB_VALUE * value, char *buf);
101 static int coerce_time_to_dbvalue (DB_VALUE * value, char *buf);
102 static int coerce_timestamp_to_dbvalue (DB_VALUE * value, char *buf);
103 static int coerce_datetime_to_dbvalue (DB_VALUE * value, char *buf);
104 
105 static VALCNV_BUFFER *valcnv_append_bytes (VALCNV_BUFFER * old_string,
106  const char *new_tail, const size_t new_tail_length);
107 static VALCNV_BUFFER *valcnv_append_string (VALCNV_BUFFER * old_string, const char *new_tail);
108 static VALCNV_BUFFER *valcnv_convert_float_to_string (VALCNV_BUFFER * buf, const float value);
109 static VALCNV_BUFFER *valcnv_convert_double_to_string (VALCNV_BUFFER * buf, const double value);
112 static VALCNV_BUFFER *valcnv_convert_money_to_string (const double value);
115 
116 /*
117  * db_value_put_null()
118  * return : Error indicator
119  * value(out) : value container to set NULL.
120  */
121 int
123 {
124  CHECK_1ARG_ERROR (value);
125 
126  value->domain.general_info.is_null = 1;
127  value->need_clear = false;
128 
129  return NO_ERROR;
130 }
131 
132 /* For strings that have a size of 0, this check will fail, and therefore
133  * the new interface for db_make_* functions will set the value to null, which is wrong.
134  * We need to investigate if this set to 0 will work or not.
135  */
136 inline bool
138 {
139  return (p != DB_DEFAULT_PRECISION) && ((p < 0) || (p > m));
140 }
141 
142 /*
143  * db_value_domain_init() - initialize value container with given type
144  * and precision/scale.
145  * return : Error indicator.
146  * value(in/out) : DB_VALUE container to initialize.
147  * type(in) : Type.
148  * precision(in) : Precision.
149  * scale(in) : Scale.
150  *
151  */
152 int
153 db_value_domain_init (DB_VALUE * value, const DB_TYPE type, const int precision, const int scale)
154 {
155  int error = NO_ERROR;
156 
157  CHECK_1ARG_ERROR (value);
158 
159  /* It's important to initialize the codeset of the data portion since it is considered domain information. It
160  * doesn't matter what we set it to, since it will be reset correctly when data is stored in the DB_VALUE by one of
161  * the db_make* function. */
162  value->data.ch.info.codeset = 0;
163  value->domain.general_info.type = type;
164  value->domain.numeric_info.precision = precision;
165  value->domain.numeric_info.scale = scale;
166  value->need_clear = false;
167  value->domain.general_info.is_null = 1;
168 
169  switch (type)
170  {
171  case DB_TYPE_NUMERIC:
172  if (precision == DB_DEFAULT_PRECISION)
173  {
175  }
176  else
177  {
178  value->domain.numeric_info.precision = precision;
179  }
180  if (scale == DB_DEFAULT_SCALE)
181  {
183  }
184  else
185  {
186  value->domain.numeric_info.scale = scale;
187  }
188  if (IS_INVALID_PRECISION (precision, DB_MAX_NUMERIC_PRECISION) || precision == 0)
189  {
190  error = ER_INVALID_PRECISION;
194  }
195  break;
196 
197  case DB_TYPE_BIT:
198  if (precision == DB_DEFAULT_PRECISION)
199  {
201  }
202  else
203  {
204  value->domain.char_info.length = precision;
205  }
207  {
208  error = ER_INVALID_PRECISION;
211  }
212 
213  if (precision == 0)
214  {
216  }
218  break;
219 
220  case DB_TYPE_VARBIT:
221  if (precision == DB_DEFAULT_PRECISION)
222  {
224  }
225  else
226  {
227  value->domain.char_info.length = precision;
228  }
230  {
231  error = ER_INVALID_PRECISION;
234  }
235 
236  if (precision == 0)
237  {
239  }
241  break;
242 
243  case DB_TYPE_CHAR:
244  if (precision == DB_DEFAULT_PRECISION)
245  {
247  }
248  else
249  {
250  value->domain.char_info.length = precision;
251  }
253  {
254  error = ER_INVALID_PRECISION;
257  }
258 
259  if (precision == 0)
260  {
262  }
265  break;
266 
267  case DB_TYPE_NCHAR:
268  if (precision == DB_DEFAULT_PRECISION)
269  {
271  }
272  else
273  {
274  value->domain.char_info.length = precision;
275  }
277  {
278  error = ER_INVALID_PRECISION;
281  }
282 
283  if (precision == 0)
284  {
286  }
289  break;
290 
291  case DB_TYPE_VARCHAR:
292  if (precision == DB_DEFAULT_PRECISION)
293  {
295  }
296  else
297  {
298  value->domain.char_info.length = precision;
299  }
301  {
302  error = ER_INVALID_PRECISION;
305  }
306 
307  if (precision == 0)
308  {
310  }
313  break;
314 
315  case DB_TYPE_VARNCHAR:
316  if (precision == DB_DEFAULT_PRECISION)
317  {
319  }
320  else
321  {
322  value->domain.char_info.length = precision;
323  }
325  {
326  error = ER_INVALID_PRECISION;
329  }
330 
331  if (precision == 0)
332  {
334  }
337  break;
338 
339  case DB_TYPE_ENUMERATION:
342  break;
343 
344  case DB_TYPE_JSON:
345  value->data.json.document = NULL;
346  value->data.json.schema_raw = NULL;
347  break;
348 
349  case DB_TYPE_NULL:
350  case DB_TYPE_INTEGER:
351  case DB_TYPE_BIGINT:
352  case DB_TYPE_FLOAT:
353  case DB_TYPE_DOUBLE:
354  case DB_TYPE_OBJECT:
355  case DB_TYPE_SET:
356  case DB_TYPE_MULTISET:
357  case DB_TYPE_SEQUENCE:
358  case DB_TYPE_MIDXKEY:
359  case DB_TYPE_BLOB:
360  case DB_TYPE_CLOB:
361  case DB_TYPE_TIME:
362  case DB_TYPE_TIMESTAMP:
363  case DB_TYPE_TIMESTAMPTZ:
365  case DB_TYPE_DATETIME:
366  case DB_TYPE_DATETIMETZ:
367  case DB_TYPE_DATETIMELTZ:
368  case DB_TYPE_DATE:
369  case DB_TYPE_MONETARY:
370  case DB_TYPE_VARIABLE:
371  case DB_TYPE_SUB:
372  case DB_TYPE_POINTER:
373  case DB_TYPE_ERROR:
374  case DB_TYPE_SHORT:
375  case DB_TYPE_VOBJ:
376  case DB_TYPE_OID:
377  break;
378 
379  default:
380  error = ER_UCI_INVALID_DATA_TYPE;
382  break;
383  }
384 
385  return error;
386 }
387 
388 // db_value_domain_init_default - default value initialization
389 //
390 // value - db_value to init
391 // type - desired type of value
392 //
393 void
395 {
396  // default initialization should not fail
398 }
399 
400 /*
401  * db_value_domain_min() - Initialize value(db_value_init)
402  * and set to the minimum value of the domain.
403  * return : Error indicator.
404  * value(in/out) : Pointer to a DB_VALUE.
405  * type(in) : type.
406  * precision(in) : precision.
407  * scale(in) : scale.
408  * codeset(in) : codeset.
409  * collation_id(in): collation_id.
410  * enumeration(in) : enumeration elements for DB_TYPE_ENUMERATION.
411  */
412 int
413 db_value_domain_min (DB_VALUE * value, const DB_TYPE type,
414  const int precision, const int scale, const int codeset,
415  const int collation_id, const DB_ENUMERATION * enumeration)
416 {
417  int error;
418 
419  error = db_value_domain_init (value, type, precision, scale);
420  if (error != NO_ERROR)
421  {
422  return error;
423  }
424 
425  switch (type)
426  {
427  case DB_TYPE_NULL:
428  break;
429  case DB_TYPE_INTEGER:
430  value->data.i = DB_INT32_MIN;
431  value->domain.general_info.is_null = 0;
432  break;
433  case DB_TYPE_BIGINT:
434  value->data.bigint = DB_BIGINT_MIN;
435  value->domain.general_info.is_null = 0;
436  break;
437  case DB_TYPE_FLOAT:
438  /* FLT_MIN is minimum normalized positive floating-point number. */
439  value->data.f = -FLT_MAX;
440  value->domain.general_info.is_null = 0;
441  break;
442  case DB_TYPE_DOUBLE:
443  /* DBL_MIN is minimum normalized positive double precision number. */
444  value->data.d = -DBL_MAX;
445  value->domain.general_info.is_null = 0;
446  break;
447  /* case DB_TYPE_OBJECT: not in server-side code */
448  case DB_TYPE_SET:
449  case DB_TYPE_MULTISET:
450  case DB_TYPE_SEQUENCE:
451  value->data.set = NULL;
452  value->domain.general_info.is_null = 1; /* NULL SET value */
453  break;
454  case DB_TYPE_BLOB:
455  case DB_TYPE_CLOB:
456  elo_init_structure (&value->data.elo);
457  value->domain.general_info.is_null = 1; /* NULL ELO value */
458  break;
459  case DB_TYPE_TIME:
460  value->data.time = DB_TIME_MIN;
461  value->domain.general_info.is_null = 0;
462  break;
463  case DB_TYPE_TIMESTAMP:
465  value->data.utime = DB_UTIME_MIN;
466  value->domain.general_info.is_null = 0;
467  break;
468  case DB_TYPE_TIMESTAMPTZ:
470  value->data.timestamptz.tz_id = *tz_get_utc_tz_id ();
471  value->domain.general_info.is_null = 0;
472  break;
473  case DB_TYPE_DATETIME:
474  case DB_TYPE_DATETIMELTZ:
475  value->data.datetime.date = DB_DATE_MIN;
476  value->data.datetime.time = DB_TIME_MIN;
477  value->domain.general_info.is_null = 0;
478  break;
479  case DB_TYPE_DATETIMETZ:
482  value->data.datetimetz.tz_id = *tz_get_utc_tz_id ();
483  value->domain.general_info.is_null = 0;
484  break;
485  case DB_TYPE_DATE:
486  value->data.date = DB_DATE_MIN;
487  value->domain.general_info.is_null = 0;
488  break;
489  case DB_TYPE_MONETARY:
490  /* DBL_MIN is minimum normalized positive double precision number. */
491  value->data.money.amount = -DBL_MAX;
493  value->domain.general_info.is_null = 0;
494  break;
495  /* case DB_TYPE_VARIABLE: internal use only */
496  /* case DB_TYPE_SUB: internal use only */
497  /* case DB_TYPE_POINTER: method arguments only */
498  /* case DB_TYPE_ERROR: method arguments only */
499  case DB_TYPE_SHORT:
500  value->data.sh = DB_INT16_MIN;
501  value->domain.general_info.is_null = 0;
502  break;
503  /* case DB_TYPE_VOBJ: internal use only */
504  case DB_TYPE_OID:
505  value->data.oid.pageid = NULL_PAGEID;
506  value->data.oid.slotid = NULL_PAGEID;
507  value->data.oid.volid = NULL_PAGEID;
508  value->domain.general_info.is_null = 0;
509  break;
510  /* case DB_TYPE_DB_VALUE: special for esql */
511  case DB_TYPE_NUMERIC:
512  {
513  char str[DB_MAX_NUMERIC_PRECISION + 2];
514 
515  memset (str, 0, DB_MAX_NUMERIC_PRECISION + 2);
516  str[0] = '-';
517  memset (str + 1, '9', value->domain.numeric_info.precision);
519  value->domain.general_info.is_null = 0;
520  }
521  break;
522  case DB_TYPE_BIT:
523  case DB_TYPE_VARBIT:
524  value->data.ch.info.style = MEDIUM_STRING;
526  value->data.ch.info.is_max_string = false;
527  value->data.ch.info.compressed_need_clear = false;
528  value->data.ch.medium.size = 1;
529  value->data.ch.medium.buf = (char *) "\0"; /* zero; 0 */
530  value->data.ch.medium.compressed_buf = NULL;
531  value->data.ch.medium.compressed_size = 0;
532  value->domain.general_info.is_null = 0;
533  break;
534  /* case DB_TYPE_STRING: internally DB_TYPE_VARCHAR */
535  /* space is the min value, matching the comparison in qstr_compare */
536  case DB_TYPE_CHAR:
537  case DB_TYPE_VARCHAR:
538  case DB_TYPE_NCHAR:
539  case DB_TYPE_VARNCHAR:
540  value->data.ch.info.style = MEDIUM_STRING;
541  value->data.ch.info.codeset = codeset;
542  value->data.ch.info.is_max_string = false;
543  value->data.ch.info.compressed_need_clear = false;
544  value->data.ch.medium.size = 1;
545  value->data.ch.medium.buf = (char *) "\40"; /* space; 32 */
546  value->data.ch.medium.compressed_buf = NULL;
547  value->data.ch.medium.compressed_size = 0;
548  value->domain.general_info.is_null = 0;
549  value->domain.char_info.collation_id = collation_id;
550  break;
551  case DB_TYPE_ENUMERATION:
552  db_make_enumeration (value, 0, NULL, 0, codeset, collation_id);
553  break;
554  /* case DB_TYPE_TABLE: internal use only */
555  case DB_TYPE_JSON:
556  value->domain.general_info.is_null = 1;
557  value->need_clear = false;
558  break;
559  default:
560  error = ER_UCI_INVALID_DATA_TYPE;
562  break;
563  }
564 
565  return error;
566 }
567 
568 /*
569  * db_value_domain_max() - Initialize value(db_value_init)
570  * and set to the maximum value of the domain.
571  * return : Error indicator.
572  * value(in/out) : Pointer to a DB_VALUE.
573  * type(in) : type.
574  * precision(in) : precision.
575  * scale(in) : scale.
576  * codeset(in) : codeset.
577  * collation_id(in): collation_id.
578  * enumeration(in) : enumeration elements for DB_TYPE_ENUMERATION.
579  */
580 int
581 db_value_domain_max (DB_VALUE * value, const DB_TYPE type,
582  const int precision, const int scale, const int codeset,
583  const int collation_id, const DB_ENUMERATION * enumeration)
584 {
585  int error;
586 
587  error = db_value_domain_init (value, type, precision, scale);
588  if (error != NO_ERROR)
589  {
590  return error;
591  }
592 
593  switch (type)
594  {
595  case DB_TYPE_NULL:
596  break;
597  case DB_TYPE_INTEGER:
598  value->data.i = DB_INT32_MAX;
599  value->domain.general_info.is_null = 0;
600  break;
601  case DB_TYPE_BIGINT:
602  value->data.bigint = DB_BIGINT_MAX;
603  value->domain.general_info.is_null = 0;
604  break;
605  case DB_TYPE_FLOAT:
606  value->data.f = FLT_MAX;
607  value->domain.general_info.is_null = 0;
608  break;
609  case DB_TYPE_DOUBLE:
610  value->data.d = DBL_MAX;
611  value->domain.general_info.is_null = 0;
612  break;
613  /* case DB_TYPE_OBJECT: not in server-side code */
614  case DB_TYPE_SET:
615  case DB_TYPE_MULTISET:
616  case DB_TYPE_SEQUENCE:
617  value->data.set = NULL;
618  value->domain.general_info.is_null = 1; /* NULL SET value */
619  break;
620  case DB_TYPE_BLOB:
621  case DB_TYPE_CLOB:
622  elo_init_structure (&value->data.elo);
623  value->domain.general_info.is_null = 1; /* NULL ELO value */
624  break;
625  case DB_TYPE_TIME:
626  value->data.time = DB_TIME_MAX;
627  value->domain.general_info.is_null = 0;
628  break;
629  case DB_TYPE_TIMESTAMP:
631  value->data.utime = DB_UTIME_MAX;
632  value->domain.general_info.is_null = 0;
633  break;
634  case DB_TYPE_TIMESTAMPTZ:
636  value->data.timestamptz.tz_id = *tz_get_utc_tz_id ();
637  value->domain.general_info.is_null = 0;
638  break;
639  case DB_TYPE_DATETIME:
640  case DB_TYPE_DATETIMELTZ:
641  value->data.datetime.date = DB_DATE_MAX;
642  value->data.datetime.time = DB_TIME_MAX;
643  value->domain.general_info.is_null = 0;
644  break;
645  case DB_TYPE_DATETIMETZ:
648  value->data.datetimetz.tz_id = *tz_get_utc_tz_id ();
649  value->domain.general_info.is_null = 0;
650  break;
651  case DB_TYPE_DATE:
652  value->data.date = DB_DATE_MAX;
653  value->domain.general_info.is_null = 0;
654  break;
655  case DB_TYPE_MONETARY:
656  value->data.money.amount = DBL_MAX;
658  value->domain.general_info.is_null = 0;
659  break;
660  /* case DB_TYPE_VARIABLE: internal use only */
661  /* case DB_TYPE_SUB: internal use only */
662  /* case DB_TYPE_POINTER: method arguments only */
663  /* case DB_TYPE_ERROR: method arguments only */
664  case DB_TYPE_SHORT:
665  value->data.sh = DB_INT16_MAX;
666  value->domain.general_info.is_null = 0;
667  break;
668  /* case DB_TYPE_VOBJ: internal use only */
669  case DB_TYPE_OID:
670  value->data.oid.pageid = DB_INT32_MAX;
671  value->data.oid.slotid = DB_INT16_MAX;
672  value->data.oid.volid = DB_INT16_MAX;
673  value->domain.general_info.is_null = 0;
674  break;
675  /* case DB_TYPE_DB_VALUE: special for esql */
676  case DB_TYPE_NUMERIC:
677  {
678  char str[DB_MAX_NUMERIC_PRECISION + 1];
679 
680  memset (str, 0, DB_MAX_NUMERIC_PRECISION + 1);
681  memset (str, '9', value->domain.numeric_info.precision);
683  value->domain.general_info.is_null = 0;
684  }
685  break;
686  case DB_TYPE_BIT:
687  case DB_TYPE_VARBIT:
688  value->data.ch.info.style = MEDIUM_STRING;
690  value->data.ch.info.is_max_string = true;
691  value->data.ch.info.compressed_need_clear = false;
692  value->data.ch.medium.size = 0;
693  value->data.ch.medium.buf = NULL;
694  value->data.ch.medium.compressed_buf = NULL;
695  value->data.ch.medium.compressed_size = 0;
696  value->domain.general_info.is_null = 0;
697  break;
698  /* case DB_TYPE_STRING: internally DB_TYPE_VARCHAR */
699  case DB_TYPE_CHAR:
700  case DB_TYPE_VARCHAR:
701  case DB_TYPE_NCHAR:
702  case DB_TYPE_VARNCHAR:
703  /* Case for the maximum String type. Just set the is_max_string flag to TRUE. */
704  value->data.ch.info.style = MEDIUM_STRING;
705  value->data.ch.info.codeset = codeset;
706  value->data.ch.info.is_max_string = true;
707  value->data.ch.info.compressed_need_clear = false;
708  value->data.ch.medium.size = 0;
709  value->data.ch.medium.buf = NULL;
710  value->data.ch.medium.compressed_buf = NULL;
711  value->data.ch.medium.compressed_size = 0;
712  value->domain.general_info.is_null = 0;
713  value->domain.char_info.collation_id = collation_id;
714  break;
715  case DB_TYPE_ENUMERATION:
716  if (enumeration == NULL || enumeration->count <= 0)
717  {
718  db_make_enumeration (value, DB_ENUM_ELEMENTS_MAX, NULL, 0, (unsigned char) codeset, collation_id);
719  value->data.ch.info.is_max_string = true;
720  }
721  else
722  {
723  db_make_enumeration (value, enumeration->count,
724  enumeration->elements[enumeration->count - 1].str_val.medium.buf,
725  enumeration->elements[enumeration->count - 1].str_val.medium.size,
726  (unsigned char) codeset, collation_id);
727  }
728  break;
729  /* case DB_TYPE_TABLE: internal use only */
730  case DB_TYPE_JSON:
731  value->domain.general_info.is_null = 1;
732  value->need_clear = false;
733  break;
734  default:
735  error = ER_UCI_INVALID_DATA_TYPE;
737  break;
738  }
739 
740  return error;
741 }
742 
743 /*
744  * db_value_domain_default() - Initialize value(db_value_init)
745  * and set to the default value of the domain.
746  * return : Error indicator
747  * value(in/out) : Pointer to a DB_VALUE
748  * type(in) : type
749  * precision(in) : precision
750  * scale(in) : scale
751  * codeset(in) : codeset.
752  * collation_id(in): collation_id.
753  * enumeration(in) : enumeration elements for DB_TYPE_ENUMERATION
754  */
755 int
757  const int precision, const int scale,
758  const int codeset, const int collation_id, DB_ENUMERATION * enumeration)
759 {
760  int error = NO_ERROR;
761 
762  if (TP_IS_NUMERIC_TYPE (type))
763  {
764  return db_value_domain_zero (value, type, precision, scale);
765  }
766 
767  error = db_value_domain_init (value, type, precision, scale);
768  if (error != NO_ERROR)
769  {
770  return error;
771  }
772 
773  switch (type)
774  {
775  case DB_TYPE_NULL:
776  break;
777  case DB_TYPE_INTEGER:
778  case DB_TYPE_BIGINT:
779  case DB_TYPE_FLOAT:
780  case DB_TYPE_DOUBLE:
781  case DB_TYPE_SHORT:
782  case DB_TYPE_MONETARY:
783  case DB_TYPE_NUMERIC:
784  assert (false);
785  break;
786  case DB_TYPE_SET:
787  /* empty set */
789  break;
790  case DB_TYPE_MULTISET:
791  /* empty multi-set */
793  break;
794  case DB_TYPE_SEQUENCE:
795  /* empty sequence */
796  db_make_sequence (value, db_seq_create (NULL, NULL, 0));
797  break;
798  case DB_TYPE_TIME:
799  value->data.time = DB_TIME_MIN;
800  value->domain.general_info.is_null = 0;
801  break;
802  case DB_TYPE_TIMESTAMP:
804  value->data.utime = DB_UTIME_MIN;
805  value->domain.general_info.is_null = 0;
806  break;
807  case DB_TYPE_TIMESTAMPTZ:
809  value->data.timestamptz.tz_id = *tz_get_utc_tz_id ();
810  value->domain.general_info.is_null = 0;
811  break;
812  case DB_TYPE_DATETIME:
813  case DB_TYPE_DATETIMELTZ:
814  value->data.datetime.date = DB_DATE_MIN;
815  value->data.datetime.time = DB_TIME_MIN;
816  value->domain.general_info.is_null = 0;
817  break;
818  case DB_TYPE_DATETIMETZ:
821  value->data.datetimetz.tz_id = *tz_get_utc_tz_id ();
822  value->domain.general_info.is_null = 0;
823  break;
824  case DB_TYPE_DATE:
825  value->data.date = DB_DATE_MIN;
826  value->domain.general_info.is_null = 0;
827  break;
828  case DB_TYPE_OID:
829  value->data.oid.pageid = NULL_PAGEID;
830  value->data.oid.slotid = NULL_PAGEID;
831  value->data.oid.volid = NULL_PAGEID;
832  value->domain.general_info.is_null = 0;
833  break;
834  case DB_TYPE_BIT:
835  case DB_TYPE_VARBIT:
836  db_make_bit (value, 1, "0", 1);
837  break;
838  case DB_TYPE_CHAR:
839  case DB_TYPE_VARCHAR:
840  value->data.ch.info.style = MEDIUM_STRING;
841  value->data.ch.info.codeset = codeset;
842  value->data.ch.info.is_max_string = false;
843  value->data.ch.info.compressed_need_clear = false;
844  value->data.ch.medium.size = 0;
845  value->data.ch.medium.buf = (char *) "";
846  value->data.ch.medium.compressed_buf = NULL;
847  value->data.ch.medium.compressed_size = 0;
848  value->domain.general_info.is_null = 0;
849  value->domain.char_info.collation_id = collation_id;
850  break;
851  case DB_TYPE_NCHAR:
852  case DB_TYPE_VARNCHAR:
853  value->data.ch.info.style = MEDIUM_STRING;
854  value->data.ch.info.codeset = codeset;
855  value->data.ch.info.compressed_need_clear = false;
856  value->data.ch.info.is_max_string = false;
857  value->data.ch.medium.size = 1;
858  value->data.ch.medium.buf = (char *) "";
859  value->data.ch.medium.compressed_buf = NULL;
860  value->data.ch.medium.compressed_size = 0;
861  value->domain.general_info.is_null = 0;
862  value->domain.char_info.collation_id = collation_id;
863  break;
864  case DB_TYPE_ENUMERATION:
865  db_make_enumeration (value, 0, NULL, 0, codeset, collation_id);
866  break;
867  case DB_TYPE_BLOB:
868  case DB_TYPE_CLOB:
869  value->data.elo.type = ELO_NULL;
870  value->domain.general_info.is_null = 0;
871  break;
872 #if 1 /* TODO - */
873  case DB_TYPE_OBJECT:
874  case DB_TYPE_MIDXKEY:
875  case DB_TYPE_VARIABLE:
876  case DB_TYPE_SUB:
877  case DB_TYPE_POINTER:
878  case DB_TYPE_ERROR:
879  case DB_TYPE_VOBJ:
880 #endif
881  default:
882  error = ER_UCI_INVALID_DATA_TYPE;
884  break;
885  }
886 
887  return error;
888 }
889 
890 /*
891  * db_value_domain_zero() - Initialize value(db_value_init)
892  * and set to the value 'zero' of the domain.
893  * return : Error indicator
894  * value(in/out) : Pointer to a DB_VALUE
895  * type(in) : type
896  * precision(in) : precision
897  * scale(in) : scale
898  *
899  * Note : this makes sense only for number data types, for all other
900  * types it returns an error (ER_UCI_INVALID_DATA_TYPE);
901  */
902 int
903 db_value_domain_zero (DB_VALUE * value, const DB_TYPE type, const int precision, const int scale)
904 {
905  int error = NO_ERROR;
906 
907  assert (TP_IS_NUMERIC_TYPE (type));
908 
909  error = db_value_domain_init (value, type, precision, scale);
910  if (error != NO_ERROR)
911  {
912  return error;
913  }
914 
915  switch (type)
916  {
917  case DB_TYPE_INTEGER:
918  value->data.i = DB_NUMBER_ZERO;
919  value->domain.general_info.is_null = 0;
920  break;
921  case DB_TYPE_BIGINT:
922  value->data.bigint = DB_NUMBER_ZERO;
923  value->domain.general_info.is_null = 0;
924  break;
925  case DB_TYPE_FLOAT:
926  value->data.f = DB_NUMBER_ZERO;
927  value->domain.general_info.is_null = 0;
928  break;
929  case DB_TYPE_DOUBLE:
930  value->data.d = DB_NUMBER_ZERO;
931  value->domain.general_info.is_null = 0;
932  break;
933  case DB_TYPE_MONETARY:
934  value->data.money.amount = DB_NUMBER_ZERO;
936  value->domain.general_info.is_null = 0;
937  break;
938  case DB_TYPE_SHORT:
939  value->data.sh = DB_NUMBER_ZERO;
940  value->domain.general_info.is_null = 0;
941  break;
942  case DB_TYPE_NUMERIC:
944  value->domain.general_info.is_null = 0;
945  break;
946  default:
947  error = ER_UCI_INVALID_DATA_TYPE;
949  break;
950  }
951 
952  return error;
953 }
954 
955 /*
956  * db_string_truncate() - truncate string in DB_TYPE_STRING value container
957  * return : Error indicator.
958  * value(in/out) : Pointer to a DB_VALUE
959  * precision(in) : value's precision after truncate.
960  */
961 int
962 db_string_truncate (DB_VALUE * value, const int precision)
963 {
964  int error = NO_ERROR;
965  DB_VALUE src_value;
966  char *string = NULL;
967  const char *val_str = NULL;
968  int length;
969  int byte_size;
970 
971  switch (DB_VALUE_TYPE (value))
972  {
973  case DB_TYPE_STRING:
974  val_str = db_get_string (value);
975  if (val_str != NULL && db_get_string_length (value) > precision)
976  {
977  intl_char_size ((unsigned char *) val_str, precision, db_get_string_codeset (value), &byte_size);
978  string = (char *) db_private_alloc (NULL, byte_size + 1);
979  if (string == NULL)
980  {
981  error = ER_OUT_OF_VIRTUAL_MEMORY;
982  break;
983  }
984 
985  assert (byte_size < db_get_string_size (value));
986  strncpy (string, val_str, byte_size);
987  string[byte_size] = '\0';
988  db_make_varchar (&src_value, precision, string, byte_size,
990 
991  pr_clear_value (value);
992  tp_String.setval (value, &src_value, true);
993 
994  pr_clear_value (&src_value);
995  }
996  break;
997 
998  case DB_TYPE_CHAR:
999  val_str = db_get_char (value, &length);
1000  if (val_str != NULL && length > precision)
1001  {
1002  intl_char_size ((unsigned char *) val_str, precision, db_get_string_codeset (value), &byte_size);
1003  string = (char *) db_private_alloc (NULL, byte_size + 1);
1004  if (string == NULL)
1005  {
1006  error = ER_OUT_OF_VIRTUAL_MEMORY;
1007  break;
1008  }
1009 
1010  assert (byte_size < db_get_string_size (value));
1011  strncpy (string, val_str, byte_size);
1012  string[byte_size] = '\0';
1013  db_make_char (&src_value, precision, string, byte_size,
1015 
1016  pr_clear_value (value);
1017  tp_Char.setval (value, &src_value, true);
1018 
1019  pr_clear_value (&src_value);
1020 
1021  }
1022  break;
1023 
1024  case DB_TYPE_VARNCHAR:
1025  val_str = db_get_nchar (value, &length);
1026  if (val_str != NULL && length > precision)
1027  {
1028  intl_char_size ((unsigned char *) val_str, precision, db_get_string_codeset (value), &byte_size);
1029  string = (char *) db_private_alloc (NULL, byte_size + 1);
1030  if (string == NULL)
1031  {
1032  error = ER_OUT_OF_VIRTUAL_MEMORY;
1033  break;
1034  }
1035 
1036  assert (byte_size < db_get_string_size (value));
1037  strncpy (string, val_str, byte_size);
1038  string[byte_size] = '\0';
1039  db_make_varnchar (&src_value, precision, string, byte_size,
1041 
1042  pr_clear_value (value);
1043  tp_VarNChar.setval (value, &src_value, true);
1044 
1045  pr_clear_value (&src_value);
1046  }
1047  break;
1048 
1049  case DB_TYPE_NCHAR:
1050  val_str = db_get_nchar (value, &length);
1051  if (val_str != NULL && length > precision)
1052  {
1053  intl_char_size ((unsigned char *) val_str, precision, db_get_string_codeset (value), &byte_size);
1054  string = (char *) db_private_alloc (NULL, byte_size + 1);
1055  if (string == NULL)
1056  {
1057  error = ER_OUT_OF_VIRTUAL_MEMORY;
1058  break;
1059  }
1060 
1061  assert (byte_size < db_get_string_size (value));
1062  strncpy (string, val_str, byte_size);
1063  string[byte_size] = '\0';
1064  db_make_nchar (&src_value, precision, string, byte_size,
1066 
1067  pr_clear_value (value);
1068  tp_NChar.setval (value, &src_value, true);
1069 
1070  pr_clear_value (&src_value);
1071 
1072  }
1073  break;
1074 
1075  case DB_TYPE_BIT:
1076  val_str = db_get_bit (value, &length);
1077  length = (length + 7) >> 3;
1078  if (val_str != NULL && length > precision)
1079  {
1080  string = (char *) db_private_alloc (NULL, precision);
1081  if (string == NULL)
1082  {
1083  error = ER_OUT_OF_VIRTUAL_MEMORY;
1084  break;
1085  }
1086 
1087  memcpy (string, val_str, precision);
1088  db_make_bit (&src_value, precision << 3, string, precision << 3);
1089 
1090  pr_clear_value (value);
1091  tp_Bit.setval (value, &src_value, true);
1092 
1093  pr_clear_value (&src_value);
1094  }
1095  break;
1096 
1097  case DB_TYPE_VARBIT:
1098  val_str = db_get_bit (value, &length);
1099  length = (length >> 3) + ((length & 7) ? 1 : 0);
1100  if (val_str != NULL && length > precision)
1101  {
1102  string = (char *) db_private_alloc (NULL, precision);
1103  if (string == NULL)
1104  {
1105  error = ER_OUT_OF_VIRTUAL_MEMORY;
1106  break;
1107  }
1108 
1109  memcpy (string, val_str, precision);
1110  db_make_varbit (&src_value, precision << 3, string, precision << 3);
1111 
1112  pr_clear_value (value);
1113  tp_VarBit.setval (value, &src_value, true);
1114 
1115  pr_clear_value (&src_value);
1116 
1117  }
1118  break;
1119 
1120  case DB_TYPE_NULL:
1121  break;
1122  default:
1123  {
1124  error = ER_UCI_INVALID_DATA_TYPE;
1126  }
1127  break;
1128  }
1129 
1130  if (string != NULL)
1131  {
1132  db_private_free (NULL, string);
1133  }
1134 
1135  return error;
1136 }
1137 
1138 /*
1139  * db_value_type_is_collection() -
1140  * return :
1141  * value(in) :
1142  */
1143 bool
1145 {
1146  bool is_collection;
1147  DB_TYPE type;
1148 
1149  CHECK_1ARG_FALSE (value);
1150 
1151  type = db_value_type (value);
1152  is_collection = (TP_IS_SET_TYPE (type) || type == DB_TYPE_VOBJ);
1153 
1154  return is_collection;
1155 }
1156 
1157 #if defined (ENABLE_UNUSED_FUNCTION)
1158 /*
1159  * db_value_eh_key() -
1160  * return :
1161  * value(in) :
1162  */
1163 void *
1164 db_value_eh_key (DB_VALUE * value)
1165 {
1166  DB_OBJECT *obj;
1167 
1168  CHECK_1ARG_NULL (value);
1169 
1170  switch (value->domain.general_info.type)
1171  {
1172  case DB_TYPE_STRING:
1173  return db_get_string (value);
1174  case DB_TYPE_OBJECT:
1175  obj = db_get_object (value);
1176  if (obj == NULL)
1177  {
1178  return NULL;
1179  }
1180  else
1181  {
1182  return WS_OID (obj);
1183  }
1184  default:
1185  return &value->data;
1186  }
1187 }
1188 
1189 /*
1190  * db_value_put_db_data()
1191  * return : Error indicator.
1192  * value(in/out) : Pointer to a DB_VALUE to set data.
1193  * data(in) : Pointer to a DB_DATA.
1194  */
1195 int
1196 db_value_put_db_data (DB_VALUE * value, const DB_DATA * data)
1197 {
1198  CHECK_2ARGS_ERROR (value, data);
1199 
1200  value->data = *data; /* structure copy */
1201  return NO_ERROR;
1202 }
1203 #endif
1204 
1205 /*
1206  * db_value_get_db_data()
1207  * return : DB_DATA of value container.
1208  * value(in) : Pointer to a DB_VALUE.
1209  */
1210 DB_DATA *
1212 {
1213  CHECK_1ARG_NULL (value);
1214 
1215  return &value->data;
1216 }
1217 
1218 /*
1219  * db_value_alter_type() - change the type of given value container.
1220  * return : Error indicator.
1221  * value(in/out) : Pointer to a DB_VALUE.
1222  * type(in) : new type.
1223  */
1224 int
1225 db_value_alter_type (DB_VALUE * value, const DB_TYPE type)
1226 {
1227  CHECK_1ARG_ERROR (value);
1228 
1229  value->domain.general_info.type = type;
1230  return NO_ERROR;
1231 }
1232 
1233 /*
1234  * db_value_put() -
1235  *
1236  * return: an error indicator
1237  * ER_DB_UNSUPPORTED_CONVERSION -
1238  * The C type to DB type conversion is not supported.
1239  *
1240  * ER_OBJ_VALUE_CONVERSION_ERROR -
1241  * An error occurred while performing the requested conversion.
1242  *
1243  * ER_OBJ_INVALID_ARGUMENTS - The value pointer is NULL.
1244  *
1245  * value(out) : Pointer to a DB_VALUE. The value container will need
1246  * to be initialized prior to entry as explained below.
1247  * c_type(in) : The type of the C destination buffer (and, therefore, an
1248  * indication of the type of coercion desired)
1249  * input(in) : Pointer to a C buffer
1250  * input_length(in): The length of the buffer. The buffer length is measured
1251  * in bit for C types DB_C_BIT and DB_C_VARBIT and is
1252  * measured in bytes for all other types.
1253  *
1254  */
1255 int
1256 db_value_put (DB_VALUE * value, const DB_TYPE_C c_type, void *input, const int input_length)
1257 {
1258  int error_code = NO_ERROR;
1259  int status = C_TO_VALUE_NOERROR;
1260 
1261  if ((value == NULL) || (input == NULL))
1262  {
1264  return ER_OBJ_INVALID_ARGUMENTS;
1265  }
1266  else if (input_length == -1)
1267  {
1268  db_make_null (value);
1269  return NO_ERROR;
1270  }
1271 
1272  switch (c_type)
1273  {
1274  case DB_TYPE_C_CHAR:
1275  case DB_TYPE_C_VARCHAR:
1276  case DB_TYPE_C_NCHAR:
1277  case DB_TYPE_C_VARNCHAR:
1278  status = coerce_char_to_dbvalue (value, (char *) input, input_length);
1279  break;
1280  case DB_TYPE_C_INT:
1281  case DB_TYPE_C_SHORT:
1282  case DB_TYPE_C_LONG:
1283  case DB_TYPE_C_FLOAT:
1284  case DB_TYPE_C_DOUBLE:
1285  case DB_TYPE_C_MONETARY:
1286  status = coerce_numeric_to_dbvalue (value, (char *) input, c_type);
1287  break;
1288  case DB_TYPE_C_BIT:
1289  case DB_TYPE_C_VARBIT:
1290  status = coerce_binary_to_dbvalue (value, (char *) input, input_length);
1291  break;
1292  case DB_TYPE_C_DATE:
1293  status = coerce_date_to_dbvalue (value, (char *) input);
1294  break;
1295  case DB_TYPE_C_TIME:
1296  status = coerce_time_to_dbvalue (value, (char *) input);
1297  break;
1298  case DB_TYPE_C_TIMESTAMP:
1299  status = coerce_timestamp_to_dbvalue (value, (char *) input);
1300  break;
1301  case DB_TYPE_C_DATETIME:
1302  status = coerce_datetime_to_dbvalue (value, (char *) input);
1303  break;
1304  case DB_TYPE_C_OBJECT:
1305  if (DB_VALUE_DOMAIN_TYPE (value) == DB_TYPE_OBJECT)
1306  {
1307  db_make_object (value, *(DB_C_OBJECT **) input);
1308  }
1309  else
1310  {
1312  }
1313  break;
1314  case DB_TYPE_C_SET:
1315  switch (DB_VALUE_DOMAIN_TYPE (value))
1316  {
1317  case DB_TYPE_SET:
1318  db_make_set (value, *(DB_C_SET **) input);
1319  break;
1320  case DB_TYPE_MULTISET:
1321  db_make_multiset (value, *(DB_C_SET **) input);
1322  break;
1323  case DB_TYPE_SEQUENCE:
1324  db_make_sequence (value, *(DB_C_SET **) input);
1325  break;
1326  default:
1328  break;
1329  }
1330  break;
1331  default:
1333  break;
1334  }
1335 
1336  if (status == C_TO_VALUE_UNSUPPORTED_CONVERSION)
1337  {
1338  error_code = ER_DB_UNSUPPORTED_CONVERSION;
1340  }
1341  else if (status == C_TO_VALUE_CONVERSION_ERROR)
1342  {
1343  error_code = ER_OBJ_INVALID_ARGUMENTS;
1345  }
1346 
1347  return error_code;
1348 }
1349 
1350 /*
1351  * db_value_put_encoded_time() -
1352  * return :
1353  * value(out):
1354  * time(in):
1355  */
1356 int
1358 {
1359  CHECK_1ARG_ERROR (value);
1360 
1362  value->need_clear = false;
1363  if (time)
1364  {
1365  value->data.time = *time;
1366  value->domain.general_info.is_null = 0;
1367  }
1368  else
1369  {
1370  value->domain.general_info.is_null = 1;
1371  }
1372 
1373  return NO_ERROR;
1374 }
1375 
1376 /*
1377  * db_value_put_encoded_date() -
1378  * return :
1379  * value(out):
1380  * date(in):
1381  */
1382 int
1384 {
1385  CHECK_1ARG_ERROR (value);
1386 
1388  if (date)
1389  {
1390  value->data.date = *date;
1391  value->domain.general_info.is_null = 0;
1392  }
1393  else
1394  {
1395  value->domain.general_info.is_null = 1;
1396  }
1397  value->need_clear = false;
1398 
1399  return NO_ERROR;
1400 }
1401 
1402 /*
1403  * db_value_put_monetary_currency() -
1404  * return :
1405  * value(out):
1406  * type(in):
1407  */
1408 int
1410 {
1411  int error;
1412 
1413  CHECK_1ARG_ERROR (value);
1414 
1415  /* check for valid currency type don't put default case in the switch!!! */
1416  error = ER_INVALID_CURRENCY_TYPE;
1417  switch (type)
1418  {
1419  case DB_CURRENCY_DOLLAR:
1420  case DB_CURRENCY_YEN:
1421  case DB_CURRENCY_WON:
1422  case DB_CURRENCY_TL:
1432  case DB_CURRENCY_EURO:
1443  error = NO_ERROR; /* it's a type we expect */
1444  break;
1445  default:
1446  break;
1447  }
1448 
1449  if (error != NO_ERROR)
1450  {
1451  er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, error, 1, type);
1452  }
1453  else
1454  {
1456  value->data.money.type = type;
1457  }
1458  value->need_clear = false;
1459 
1460  return error;
1461 }
1462 
1463 /*
1464  * db_value_put_monetary_amount_as_double() -
1465  * return :
1466  * value(out):
1467  * amount(in):
1468  */
1469 int
1470 db_value_put_monetary_amount_as_double (DB_VALUE * value, const double amount)
1471 {
1472  CHECK_1ARG_ERROR (value);
1473 
1475  value->data.money.amount = amount;
1476  value->domain.general_info.is_null = 0;
1477  value->need_clear = false;
1478 
1479  return NO_ERROR;
1480 }
1481 
1482 /*
1483  * OBTAIN DATA VALUES OF DB_VALUE
1484  */
1485 
1486 /*
1487  * db_value_get_monetary_currency() -
1488  * return :
1489  * value(in):
1490  */
1493 {
1495 
1496  return value->data.money.type;
1497 }
1498 
1499 /*
1500  * db_value_get_monetary_amount_as_double() -
1501  * return :
1502  * value(in):
1503  */
1504 double
1506 {
1507  CHECK_1ARG_ZERO (value);
1508 
1509  return value->data.money.amount;
1510 }
1511 
1512 /*
1513  * db_value_create() - construct an empty value container
1514  * return : a newly allocated value container
1515  */
1516 DB_VALUE *
1518 {
1519  DB_VALUE *retval;
1520 
1521  CHECK_CONNECT_NULL ();
1522 
1523  retval = pr_make_ext_value ();
1524 
1525  return (retval);
1526 }
1527 
1528 /*
1529  * db_value_copy()- A new value is created and a copy is made of the contents
1530  * of the supplied container. If the supplied value contains
1531  * external allocates such as strings or sets,
1532  * the external strings or sets are copied as well.
1533  * return : A newly created value container.
1534  * value(in) : The value to copy.
1535  */
1536 DB_VALUE *
1538 {
1539  DB_VALUE *new_ = NULL;
1540 
1541  CHECK_CONNECT_NULL ();
1542 
1543  if (value != NULL)
1544  {
1545  new_ = pr_make_ext_value ();
1546  pr_clone_value (value, new_);
1547  }
1548 
1549  return (new_);
1550 }
1551 
1552 /*
1553  * db_value_clone() - Copies the contents of one value to another without
1554  * allocating a new container.
1555  * The destination container is NOT initialized prior
1556  * to the clone so it must be cleared before calling this
1557  * function.
1558  * return : Error indicator
1559  * src(in) : DB_VALUE pointer of source value container.
1560  * dest(out) : DB_VALUE pointer of destination value container.
1561  *
1562  */
1563 int
1565 {
1566  int error = NO_ERROR;
1567 
1569 
1570  if (src != NULL && dest != NULL)
1571  {
1572  error = pr_clone_value (src, dest);
1573  }
1574 
1575  return error;
1576 }
1577 
1578 /*
1579  * db_value_clear() - the value container is initialized to an empty state
1580  * the internal type tag will be set to DB_TYPE_NULL. Any external
1581  * allocations such as strings or sets will be freed.
1582  * The container itself is not freed and may be reused.
1583  * return: Error indicator
1584  * value(out) : the value to clear
1585  *
1586  */
1587 int
1589 {
1590  int error = NO_ERROR;
1591 
1592  /* don't check connection here, we always allow things to be freed */
1593  if (value != NULL)
1594  {
1595  error = pr_clear_value (value);
1596  }
1597 
1598  return error;
1599 }
1600 
1601 /*
1602  * db_value_free() - the value container is cleared and freed. Any external
1603  * allocations within the container such as strings or sets will also
1604  * be freed.
1605  *
1606  * return : Error indicator.
1607  * value(out) : The value to free.
1608  */
1609 int
1611 {
1612  int error = NO_ERROR;
1613 
1614  /* don't check connection here, we always allow things to be freed */
1615  if (value != NULL)
1616  {
1617  error = pr_free_ext_value (value);
1618  }
1619 
1620  return error;
1621 }
1622 
1623 /*
1624  * db_value_clear_array() - all the value containers in the values array are
1625  * initialized to an empty state; their internal type tag will be set
1626  * to DB_TYPE_NULL. Any external allocations such as strings or sets
1627  * will be freed.
1628  * The array itself is not freed and may be reused.
1629  * return: Error indicator
1630  * value_array(out) : the value array to clear
1631  */
1632 int
1634 {
1635  int error = NO_ERROR;
1636  int i = 0;
1637 
1638  assert (value_array != NULL && value_array->size >= 0);
1639 
1640  for (i = 0; i < value_array->size; ++i)
1641  {
1642  int tmp_error = NO_ERROR;
1643 
1644  assert (value_array->vals != NULL);
1645 
1646  /* don't check connection here, we always allow things to be freed */
1647  tmp_error = pr_clear_value (&value_array->vals[i]);
1648  if (tmp_error != NO_ERROR && error == NO_ERROR)
1649  {
1650  error = tmp_error;
1651  }
1652  }
1653 
1654  return error;
1655 }
1656 
1657 /*
1658  * db_value_print() - describe the contents of a value container
1659  * return : none
1660  * value(in): value container to print.
1661  */
1662 void
1663 db_value_print (const DB_VALUE * value)
1664 {
1665  CHECK_CONNECT_VOID ();
1666 
1667  if (value != NULL)
1668  {
1669  db_fprint_value (stdout, value);
1670  }
1671 
1672 }
1673 
1674 /*
1675  * db_value_fprint() - describe the contents of a value to the specified file
1676  * return : none
1677  * fp(in) : file pointer.
1678  * value(in) : value container to print.
1679  */
1680 void
1681 db_value_fprint (FILE * fp, const DB_VALUE * value)
1682 {
1683  CHECK_CONNECT_VOID ();
1684 
1685  if (fp != NULL && value != NULL)
1686  {
1687  db_fprint_value (fp, value);
1688  }
1689 }
1690 
1691 /*
1692  * db_type_to_db_domain() - see the note below.
1693  *
1694  * return : DB_DOMAIN of a primitive DB_TYPE, returns NULL otherwise
1695  * type(in) : a primitive DB_TYPE
1696  *
1697  * note:
1698  * This function is used only in special cases where we need to get the
1699  * DB_DOMAIN of a primitive DB_TYPE that has no domain parameters, or of a
1700  * parameterized DB_TYPE with the default domain parameters.
1701  *
1702  * For example, it can be used to get the DB_DOMAIN of primitive
1703  * DB_TYPES like DB_TYPE_INTEGER, DB_TYPE_FLOAT, etc., or of
1704  * DB_TYPE_NUMERIC(DB_DEFAULT_NUMERIC_PRECISION, DB_DEFAULT_NUMERIC_SCALE).
1705  *
1706  * This function CANNOT be used to get the DB_DOMAIN of
1707  * set/multiset/sequence and object DB_TYPEs.
1708  */
1709 DB_DOMAIN *
1711 {
1712  DB_DOMAIN *result = NULL;
1713 
1714  switch (type)
1715  {
1716  case DB_TYPE_INTEGER:
1717  case DB_TYPE_FLOAT:
1718  case DB_TYPE_DOUBLE:
1719  case DB_TYPE_TIME:
1720  case DB_TYPE_TIMESTAMP:
1721  case DB_TYPE_TIMESTAMPTZ:
1722  case DB_TYPE_TIMESTAMPLTZ:
1723  case DB_TYPE_DATETIME:
1724  case DB_TYPE_DATETIMETZ:
1725  case DB_TYPE_DATETIMELTZ:
1726  case DB_TYPE_DATE:
1727  case DB_TYPE_MONETARY:
1728  case DB_TYPE_SHORT:
1729  case DB_TYPE_BIGINT:
1730  case DB_TYPE_NUMERIC:
1731  case DB_TYPE_CHAR:
1732  case DB_TYPE_NCHAR:
1733  case DB_TYPE_BIT:
1734  case DB_TYPE_VARCHAR:
1735  case DB_TYPE_VARNCHAR:
1736  case DB_TYPE_VARBIT:
1737  case DB_TYPE_SET:
1738  case DB_TYPE_MULTISET:
1739  case DB_TYPE_SEQUENCE:
1740  case DB_TYPE_NULL:
1741  case DB_TYPE_BLOB:
1742  case DB_TYPE_CLOB:
1743  case DB_TYPE_ENUMERATION:
1744  case DB_TYPE_ELO:
1745  case DB_TYPE_JSON:
1746  result = tp_domain_resolve_default (type);
1747  break;
1748  case DB_TYPE_SUB:
1749  case DB_TYPE_POINTER:
1750  case DB_TYPE_ERROR:
1751  case DB_TYPE_VOBJ:
1752  case DB_TYPE_OID:
1753  case DB_TYPE_OBJECT:
1754  case DB_TYPE_DB_VALUE:
1755  case DB_TYPE_VARIABLE:
1756  case DB_TYPE_RESULTSET:
1757  case DB_TYPE_MIDXKEY:
1758  case DB_TYPE_TABLE:
1759  result = NULL;
1760  break;
1761 
1762  /* NO DEFAULT CASE!!!!! ALL TYPES MUST GET HANDLED HERE! */
1763  default:
1764  assert (0);
1765  break;
1766  }
1767 
1768  return result;
1769 }
1770 
1771 /*
1772  * db_value_coerce()-coerces a DB_VALUE to another compatible DB_VALUE domain.
1773  * return : error indicator.
1774  * src(in) : a pointer to the original DB_VALUE.
1775  * dest(in/out) : a pointer to a place to put the coerced DB_VALUE.
1776  * desired_domain(in) : the desired domain of the coerced result.
1777  */
1778 int
1779 db_value_coerce (const DB_VALUE * src, DB_VALUE * dest, const DB_DOMAIN * desired_domain)
1780 {
1781  TP_DOMAIN_STATUS status;
1782  int err = NO_ERROR;
1783 
1784  status = tp_value_cast_force (src, dest, desired_domain, false);
1785  if (status != DOMAIN_COMPATIBLE)
1786  {
1787  err = tp_domain_status_er_set (status, ARG_FILE_LINE, src, desired_domain);
1788  }
1789 
1790  return err;
1791 }
1792 
1793 /*
1794  * db_value_equal()- compare two values to see if they are equal.
1795  * return : non-zero if equal, zero if not equal
1796  * value1(in) : value container to compare.
1797  * value2(in) : value container to compare.
1798  *
1799  * note : this is a boolean test, the sign or magnitude of the non-zero return
1800  * value has no meaning.
1801  */
1802 int
1803 db_value_equal (const DB_VALUE * value1, const DB_VALUE * value2)
1804 {
1805  int retval;
1806 
1807  CHECK_CONNECT_ZERO ();
1808 
1809  /* this handles NULL arguments */
1810  retval = (tp_value_equal (value1, value2, 1));
1811 
1812  return (retval);
1813 }
1814 
1815 /*
1816  * db_set_compare() - This compares the two collection values.
1817  * It will determine if the value1 is a subset or superset of value2.
1818  * If either value is not a collection type, it will return DB_NE
1819  * If both values are set types, a set comparison will be done.
1820  * Otherwise a multiset comparison will be done.
1821  * return : DB_EQ - values are equal
1822  * DB_SUBSET - value1 is subset of value2
1823  * DB_SUPERSET - value1 is superset of value2
1824  * DB_NE - values are not both collections.
1825  * DB_UNK - collections contain NULLs preventing
1826  * a more certain answer.
1827  *
1828  * value1(in): A db_value of some collection type.
1829  * value2(in): A db_value of some collection type.
1830  *
1831  */
1832 int
1833 db_set_compare (const DB_VALUE * value1, const DB_VALUE * value2)
1834 {
1835  int retval;
1836 
1837  /* this handles NULL arguments */
1838  retval = (tp_set_compare (value1, value2, 1, 0));
1839 
1840  return (retval);
1841 }
1842 
1843 /*
1844  * db_value_compare() - Compares the two values for ordinal position
1845  * It will attempt to coerce the two values to the most general
1846  * of the two types passed in. Then a connonical comparison is done.
1847  *
1848  * return : DB_EQ - values are equal
1849  * DB_GT - value1 is cannonicaly before value2
1850  * DB_LT - value1 is cannonicaly after value2
1851  * DB_UNK - value is or contains NULLs preventing
1852  * a more certain answer
1853  */
1854 int
1855 db_value_compare (const DB_VALUE * value1, const DB_VALUE * value2)
1856 {
1857  /* this handles NULL arguments */
1858  return tp_value_compare (value1, value2, 1, 0);
1859 }
1860 
1861 /*
1862  * db_get_currency_default() - This returns the value of the default currency
1863  * identifier based on the current locale. This was formerly defined with
1864  * the variable DB_CURRENCY_DEFAULT but for the PC, we need to
1865  * have this available through a function so it can be exported through
1866  * the DLL.
1867  * return : currency identifier.
1868  */
1871 {
1872  return lang_currency ();
1873 }
1874 
1875 /*
1876  * transfer_string() -
1877  * return : an error indicator.
1878  *
1879  * dst(out) : pointer to destination buffer area
1880  * xflen(out) : pointer to int field that will receive the number of bytes
1881  * transferred.
1882  * outlen(out): pointer to int field that will receive an indication of number
1883  * of bytes transferred.(see the note below)
1884  * dstlen(in) : size of destination buffer area (in bytes, *including* null
1885  * terminator in the case of strings)
1886  * src(in) : pointer to source buffer area
1887  * srclen(in) : size of source buffer area (in bytes, *NOT* including null
1888  * terminator in the case of strings)
1889  * c_type(in) : the type of the destination buffer (i.e., whether it is varying
1890  * or fixed)
1891  * codeset(in): International codeset for the character string. This is needed
1892  * to properly pad the strings.
1893  *
1894  */
1895 static int
1896 transfer_string (char *dst, int *xflen, int *outlen, const int dstlen,
1897  const char *src, const int srclen, const DB_TYPE_C type, const INTL_CODESET codeset)
1898 {
1899  int code;
1900  unsigned char *ptr;
1901  int length, size;
1902 
1903  code = NO_ERROR;
1904 
1905  if (dstlen > srclen)
1906  {
1907  /*
1908  * No truncation; copy the data and blank pad if necessary.
1909  */
1910  memcpy (dst, src, srclen);
1911  if ((type == DB_TYPE_C_CHAR) || (type == DB_TYPE_C_NCHAR))
1912  {
1913  ptr =
1914  qstr_pad_string ((unsigned char *) &dst[srclen],
1915  (int) ((dstlen - srclen - 1) / intl_pad_size (codeset)), codeset);
1916  *xflen = CAST_STRLEN ((char *) ptr - (char *) dst);
1917  }
1918  else
1919  {
1920  *xflen = srclen;
1921  }
1922  dst[*xflen] = '\0';
1923 
1924  if (outlen)
1925  {
1926  *outlen = 0;
1927  }
1928  }
1929  else
1930  {
1931  /*
1932  * Truncation is necessary; put as many bytes as possible into
1933  * the receiving buffer and null-terminate it (i.e., it receives
1934  * at most dstlen-1 bytes). If there is not outlen indicator by
1935  * which we can indicate truncation, this is an error.
1936  *
1937  */
1938  intl_char_count ((unsigned char *) src, dstlen - 1, codeset, &length);
1939  intl_char_size ((unsigned char *) src, length, codeset, &size);
1940  memcpy (dst, src, size);
1941  dst[size] = '\0';
1942  *xflen = size;
1943  if (outlen)
1944  {
1945  *outlen = srclen;
1946  }
1947  else
1948  {
1949  code = ER_UCI_NULL_IND_NEEDED;
1951  }
1952  }
1953 
1954  return code;
1955 }
1956 
1957 /*
1958  * transfer_bit_string() -
1959  * Transfers at most buflen bytes to the region pointed at by buf.
1960  * If c_type is DB_TYPE_C_BIT, strings shorter than dstlen will be
1961  * blank-padded out to buflen-1 bytes. All strings will be
1962  * null-terminated. If truncation is necessary (i.e., if buflen is
1963  * less than or equal to length of src), *outlen is set to length of
1964  * src; if truncation is is not necessary, *outlen is set to 0.
1965  *
1966  * return : an error indicator
1967  *
1968  * buf(out) : pointer to destination buffer area
1969  * xflen(out) : Number of bits transfered from the src string to the buf.
1970  * outlen(out): pointer to a int field. *outlen will equal 0 if no
1971  * truncation occurred and will equal the size of the destination
1972  * buffer in bytes needed to avoid truncation, otherwise.
1973  * buflen(in) : size of destination buffer area in bytes
1974  * src(in) : pointer to source buffer area.
1975  * c_type(in) : the type of the destination buffer (i.e., whether it is varying
1976  * or fixed).
1977  */
1978 static int
1979 transfer_bit_string (char *buf, int *xflen, int *outlen, const int buflen, const DB_VALUE * src, const DB_TYPE_C c_type)
1980 {
1981  DB_VALUE tmp_value;
1982  DB_DATA_STATUS data_status;
1983  DB_TYPE db_type;
1984  int error_code;
1985  const char *tmp_val_str;
1986 
1987  if (c_type == DB_TYPE_C_BIT)
1988  {
1989  db_type = DB_TYPE_BIT;
1990  }
1991  else
1992  {
1993  db_type = DB_TYPE_VARBIT;
1994  }
1995 
1996  db_value_domain_init (&tmp_value, db_type, buflen, DB_DEFAULT_SCALE);
1997  error_code = db_bit_string_coerce (src, &tmp_value, &data_status);
1998  if (error_code == NO_ERROR)
1999  {
2000  *xflen = db_get_string_length (&tmp_value);
2001  if (data_status == DATA_STATUS_TRUNCATED)
2002  {
2003  if (outlen != NULL)
2004  {
2005  *outlen = db_get_string_length (src);
2006  }
2007  }
2008 
2009  tmp_val_str = db_get_string (&tmp_value);
2010  if (tmp_val_str != NULL)
2011  {
2012  memcpy (buf, tmp_val_str, db_get_string_size (&tmp_value));
2013  }
2014 
2015  error_code = db_value_clear (&tmp_value);
2016  }
2017 
2018  return error_code;
2019 }
2020 
2021 int
2023 {
2024  char *raw_schema_body = NULL;
2025  JSON_DOC *doc_copy = NULL;
2026 
2027  CHECK_2ARGS_ERROR (src, dst);
2028 
2029  assert (dst->document == NULL && dst->schema_raw == NULL);
2030 
2031  raw_schema_body = db_private_strdup (NULL, src->schema_raw);
2032 
2033  doc_copy = db_json_get_copy_of_doc (src->document);
2034 
2035  dst->schema_raw = raw_schema_body;
2036  dst->document = doc_copy;
2037 
2038  return NO_ERROR;
2039 }
2040 
2041 int
2043 {
2044  CHECK_1ARG_ERROR (val);
2045 
2046  val->schema_raw = NULL;
2047  val->document = NULL;
2048 
2049  return NO_ERROR;
2050 }
2051 
2052 /*
2053  * db_value_get() -
2054  *
2055  * return : Error indicator.
2056  * value(in) : Pointer to a DB_VALUE
2057  * c_type(in) : The type of the C destination buffer (and, therefore, an
2058  * indication of the type of coercion desired)
2059  * buf(out) : Pointer to a C buffer
2060  * buflen(in) : The length of that buffer in bytes. The buffer should include
2061  * room for a terminating NULL character which is appended to
2062  * character strings.
2063  * xflen(out) : Pointer to a int field that will contain the number of
2064  * elemental-units transfered into the buffer. This value does
2065  * not include terminating NULL characters which are appended
2066  * to character strings. An elemental-unit will be a byte
2067  * for all types except bit strings in are represented in bits.
2068  * outlen(out) : Pointer to a int field that will contain the length
2069  * of the source if truncation occurred and 0 otherwise. This
2070  * value will be in terms of bytes for all types. <outlen>
2071  * can be used to reallocate buffer space if the buffer
2072  * was too small to contain the value.
2073  *
2074  *
2075  */
2076 int
2077 db_value_get (DB_VALUE * value, const DB_TYPE_C c_type, void *buf, const int buflen, int *xflen, int *outlen)
2078 {
2079  int error_code = NO_ERROR;
2080 
2081  if (DB_IS_NULL (value))
2082  {
2083  if (outlen)
2084  {
2085  *outlen = -1;
2086  return NO_ERROR;
2087  }
2088  else
2089  {
2090  error_code = ER_UCI_NULL_IND_NEEDED;
2091  goto error0;
2092  }
2093  }
2094 
2095  if ((buf == NULL) || (xflen == NULL))
2096  {
2097  goto invalid_args;
2098  }
2099 
2100  /*
2101  * *outlen will be non-zero only when converting to a character
2102  * output and truncation is necessary. All other cases should set
2103  * *outlen to 0 unless a NULL is encountered (which case we've
2104  * already dealt with).
2105  */
2106  if (outlen)
2107  {
2108  *outlen = 0;
2109  }
2110 
2111  /*
2112  * The numeric conversions below probably ought to be checking for
2113  * overflow and complaining when it happens. For example, trying to
2114  * get a double out into a DB_C_SHORT is likely to overflow; the
2115  * user probably wants to know about it.
2116  */
2117  switch (DB_VALUE_TYPE (value))
2118  {
2119  case DB_TYPE_INTEGER:
2120  {
2121  int i = db_get_int (value);
2122 
2123  switch (c_type)
2124  {
2125  case DB_TYPE_C_INT:
2126  *(DB_C_INT *) buf = (DB_C_INT) i;
2127  *xflen = sizeof (DB_C_INT);
2128  break;
2129  case DB_TYPE_C_SHORT:
2130  *(DB_C_SHORT *) buf = (DB_C_SHORT) i;
2131  *xflen = sizeof (DB_C_SHORT);
2132  break;
2133  case DB_TYPE_C_LONG:
2134  *(DB_C_LONG *) buf = (DB_C_LONG) i;
2135  *xflen = sizeof (DB_C_LONG);
2136  break;
2137  case DB_TYPE_C_FLOAT:
2138  *(DB_C_FLOAT *) buf = (DB_C_FLOAT) i;
2139  *xflen = sizeof (DB_C_FLOAT);
2140  break;
2141  case DB_TYPE_C_DOUBLE:
2142  *(DB_C_DOUBLE *) buf = (DB_C_DOUBLE) i;
2143  *xflen = sizeof (DB_C_DOUBLE);
2144  break;
2145  case DB_TYPE_C_CHAR:
2146  case DB_TYPE_C_VARCHAR:
2147  {
2148  char tmp[NUM_BUF_SIZE];
2149  sprintf (tmp, "%d", i);
2150  error_code =
2151  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2152  }
2153  break;
2154  case DB_TYPE_C_NCHAR:
2155  case DB_TYPE_C_VARNCHAR:
2156  {
2157  char tmp[NUM_BUF_SIZE];
2158  sprintf (tmp, "%d", i);
2159  error_code =
2160  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2161  }
2162  break;
2163  default:
2164  goto unsupported_conversion;
2165  }
2166  } /* DB_TYPE_INT */
2167  break;
2168 
2169  case DB_TYPE_SMALLINT:
2170  {
2171  short s = db_get_short (value);
2172 
2173  switch (c_type)
2174  {
2175  case DB_TYPE_C_INT:
2176  {
2177  *(DB_C_INT *) buf = (DB_C_INT) s;
2178  *xflen = sizeof (DB_C_INT);
2179  }
2180  break;
2181  case DB_TYPE_C_SHORT:
2182  {
2183  *(DB_C_SHORT *) buf = (DB_C_SHORT) s;
2184  *xflen = sizeof (DB_C_SHORT);
2185  }
2186  break;
2187  case DB_TYPE_C_LONG:
2188  {
2189  *(DB_C_LONG *) buf = (DB_C_LONG) s;
2190  *xflen = sizeof (DB_C_LONG);
2191  }
2192  break;
2193  case DB_TYPE_C_FLOAT:
2194  {
2195  *(DB_C_FLOAT *) buf = (DB_C_FLOAT) s;
2196  *xflen = sizeof (DB_C_FLOAT);
2197  }
2198  break;
2199  case DB_TYPE_C_DOUBLE:
2200  {
2201  *(DB_C_DOUBLE *) buf = (DB_C_DOUBLE) s;
2202  *xflen = sizeof (DB_C_DOUBLE);
2203  }
2204  break;
2205  case DB_TYPE_C_CHAR:
2206  case DB_TYPE_C_VARCHAR:
2207  {
2208  char tmp[NUM_BUF_SIZE];
2209  sprintf (tmp, "%d", s);
2210  error_code =
2211  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2212  }
2213  break;
2214  case DB_TYPE_C_NCHAR:
2215  case DB_TYPE_C_VARNCHAR:
2216  {
2217  char tmp[NUM_BUF_SIZE];
2218  sprintf (tmp, "%d", s);
2219  error_code =
2220  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2221  }
2222  break;
2223  default:
2224  goto unsupported_conversion;
2225  }
2226  } /* DB_TYPE_SMALLINT */
2227  break;
2228 
2229  case DB_TYPE_BIGINT:
2230  {
2231  DB_BIGINT bigint = db_get_bigint (value);
2232 
2233  switch (c_type)
2234  {
2235  case DB_TYPE_C_INT:
2236  *(DB_C_INT *) buf = (DB_C_INT) bigint;
2237  *xflen = sizeof (DB_C_INT);
2238  break;
2239  case DB_TYPE_C_SHORT:
2240  *(DB_C_SHORT *) buf = (DB_C_SHORT) bigint;
2241  *xflen = sizeof (DB_C_SHORT);
2242  break;
2243  case DB_TYPE_C_BIGINT:
2244  *(DB_C_BIGINT *) buf = (DB_C_BIGINT) bigint;
2245  *xflen = sizeof (DB_C_BIGINT);
2246  break;
2247  case DB_TYPE_C_LONG:
2248  *(DB_C_LONG *) buf = (DB_C_LONG) bigint;
2249  *xflen = sizeof (DB_C_LONG);
2250  break;
2251  case DB_TYPE_C_FLOAT:
2252  *(DB_C_FLOAT *) buf = (DB_C_FLOAT) bigint;
2253  *xflen = sizeof (DB_C_FLOAT);
2254  break;
2255  case DB_TYPE_C_DOUBLE:
2256  *(DB_C_DOUBLE *) buf = (DB_C_DOUBLE) bigint;
2257  *xflen = sizeof (DB_C_DOUBLE);
2258  break;
2259  case DB_TYPE_C_CHAR:
2260  case DB_TYPE_C_VARCHAR:
2261  {
2262  char tmp[NUM_BUF_SIZE];
2263  sprintf (tmp, "%lld", (long long) bigint);
2264  error_code =
2265  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2266  }
2267  break;
2268  case DB_TYPE_C_NCHAR:
2269  case DB_TYPE_C_VARNCHAR:
2270  {
2271  char tmp[NUM_BUF_SIZE];
2272  sprintf (tmp, "%lld", (long long) bigint);
2273  error_code =
2274  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2275  }
2276  break;
2277  default:
2278  goto unsupported_conversion;
2279  }
2280  } /* DB_TYPE_BIGINT */
2281  break;
2282 
2283  case DB_TYPE_FLOAT:
2284  {
2285  float f = db_get_float (value);
2286 
2287  switch (c_type)
2288  {
2289  case DB_TYPE_C_INT:
2290  {
2291  *(DB_C_INT *) buf = (DB_C_INT) f;
2292  *xflen = sizeof (DB_C_INT);
2293  }
2294  break;
2295  case DB_TYPE_C_SHORT:
2296  {
2297  *(DB_C_SHORT *) buf = (DB_C_SHORT) f;
2298  *xflen = sizeof (DB_C_SHORT);
2299  }
2300  break;
2301  case DB_TYPE_C_LONG:
2302  {
2303  *(DB_C_LONG *) buf = (DB_C_LONG) f;
2304  *xflen = sizeof (DB_C_LONG);
2305  }
2306  break;
2307  case DB_TYPE_C_FLOAT:
2308  {
2309  *(DB_C_FLOAT *) buf = (DB_C_FLOAT) f;
2310  *xflen = sizeof (DB_C_FLOAT);
2311  }
2312  break;
2313  case DB_TYPE_C_DOUBLE:
2314  {
2315  *(DB_C_DOUBLE *) buf = (DB_C_DOUBLE) f;
2316  *xflen = sizeof (DB_C_DOUBLE);
2317  }
2318  break;
2319  case DB_TYPE_C_CHAR:
2320  case DB_TYPE_C_VARCHAR:
2321  {
2322  char tmp[NUM_BUF_SIZE];
2323  sprintf (tmp, "%f", (DB_C_DOUBLE) f);
2324  error_code =
2325  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2326  }
2327  break;
2328  case DB_TYPE_C_NCHAR:
2329  case DB_TYPE_C_VARNCHAR:
2330  {
2331  char tmp[NUM_BUF_SIZE];
2332  sprintf (tmp, "%f", (DB_C_DOUBLE) f);
2333  error_code =
2334  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2335  }
2336  break;
2337  default:
2338  goto unsupported_conversion;
2339  }
2340  } /* DB_TYPE_FLOAT */
2341  break;
2342 
2343  case DB_TYPE_DOUBLE:
2344  {
2345  double d = db_get_double (value);
2346 
2347  switch (c_type)
2348  {
2349  case DB_TYPE_C_INT:
2350  {
2351  *(DB_C_INT *) buf = (DB_C_INT) d;
2352  *xflen = sizeof (DB_C_INT);
2353  }
2354  break;
2355  case DB_TYPE_C_SHORT:
2356  {
2357  *(DB_C_SHORT *) buf = (DB_C_SHORT) d;
2358  *xflen = sizeof (DB_C_SHORT);
2359  }
2360  break;
2361  case DB_TYPE_C_LONG:
2362  {
2363  *(DB_C_LONG *) buf = (DB_C_LONG) d;
2364  *xflen = sizeof (DB_C_LONG);
2365  }
2366  break;
2367  case DB_TYPE_C_FLOAT:
2368  {
2369  *(DB_C_FLOAT *) buf = (DB_C_FLOAT) d;
2370  *xflen = sizeof (DB_C_FLOAT);
2371  }
2372  break;
2373  case DB_TYPE_C_DOUBLE:
2374  {
2375  *(DB_C_DOUBLE *) buf = (DB_C_DOUBLE) d;
2376  *xflen = sizeof (DB_C_DOUBLE);
2377  }
2378  break;
2379  case DB_TYPE_C_CHAR:
2380  case DB_TYPE_C_VARCHAR:
2381  {
2382  char tmp[NUM_BUF_SIZE];
2383  sprintf (tmp, "%f", (DB_C_DOUBLE) d);
2384  error_code =
2385  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2386  }
2387  break;
2388  case DB_TYPE_C_NCHAR:
2389  case DB_TYPE_C_VARNCHAR:
2390  {
2391  char tmp[NUM_BUF_SIZE];
2392  sprintf (tmp, "%f", (DB_C_DOUBLE) d);
2393  error_code =
2394  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2395  }
2396  break;
2397  default:
2398  goto unsupported_conversion;
2399  }
2400  } /* DB_TYPE_DOUBLE */
2401  break;
2402 
2403  case DB_TYPE_MONETARY:
2404  {
2405  DB_MONETARY *money = db_get_monetary (value);
2406  double d = money->amount;
2407 
2408  switch (c_type)
2409  {
2410  case DB_TYPE_C_INT:
2411  {
2412  *(DB_C_INT *) buf = (DB_C_INT) d;
2413  *xflen = sizeof (DB_C_INT);
2414  }
2415  break;
2416  case DB_TYPE_C_SHORT:
2417  {
2418  *(DB_C_SHORT *) buf = (DB_C_SHORT) d;
2419  *xflen = sizeof (DB_C_SHORT);
2420  }
2421  break;
2422  case DB_TYPE_C_LONG:
2423  {
2424  *(DB_C_LONG *) buf = (DB_C_LONG) d;
2425  *xflen = sizeof (DB_C_LONG);
2426  }
2427  break;
2428  case DB_TYPE_C_FLOAT:
2429  {
2430  *(DB_C_FLOAT *) buf = (DB_C_FLOAT) d;
2431  *xflen = sizeof (DB_C_FLOAT);
2432  }
2433  break;
2434  case DB_TYPE_C_DOUBLE:
2435  {
2436  *(DB_C_DOUBLE *) buf = (DB_C_DOUBLE) d;
2437  *xflen = sizeof (DB_C_DOUBLE);
2438  }
2439  break;
2440  case DB_TYPE_C_MONETARY:
2441  {
2442  /*
2443  * WARNING: this works only so long as DB_C_MONETARY
2444  * is typedef'ed as a DB_MONETARY. If that changes,
2445  * so must this.
2446  */
2447  *(DB_C_MONETARY *) buf = *money;
2448  *xflen = sizeof (DB_C_MONETARY);
2449  }
2450  break;
2451  case DB_TYPE_C_CHAR:
2452  case DB_TYPE_C_VARCHAR:
2453  {
2454  char tmp[NUM_BUF_SIZE];
2455  sprintf (tmp, "%4.2f", (DB_C_DOUBLE) d);
2456  error_code =
2457  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2458  }
2459  break;
2460  case DB_TYPE_C_NCHAR:
2461  case DB_TYPE_C_VARNCHAR:
2462  {
2463  char tmp[NUM_BUF_SIZE];
2464  sprintf (tmp, "%4.2f", (DB_C_DOUBLE) d);
2465  error_code =
2466  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2467  }
2468  break;
2469  default:
2470  goto unsupported_conversion;
2471  }
2472  } /* DB_TYPE_MONETARY */
2473  break;
2474 
2475  case DB_TYPE_VARCHAR:
2476  case DB_TYPE_CHAR:
2477  case DB_TYPE_VARNCHAR:
2478  case DB_TYPE_NCHAR:
2479  {
2480  const char *s = db_get_string (value);
2481  int n = db_get_string_size (value);
2482 
2483  if (s == NULL)
2484  {
2485  goto invalid_args;
2486  }
2487 
2488  switch (c_type)
2489  {
2490  case DB_TYPE_C_INT:
2491  {
2492  char tmp[NUM_BUF_SIZE];
2493  if (n >= NUM_BUF_SIZE)
2494  {
2495  goto invalid_args;
2496  }
2497 
2498  memcpy (tmp, s, n);
2499  tmp[n] = '\0';
2500  *(DB_C_INT *) buf = (DB_C_INT) atol (tmp);
2501  *xflen = sizeof (DB_C_INT);
2502  }
2503  break;
2504  case DB_TYPE_C_SHORT:
2505  {
2506  char tmp[NUM_BUF_SIZE];
2507  if (n >= NUM_BUF_SIZE)
2508  {
2509  goto invalid_args;
2510  }
2511 
2512  memcpy (tmp, s, n);
2513  tmp[n] = '\0';
2514  *(DB_C_SHORT *) buf = (DB_C_SHORT) atol (tmp);
2515  *xflen = sizeof (DB_C_SHORT);
2516  }
2517  break;
2518  case DB_TYPE_C_LONG:
2519  {
2520  char tmp[NUM_BUF_SIZE];
2521  if (n >= NUM_BUF_SIZE)
2522  {
2523  goto invalid_args;
2524  }
2525 
2526  memcpy (tmp, s, n);
2527  tmp[n] = '\0';
2528  *(DB_C_LONG *) buf = (DB_C_LONG) atol (tmp);
2529  *xflen = sizeof (DB_C_LONG);
2530  }
2531  break;
2532  case DB_TYPE_C_FLOAT:
2533  {
2534  char tmp[NUM_BUF_SIZE];
2535  if (n >= NUM_BUF_SIZE)
2536  {
2537  goto invalid_args;
2538  }
2539 
2540  memcpy (tmp, s, n);
2541  tmp[n] = '\0';
2542  *(DB_C_FLOAT *) buf = (DB_C_FLOAT) atof (tmp);
2543  *xflen = sizeof (DB_C_FLOAT);
2544  }
2545  break;
2546  case DB_TYPE_C_DOUBLE:
2547  {
2548  char tmp[NUM_BUF_SIZE];
2549  if (n >= NUM_BUF_SIZE)
2550  {
2551  goto invalid_args;
2552  }
2553 
2554  memcpy (tmp, s, n);
2555  tmp[n] = '\0';
2556  *(DB_C_DOUBLE *) buf = (DB_C_DOUBLE) atof (tmp);
2557  *xflen = sizeof (DB_C_DOUBLE);
2558  }
2559  break;
2560  case DB_TYPE_C_CHAR:
2561  case DB_TYPE_C_VARCHAR:
2562  error_code = transfer_string ((char *) buf, xflen, outlen, buflen, s, n, c_type, LANG_SYS_CODESET);
2563  break;
2564  case DB_TYPE_C_NCHAR:
2565  case DB_TYPE_C_VARNCHAR:
2566  error_code = transfer_string ((char *) buf, xflen, outlen, buflen, s, n, c_type, LANG_SYS_CODESET);
2567  break;
2568 
2569  default:
2570  goto unsupported_conversion;
2571  }
2572  } /* DB_TYPE_VARCHAR, DB_TYPE_CHAR */
2573  break;
2574 
2575  case DB_TYPE_OBJECT:
2576  {
2577  switch (c_type)
2578  {
2579  case DB_TYPE_C_OBJECT:
2580  {
2581  *(DB_OBJECT **) buf = (DB_OBJECT *) db_get_object (value);
2582  *xflen = sizeof (DB_OBJECT *);
2583  }
2584  break;
2585  default:
2586  goto unsupported_conversion;
2587  }
2588  } /* DB_TYPE_OBJECT */
2589  break;
2590 
2591  case DB_TYPE_SET:
2592  case DB_TYPE_MULTISET:
2593  case DB_TYPE_SEQUENCE:
2594  {
2595  switch (c_type)
2596  {
2597  case DB_TYPE_C_SET:
2598  {
2599  *(DB_SET **) buf = (DB_SET *) db_get_set (value);
2600  *xflen = sizeof (DB_SET *);
2601  }
2602  break;
2603  default:
2604  goto unsupported_conversion;
2605  }
2606  }
2607  break;
2608 
2609  case DB_TYPE_TIME:
2610  {
2611  switch (c_type)
2612  {
2613  case DB_TYPE_C_TIME:
2614  {
2615  *(DB_TIME *) buf = *(db_get_time (value));
2616  *xflen = sizeof (DB_TIME);
2617  }
2618  break;
2619  case DB_TYPE_C_CHAR:
2620  case DB_TYPE_C_VARCHAR:
2621  {
2622  int n;
2623  char tmp[TIME_BUF_SIZE];
2624  n = db_time_to_string (tmp, sizeof (tmp), db_get_time (value));
2625  if (n < 0)
2626  {
2627  goto invalid_args;
2628  }
2629  error_code =
2630  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2631  }
2632  break;
2633  case DB_TYPE_C_NCHAR:
2634  case DB_TYPE_C_VARNCHAR:
2635  {
2636  int n;
2637  char tmp[TIME_BUF_SIZE];
2638  n = db_time_to_string (tmp, sizeof (tmp), db_get_time (value));
2639  if (n < 0)
2640  {
2641  goto invalid_args;
2642  }
2643  error_code =
2644  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2645  }
2646  break;
2647  default:
2648  goto unsupported_conversion;
2649  }
2650  } /* DB_TYPE_TIME */
2651  break;
2652 
2653  case DB_TYPE_TIMESTAMP:
2654  {
2655  switch (c_type)
2656  {
2657  case DB_TYPE_C_TIMESTAMP:
2658  {
2659  *(DB_TIMESTAMP *) buf = *(db_get_timestamp (value));
2660  *xflen = sizeof (DB_TIMESTAMP);
2661  }
2662  break;
2663  case DB_TYPE_C_CHAR:
2664  case DB_TYPE_C_VARCHAR:
2665  {
2666  int n;
2667  char tmp[TIMESTAMP_BUF_SIZE];
2668  n = db_timestamp_to_string (tmp, sizeof (tmp), db_get_timestamp (value));
2669  if (n < 0)
2670  {
2671  goto invalid_args;
2672  }
2673  error_code =
2674  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2675 
2676  }
2677  break;
2678  case DB_TYPE_C_NCHAR:
2679  case DB_TYPE_C_VARNCHAR:
2680  {
2681  int n;
2682  char tmp[TIMESTAMP_BUF_SIZE];
2683  n = db_timestamp_to_string (tmp, sizeof (tmp), db_get_timestamp (value));
2684  if (n < 0)
2685  {
2686  goto invalid_args;
2687  }
2688  error_code =
2689  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2690  }
2691  break;
2692  default:
2693  goto unsupported_conversion;
2694  }
2695  } /* DB_TYPE_TIMESTAMP */
2696  break;
2697 
2698  case DB_TYPE_DATETIME:
2699  {
2700  switch (c_type)
2701  {
2702  case DB_TYPE_C_DATETIME:
2703  {
2704  *(DB_DATETIME *) buf = *(db_get_datetime (value));
2705  *xflen = sizeof (DB_DATETIME);
2706  }
2707  break;
2708  case DB_TYPE_C_CHAR:
2709  case DB_TYPE_C_VARCHAR:
2710  {
2711  int n;
2712  char tmp[DATETIME_BUF_SIZE];
2713  n = db_datetime_to_string (tmp, sizeof (tmp), db_get_datetime (value));
2714  if (n < 0)
2715  {
2716  goto invalid_args;
2717  }
2718  error_code =
2719  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2720 
2721  }
2722  break;
2723  case DB_TYPE_C_NCHAR:
2724  case DB_TYPE_C_VARNCHAR:
2725  {
2726  int n;
2727  char tmp[DATETIME_BUF_SIZE];
2728  n = db_datetime_to_string (tmp, sizeof (tmp), db_get_datetime (value));
2729  if (n < 0)
2730  {
2731  goto invalid_args;
2732  }
2733  error_code =
2734  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2735  }
2736  break;
2737  default:
2738  goto unsupported_conversion;
2739  }
2740  } /* DB_TYPE_DATETIME */
2741  break;
2742 
2743  case DB_TYPE_DATE:
2744  {
2745  switch (c_type)
2746  {
2747  case DB_TYPE_C_DATE:
2748  {
2749  *(DB_DATE *) buf = *(db_get_date (value));
2750  *xflen = sizeof (DB_DATE);
2751  }
2752  break;
2753  case DB_TYPE_C_CHAR:
2754  case DB_TYPE_C_VARCHAR:
2755  {
2756  int n;
2757  char tmp[DATE_BUF_SIZE];
2758  n = db_date_to_string (tmp, sizeof (tmp), db_get_date (value));
2759  if (n < 0)
2760  {
2761  goto invalid_args;
2762  }
2763  error_code =
2764  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2765  }
2766  break;
2767  case DB_TYPE_C_NCHAR:
2768  case DB_TYPE_C_VARNCHAR:
2769  {
2770  int n;
2771  char tmp[DATE_BUF_SIZE];
2772  n = db_date_to_string (tmp, sizeof (tmp), db_get_date (value));
2773  if (n < 0)
2774  {
2775  goto invalid_args;
2776  }
2777  error_code =
2778  transfer_string ((char *) buf, xflen, outlen, buflen, tmp, strlen (tmp), c_type, LANG_SYS_CODESET);
2779  }
2780  break;
2781  default:
2782  goto unsupported_conversion;
2783  }
2784  } /* DB_TYPE_DATE */
2785  break;
2786 
2787  case DB_TYPE_NUMERIC:
2788  {
2789  switch (c_type)
2790  {
2791  case DB_TYPE_C_INT:
2792  case DB_TYPE_C_SHORT:
2793  case DB_TYPE_C_LONG:
2794  case DB_TYPE_C_BIGINT:
2795  {
2796  DB_VALUE v;
2797  DB_DATA_STATUS status;
2798 
2800  (void) numeric_db_value_coerce_from_num (value, &v, &status);
2801  if (status != NO_ERROR)
2802  {
2803  goto invalid_args;
2804  }
2805  error_code = db_value_get (&v, c_type, buf, buflen, xflen, outlen);
2806  pr_clear_value (&v);
2807  }
2808  break;
2809  case DB_TYPE_C_FLOAT:
2810  case DB_TYPE_C_DOUBLE:
2811  {
2812  DB_VALUE v;
2813  DB_DATA_STATUS status;
2814 
2816  (void) numeric_db_value_coerce_from_num (value, &v, &status);
2817  if (status != NO_ERROR)
2818  {
2819  goto invalid_args;
2820  }
2821  error_code = db_value_get (&v, c_type, buf, buflen, xflen, outlen);
2822  pr_clear_value (&v);
2823  }
2824  break;
2825  case DB_TYPE_C_CHAR:
2826  case DB_TYPE_C_VARCHAR:
2827  case DB_TYPE_C_NCHAR:
2828  case DB_TYPE_C_VARNCHAR:
2829  {
2830  DB_VALUE v;
2831  DB_DATA_STATUS status;
2832 
2834  (void) numeric_db_value_coerce_from_num (value, &v, &status);
2835  if (status != NO_ERROR)
2836  {
2837  goto invalid_args;
2838  }
2839  error_code = db_value_get (&v, c_type, buf, buflen, xflen, outlen);
2840  pr_clear_value (&v);
2841  }
2842  break;
2843  default:
2844  goto unsupported_conversion;
2845  }
2846  } /* DB_TYPE_NUMERIC */
2847  break;
2848 
2849  case DB_TYPE_BIT:
2850  case DB_TYPE_VARBIT:
2851  {
2852  switch (c_type)
2853  {
2854  case DB_TYPE_C_BIT:
2855  case DB_TYPE_C_VARBIT:
2856  error_code = transfer_bit_string ((char *) buf, xflen, outlen, buflen, value, c_type);
2857  break;
2858  case DB_TYPE_C_CHAR:
2859  case DB_TYPE_C_NCHAR:
2860  {
2861  int truncated;
2862  qstr_bit_to_hex_coerce ((char *) buf, buflen,
2863  db_get_string (value), db_get_string_length (value), true, xflen, &truncated);
2864  if (truncated > 0)
2865  {
2866  if (outlen)
2867  {
2868  *outlen = truncated;
2869  }
2870  else
2871  {
2872  error_code = ER_UCI_NULL_IND_NEEDED;
2874  }
2875  }
2876  }
2877  break;
2878  case DB_TYPE_C_VARCHAR:
2879  case DB_TYPE_C_VARNCHAR:
2880  {
2881  int truncated;
2882  qstr_bit_to_hex_coerce ((char *) buf, buflen,
2883  db_get_string (value), db_get_string_length (value), false, xflen, &truncated);
2884  if (truncated > 0)
2885  {
2886  if (outlen)
2887  {
2888  *outlen = truncated;
2889  }
2890  else
2891  {
2892  error_code = ER_UCI_NULL_IND_NEEDED;
2894  }
2895  }
2896  }
2897  break;
2898  default:
2899  goto unsupported_conversion;
2900  }
2901  } /* DB_TYPE_BIT, DB_TYPE_VARBIT */
2902  break;
2903 
2904  case DB_TYPE_BLOB:
2905  case DB_TYPE_CLOB:
2906  case DB_TYPE_VARIABLE:
2907  case DB_TYPE_SUB:
2908  case DB_TYPE_POINTER:
2909  case DB_TYPE_ERROR:
2910  case DB_TYPE_VOBJ:
2911  case DB_TYPE_OID: /* Probably won't ever happen */
2912  goto unsupported_conversion;
2913 
2914  case DB_TYPE_FIRST:
2915  case DB_TYPE_DB_VALUE:
2916  case DB_TYPE_RESULTSET:
2917  case DB_TYPE_MIDXKEY:
2918  case DB_TYPE_TABLE: /* Should be impossible. */
2919  goto invalid_args;
2920 
2921 #if 1 /* TODO - */
2922  case DB_TYPE_ENUMERATION:
2923  break;
2924 #endif
2925 
2926  default:
2927  break;
2928  }
2929 
2930  if (error_code != NO_ERROR)
2931  {
2932  goto error0;
2933  }
2934 
2935  return NO_ERROR;
2936 
2937 invalid_args:
2938  error_code = ER_OBJ_INVALID_ARGUMENTS;
2939  goto error0;
2940 
2941 error0:
2942  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, error_code, 0);
2943  return error_code;
2944 
2945 unsupported_conversion:
2948 }
2949 
2950 /*
2951  * coerce_char_to_dbvalue() - Coerce the C character string into the
2952  * desired type and place in a DB_VALUE container.
2953  * return :
2954  * C_TO_VALUE_NOERROR - No errors occurred
2955  * C_TO_VALUE_UNSUPPORTED_CONVERSION - The conversion to the db_value
2956  * type is not supported
2957  * value(in/out): DB_VALUE container for result. This also contains the DB
2958  * type to convert to.
2959  * buf(in) : Pointer to character buffer
2960  * buflen(in) : Length of character buffer (size in bytes)
2961  *
2962  */
2963 static int
2964 coerce_char_to_dbvalue (DB_VALUE * value, char *buf, const int buflen)
2965 {
2966  int status = C_TO_VALUE_NOERROR;
2967  DB_TYPE db_type = DB_VALUE_DOMAIN_TYPE (value);
2968 
2969  switch (db_type)
2970  {
2971  case DB_TYPE_CHAR:
2972  case DB_TYPE_VARCHAR:
2973  {
2974  int char_count;
2975  int precision = DB_VALUE_PRECISION (value);
2976 
2977  intl_char_count ((unsigned char *) buf, buflen, LANG_SYS_CODESET, &char_count);
2978 
2979  if (precision == TP_FLOATING_PRECISION_VALUE && buflen != 0)
2980  {
2981  precision = char_count;
2982  }
2983 
2984  if ((precision == TP_FLOATING_PRECISION_VALUE)
2985  || (db_type == DB_TYPE_VARCHAR && precision >= char_count)
2986  || (db_type == DB_TYPE_CHAR && precision == char_count))
2987  {
2988  qstr_make_typed_string (db_type, value, precision, buf, buflen, LANG_SYS_CODESET, LANG_SYS_COLLATION);
2989  }
2990  else
2991  {
2992  DB_VALUE tmp_value;
2993  DB_DATA_STATUS data_status;
2994  int error;
2995 
2996  qstr_make_typed_string (db_type, &tmp_value, precision, buf, buflen, LANG_SYS_CODESET, LANG_SYS_COLLATION);
2997 
2998  error = db_char_string_coerce (&tmp_value, value, &data_status);
2999  if (error != NO_ERROR)
3000  {
3001  status = C_TO_VALUE_CONVERSION_ERROR;
3002  }
3003  else if (data_status == DATA_STATUS_TRUNCATED)
3004  {
3005  status = C_TO_VALUE_TRUNCATION_ERROR;
3006  }
3007 
3008  (void) db_value_clear (&tmp_value);
3009  }
3010  }
3011  break;
3012  case DB_TYPE_NCHAR:
3013  case DB_TYPE_VARNCHAR:
3014  {
3015  int char_count;
3016  int precision = DB_VALUE_PRECISION (value);
3017 
3018  intl_char_count ((unsigned char *) buf, buflen, LANG_SYS_CODESET, &char_count);
3019 
3020  if (precision == TP_FLOATING_PRECISION_VALUE)
3021  {
3022  precision = char_count;
3023  }
3024 
3025  if ((db_type == DB_TYPE_VARNCHAR && precision >= char_count)
3026  || (db_type == DB_TYPE_NCHAR && precision == char_count))
3027  {
3028 
3029  qstr_make_typed_string (db_type, value, precision, buf, buflen, LANG_SYS_CODESET, LANG_SYS_COLLATION);
3030  }
3031  else
3032  {
3033  DB_VALUE tmp_value;
3034  DB_DATA_STATUS data_status;
3035 
3036  qstr_make_typed_string (db_type, &tmp_value, precision, buf, buflen, LANG_SYS_CODESET, LANG_SYS_COLLATION);
3037 
3038  (void) db_char_string_coerce (&tmp_value, value, &data_status);
3039  if (data_status == DATA_STATUS_TRUNCATED)
3040  {
3041  status = C_TO_VALUE_TRUNCATION_ERROR;
3042  }
3043 
3044  (void) db_value_clear (&tmp_value);
3045  }
3046  }
3047  break;
3048  case DB_TYPE_BIT:
3049  case DB_TYPE_VARBIT:
3050  {
3051  DB_VALUE tmp_value;
3052  DB_DATA_STATUS data_status;
3053 
3055  if (db_string_value (buf, buflen, "%H", &tmp_value) == NULL)
3056  {
3057  status = C_TO_VALUE_CONVERSION_ERROR;
3058  }
3059  else
3060  {
3061  /*
3062  * If the precision is not specified, fix it to
3063  * the input precision otherwise db_bit_string_coerce()
3064  * will fail.
3065  */
3067  {
3068  db_value_domain_init (value, db_type, db_get_string_length (&tmp_value), DB_DEFAULT_SCALE);
3069  }
3070 
3071  (void) db_bit_string_coerce (&tmp_value, value, &data_status);
3072  if (data_status == DATA_STATUS_TRUNCATED)
3073  {
3074  status = C_TO_VALUE_TRUNCATION_ERROR;
3075  }
3076  }
3077 
3078  (void) db_value_clear (&tmp_value);
3079  }
3080  break;
3081  case DB_TYPE_DOUBLE:
3082  case DB_TYPE_FLOAT:
3083  case DB_TYPE_INTEGER:
3084  case DB_TYPE_SHORT:
3085  case DB_TYPE_BIGINT:
3086  case DB_TYPE_DATE:
3087  case DB_TYPE_TIME:
3088  case DB_TYPE_TIMESTAMP:
3089  case DB_TYPE_DATETIME:
3090  case DB_TYPE_MONETARY:
3091  if (db_string_value (buf, buflen, "", value) == NULL)
3092  {
3093  status = C_TO_VALUE_CONVERSION_ERROR;
3094  }
3095  break;
3096  case DB_TYPE_NUMERIC:
3097  {
3098  DB_VALUE tmp_value;
3099  unsigned char new_num[DB_NUMERIC_BUF_SIZE];
3100  int desired_precision = DB_VALUE_PRECISION (value);
3101  int desired_scale = DB_VALUE_SCALE (value);
3102 
3103  /* string_to_num will coerce the string to a numeric, but will set the precision and scale based on the value
3104  * passed. Then we call num_to_num to coerce to the desired precision and scale. */
3105 
3106  if (numeric_coerce_string_to_num (buf, buflen, LANG_SYS_CODESET, &tmp_value) != NO_ERROR)
3107  {
3108  status = C_TO_VALUE_CONVERSION_ERROR;
3109  }
3110  else
3112  (db_get_numeric (&tmp_value), DB_VALUE_PRECISION (&tmp_value),
3113  DB_VALUE_SCALE (&tmp_value), desired_precision, desired_scale, new_num) != NO_ERROR)
3114  {
3115  status = C_TO_VALUE_CONVERSION_ERROR;
3116  }
3117  else
3118  {
3119  /* Yes, I know that the precision and scale are already set, but this is neater than just assigning the
3120  * value. */
3121  db_make_numeric (value, new_num, desired_precision, desired_scale);
3122  }
3123 
3124  db_value_clear (&tmp_value);
3125  }
3126  break;
3127  default:
3129  break;
3130  }
3131 
3132  return status;
3133 }
3134 
3135 /*
3136  * coerce_numeric_to_dbvalue() - Coerce the C character number string
3137  * into the desired type and place in a DB_VALUE container.
3138  *
3139  * return :
3140  * C_TO_VALUE_NOERROR - no errors occurred
3141  * C_TO_VALUE_UNSUPPORTED_CONVERSION - The conversion to the db_value
3142  * type is not supported.
3143  * value(out) : DB_VALUE container for result. This also contains the DB
3144  * type to convert to.
3145  * buf(in) : Pointer to character buffer.
3146  * c_type(in) : type of c string to coerce.
3147  */
3148 
3149 static int
3150 coerce_numeric_to_dbvalue (DB_VALUE * value, char *buf, const DB_TYPE_C c_type)
3151 {
3152  int status = C_TO_VALUE_NOERROR;
3153  DB_TYPE db_type = DB_VALUE_DOMAIN_TYPE (value);
3154 
3155  switch (c_type)
3156  {
3157  case DB_TYPE_C_INT:
3158  {
3159  DB_C_INT num = *(DB_C_INT *) buf;
3160 
3161  switch (db_type)
3162  {
3163  case DB_TYPE_NUMERIC:
3164  {
3165  DB_DATA_STATUS data_status;
3166  DB_VALUE value2;
3167 
3168  db_make_int (&value2, (int) num);
3169  (void) numeric_db_value_coerce_to_num (&value2, value, &data_status);
3170  }
3171  break;
3172  case DB_TYPE_INTEGER:
3173  db_make_int (value, (int) num);
3174  break;
3175  case DB_TYPE_BIGINT:
3176  db_make_bigint (value, (DB_C_BIGINT) num);
3177  break;
3178  case DB_TYPE_FLOAT:
3179  db_make_float (value, (DB_C_FLOAT) num);
3180  break;
3181  case DB_TYPE_DOUBLE:
3182  db_make_double (value, (DB_C_DOUBLE) num);
3183  break;
3184  case DB_TYPE_SHORT:
3185  db_make_short (value, (DB_C_SHORT) num);
3186  break;
3187  case DB_TYPE_MONETARY:
3189  break;
3190  default:
3192  break;
3193  }
3194  }
3195  break;
3196 
3197  case DB_TYPE_C_SHORT:
3198  {
3199  DB_C_SHORT num = *(DB_C_SHORT *) buf;
3200 
3201  switch (db_type)
3202  {
3203  case DB_TYPE_NUMERIC:
3204  {
3205  DB_DATA_STATUS data_status;
3206  DB_VALUE value2;
3207 
3208  db_make_short (&value2, (DB_C_SHORT) num);
3209  (void) numeric_db_value_coerce_to_num (&value2, value, &data_status);
3210  }
3211  break;
3212  case DB_TYPE_INTEGER:
3213  db_make_int (value, (int) num);
3214  break;
3215  case DB_TYPE_BIGINT:
3216  db_make_bigint (value, (DB_C_BIGINT) num);
3217  break;
3218  case DB_TYPE_FLOAT:
3219  db_make_float (value, (DB_C_FLOAT) num);
3220  break;
3221  case DB_TYPE_DOUBLE:
3222  db_make_double (value, (DB_C_DOUBLE) num);
3223  break;
3224  case DB_TYPE_SHORT:
3225  db_make_short (value, (DB_C_SHORT) num);
3226  break;
3227  case DB_TYPE_MONETARY:
3229  break;
3230  default:
3232  break;
3233  }
3234  }
3235  break;
3236 
3237  case DB_TYPE_C_LONG:
3238  {
3239  DB_C_LONG num = *(DB_C_LONG *) buf;
3240 
3241  switch (db_type)
3242  {
3243  case DB_TYPE_NUMERIC:
3244  {
3245  DB_DATA_STATUS data_status;
3246  DB_VALUE value2;
3247 
3248  db_make_int (&value2, (int) num);
3249  (void) numeric_db_value_coerce_to_num (&value2, value, &data_status);
3250  }
3251  break;
3252  case DB_TYPE_INTEGER:
3253  db_make_int (value, (int) num);
3254  break;
3255  case DB_TYPE_BIGINT:
3256  db_make_bigint (value, (DB_C_BIGINT) num);
3257  break;
3258  case DB_TYPE_FLOAT:
3259  db_make_float (value, (DB_C_FLOAT) num);
3260  break;
3261  case DB_TYPE_DOUBLE:
3262  db_make_double (value, (DB_C_DOUBLE) num);
3263  break;
3264  case DB_TYPE_SHORT:
3265  db_make_short (value, (DB_C_SHORT) num);
3266  break;
3267  case DB_TYPE_MONETARY:
3269  break;
3270  default:
3272  break;
3273  }
3274  }
3275  break;
3276 
3277  case DB_TYPE_C_FLOAT:
3278  {
3279  DB_C_FLOAT num = *(DB_C_FLOAT *) buf;
3280 
3281  switch (db_type)
3282  {
3283  case DB_TYPE_NUMERIC:
3284  {
3285  DB_DATA_STATUS data_status;
3286  DB_VALUE value2;
3287 
3288  db_make_double (&value2, (DB_C_DOUBLE) num);
3289  (void) numeric_db_value_coerce_to_num (&value2, value, &data_status);
3290  }
3291  break;
3292  case DB_TYPE_INTEGER:
3293  db_make_int (value, (int) num);
3294  break;
3295  case DB_TYPE_BIGINT:
3296  db_make_bigint (value, (DB_C_BIGINT) num);
3297  break;
3298  case DB_TYPE_FLOAT:
3299  db_make_float (value, (DB_C_FLOAT) num);
3300  break;
3301  case DB_TYPE_DOUBLE:
3302  db_make_double (value, (DB_C_DOUBLE) num);
3303  break;
3304  case DB_TYPE_SHORT:
3305  db_make_short (value, (DB_C_SHORT) num);
3306  break;
3307  case DB_TYPE_MONETARY:
3309  break;
3310  default:
3312  break;
3313  }
3314  }
3315  break;
3316 
3317  case DB_TYPE_C_DOUBLE:
3318  {
3319  DB_C_DOUBLE num = *(DB_C_DOUBLE *) buf;
3320 
3321  switch (db_type)
3322  {
3323  case DB_TYPE_NUMERIC:
3324  {
3325  DB_DATA_STATUS data_status;
3326  DB_VALUE value2;
3327 
3328  db_make_double (&value2, (DB_C_DOUBLE) num);
3329  (void) numeric_db_value_coerce_to_num (&value2, value, &data_status);
3330  }
3331  break;
3332  case DB_TYPE_INTEGER:
3333  db_make_int (value, (int) num);
3334  break;
3335  case DB_TYPE_BIGINT:
3336  db_make_bigint (value, (DB_C_BIGINT) num);
3337  break;
3338  case DB_TYPE_FLOAT:
3339  db_make_float (value, (DB_C_FLOAT) num);
3340  break;
3341  case DB_TYPE_DOUBLE:
3342  db_make_double (value, (DB_C_DOUBLE) num);
3343  break;
3344  case DB_TYPE_SHORT:
3345  db_make_short (value, (DB_C_SHORT) num);
3346  break;
3347  case DB_TYPE_MONETARY:
3349  break;
3350  default:
3352  break;
3353  }
3354  }
3355  break;
3356 
3357  case DB_TYPE_C_MONETARY:
3358  {
3359  DB_C_MONETARY *money = (DB_C_MONETARY *) buf;
3360  double num = money->amount;
3361 
3362  switch (db_type)
3363  {
3364  case DB_TYPE_NUMERIC:
3365  /*
3366  * We need a better way to convert a numerical C type
3367  * into a NUMERIC. This will have to suffice for now.
3368  */
3369  {
3370  DB_DATA_STATUS data_status;
3371  DB_VALUE value2;
3372 
3373  db_make_double (&value2, (DB_C_DOUBLE) num);
3374  (void) numeric_db_value_coerce_to_num (&value2, value, &data_status);
3375  }
3376  break;
3377  case DB_TYPE_INTEGER:
3378  db_make_int (value, (int) num);
3379  break;
3380  case DB_TYPE_BIGINT:
3381  db_make_bigint (value, (DB_C_BIGINT) num);
3382  break;
3383  case DB_TYPE_FLOAT:
3384  db_make_float (value, (DB_C_FLOAT) num);
3385  break;
3386  case DB_TYPE_DOUBLE:
3387  db_make_double (value, (DB_C_DOUBLE) num);
3388  break;
3389  case DB_TYPE_SHORT:
3390  db_make_short (value, (DB_C_SHORT) num);
3391  break;
3392  case DB_TYPE_MONETARY:
3393  db_make_monetary (value, money->type, money->amount);
3394  break;
3395  default:
3397  break;
3398  }
3399  }
3400  break;
3401 
3402  default:
3404  break;
3405  }
3406 
3407  return status;
3408 }
3409 
3410 /*
3411  * coerce_binary_to_dbvalue() - Coerce a C bit type into the desired type
3412  * and place in a DB_VALUE container.
3413  * return :
3414  * C_TO_VALUE_NOERROR - No errors occurred
3415  * C_TO_VALUE_UNSUPPORTED_CONVERSION - The conversion to the db_value
3416  * type is not supported
3417  * C_TO_VALUE_CONVERSION_ERROR - An error occurred during conversion
3418  * C_TO_VALUE_TRUNCATION_ERROR - The input data was truncated
3419  * during coercion
3420  * value(in/out) : DB_VALUE container for result. This also contains the DB
3421  * type to convert to.
3422  * buf(in) : Pointer to data buffer
3423  * buflen(in) : Length of data (in bits)
3424  */
3425 static int
3426 coerce_binary_to_dbvalue (DB_VALUE * value, char *buf, const int buflen)
3427 {
3428  int status = C_TO_VALUE_NOERROR;
3429  DB_TYPE db_type = DB_VALUE_DOMAIN_TYPE (value);
3430 
3431  switch (db_type)
3432  {
3433  case DB_TYPE_BIT:
3434  case DB_TYPE_VARBIT:
3435  {
3436  int precision = DB_VALUE_PRECISION (value);
3437 
3438  if (precision == TP_FLOATING_PRECISION_VALUE && buflen != 0)
3439  {
3440  precision = buflen;
3441  }
3442 
3443  if ((precision == TP_FLOATING_PRECISION_VALUE)
3444  || (db_type == DB_TYPE_VARBIT && precision >= buflen) || (db_type == DB_TYPE_BIT && precision == buflen))
3445  {
3446  qstr_make_typed_string (db_type, value, precision, buf, buflen, INTL_CODESET_RAW_BITS, 0);
3447  }
3448  else
3449  {
3450  DB_VALUE tmp_value;
3451  DB_DATA_STATUS data_status;
3452  int error;
3453 
3454  qstr_make_typed_string (db_type, &tmp_value, precision, buf, buflen, INTL_CODESET_RAW_BITS, 0);
3455 
3456  error = db_bit_string_coerce (&tmp_value, value, &data_status);
3457  if (error != NO_ERROR)
3458  {
3459  status = C_TO_VALUE_CONVERSION_ERROR;
3460  }
3461  else if (data_status == DATA_STATUS_TRUNCATED)
3462  {
3463  status = C_TO_VALUE_TRUNCATION_ERROR;
3464  }
3465 
3466  (void) db_value_clear (&tmp_value);
3467  }
3468  }
3469  break;
3470  case DB_TYPE_CHAR:
3471  case DB_TYPE_VARCHAR:
3472  {
3473  int error_code;
3474  DB_VALUE tmp_value;
3475  DB_DATA_STATUS data_status;
3476 
3477  db_make_varchar (&tmp_value, DB_DEFAULT_PRECISION, buf,
3479 
3480  /*
3481  * If the precision is not specified, fix it to
3482  * the input precision otherwise db_char_string_coerce()
3483  * will fail.
3484  */
3486  {
3487  db_value_domain_init (value, db_type, QSTR_NUM_BYTES (buflen), 0);
3488  }
3489 
3490  error_code = db_char_string_coerce (&tmp_value, value, &data_status);
3491  if (error_code != NO_ERROR)
3492  {
3493  status = C_TO_VALUE_CONVERSION_ERROR;
3494  }
3495  else if (data_status == DATA_STATUS_TRUNCATED)
3496  {
3497  status = C_TO_VALUE_TRUNCATION_ERROR;
3498  }
3499 
3500  error_code = db_value_clear (&tmp_value);
3501  if (error_code != NO_ERROR)
3502  {
3503  status = C_TO_VALUE_CONVERSION_ERROR;
3504  }
3505  }
3506  break;
3507  case DB_TYPE_NCHAR:
3508  case DB_TYPE_VARNCHAR:
3509  {
3510  int error_code;
3511  DB_VALUE tmp_value;
3512  DB_DATA_STATUS data_status;
3513 
3514  db_make_varnchar (&tmp_value, DB_DEFAULT_PRECISION, buf,
3516 
3517  /*
3518  * If the precision is not specified, fix it to
3519  * the input precision otherwise db_char_string_coerce()
3520  * will fail.
3521  */
3523  {
3524  db_value_domain_init (value, db_type, QSTR_NUM_BYTES (buflen), 0);
3525  }
3526 
3527  error_code = db_char_string_coerce (&tmp_value, value, &data_status);
3528  if (error_code != NO_ERROR)
3529  {
3530  status = C_TO_VALUE_CONVERSION_ERROR;
3531  }
3532  else if (data_status == DATA_STATUS_TRUNCATED)
3533  {
3534  status = C_TO_VALUE_TRUNCATION_ERROR;
3535  }
3536 
3537  error_code = db_value_clear (&tmp_value);
3538  if (error_code != NO_ERROR)
3539  {
3540  status = C_TO_VALUE_CONVERSION_ERROR;
3541  }
3542  }
3543  break;
3544  case DB_TYPE_INTEGER:
3545  db_make_int (value, *(int *) buf);
3546  break;
3547  case DB_TYPE_BIGINT:
3548  db_make_bigint (value, *(DB_C_BIGINT *) buf);
3549  break;
3550  case DB_TYPE_FLOAT:
3551  db_make_float (value, *(DB_C_FLOAT *) buf);
3552  break;
3553  case DB_TYPE_DOUBLE:
3554  db_make_double (value, *(DB_C_DOUBLE *) buf);
3555  break;
3556  case DB_TYPE_SHORT:
3557  db_make_short (value, *(DB_C_SHORT *) buf);
3558  break;
3559  case DB_TYPE_DATE:
3560  db_value_put_encoded_date (value, (DB_DATE *) buf);
3561  break;
3562  case DB_TYPE_TIME:
3563  db_value_put_encoded_time (value, (DB_TIME *) buf);
3564  break;
3565  case DB_TYPE_TIMESTAMP:
3566  db_make_timestamp (value, *(DB_TIMESTAMP *) buf);
3567  break;
3568  case DB_TYPE_DATETIME:
3569  db_make_datetime (value, (DB_DATETIME *) buf);
3570  break;
3571  default:
3573  break;
3574  }
3575 
3576  return status;
3577 }
3578 
3579 /*
3580  * coerce_date_to_dbvalue() - Coerce a C date type into the desired type
3581  * and place in a DB_VALUE container.
3582  * return :
3583  * C_TO_VALUE_NOERROR - No errors occurred
3584  * C_TO_VALUE_UNSUPPORTED_CONVERSION - The conversion to the db_value
3585  * type is not supported
3586  * C_TO_VALUE_CONVERSION_ERROR - An error occurred during conversion
3587  *
3588  * value(in/out): DB_VALUE container for result. This also contains the DB
3589  * type to convert to.
3590  * buf(in) : Pointer to data buffer.
3591  *
3592  */
3593 static int
3594 coerce_date_to_dbvalue (DB_VALUE * value, char *buf)
3595 {
3596  int status = C_TO_VALUE_NOERROR;
3597  DB_TYPE db_type = DB_VALUE_DOMAIN_TYPE (value);
3598  DB_C_DATE *date = (DB_C_DATE *) buf;
3599 
3600  switch (db_type)
3601  {
3602  case DB_TYPE_CHAR:
3603  case DB_TYPE_VARCHAR:
3604  case DB_TYPE_NCHAR:
3605  case DB_TYPE_VARNCHAR:
3606  {
3607  DB_DATE db_date;
3608  char tmp[DATE_BUF_SIZE];
3609 
3610  if (db_date_encode (&db_date, date->month, date->day, date->year) !=
3611  NO_ERROR || db_date_to_string (tmp, DATE_BUF_SIZE, &db_date) == 0)
3612  {
3613  status = C_TO_VALUE_CONVERSION_ERROR;
3614  }
3615  else
3616  {
3617  DB_VALUE tmp_value;
3618  DB_DATA_STATUS data_status;
3619  int length = strlen (tmp);
3620 
3621  if (length == 0)
3622  {
3623  length = 1;
3624  }
3625 
3626  db_make_null (&tmp_value);
3627  qstr_make_typed_string (db_type, &tmp_value, length, tmp, length, LANG_SYS_CODESET, LANG_SYS_COLLATION);
3628 
3629  /*
3630  * If the precision is not specified, fix it to
3631  * the input precision otherwise db_char_string_coerce()
3632  * will fail.
3633  */
3635  {
3636  db_value_domain_init (value, db_type, length, 0);
3637  }
3638 
3639  (void) db_char_string_coerce (&tmp_value, value, &data_status);
3640  if (data_status == DATA_STATUS_TRUNCATED)
3641  {
3642  status = C_TO_VALUE_TRUNCATION_ERROR;
3643  }
3644 
3645  (void) db_value_clear (&tmp_value);
3646  }
3647  }
3648  break;
3649  case DB_TYPE_DATE:
3650  db_make_date (value, date->month, date->day, date->year);
3651  break;
3652  default:
3654  break;
3655  }
3656 
3657  return status;
3658 }
3659 
3660 /*
3661  * coerce_time_to_dbvalue() - Coerce a C time type into the desired type
3662  * and place in a DB_VALUE container.
3663  * return :
3664  * C_TO_VALUE_NOERROR - No errors occurred.
3665  * C_TO_VALUE_UNSUPPORTED_CONVERSION - If the conversion to the db_value
3666  * type is not supported.
3667  * C_TO_VALUE_CONVERSION_ERROR - An error occurred during conversion.
3668  * value(in/out) : DB_VALUE container for result. This also contains the DB
3669  * type to convert to.
3670  * buf(in) : Pointer to data buffer.
3671  *
3672  */
3673 
3674 static int
3675 coerce_time_to_dbvalue (DB_VALUE * value, char *buf)
3676 {
3677  int status = C_TO_VALUE_NOERROR;
3678  DB_TYPE db_type = DB_VALUE_DOMAIN_TYPE (value);
3679  DB_C_TIME *c_time = (DB_C_TIME *) buf;
3680 
3681  switch (db_type)
3682  {
3683  case DB_TYPE_CHAR:
3684  case DB_TYPE_VARCHAR:
3685  case DB_TYPE_NCHAR:
3686  case DB_TYPE_VARNCHAR:
3687  {
3688  DB_TIME db_time;
3689  char tmp[TIME_BUF_SIZE];
3690 
3691  db_time_encode (&db_time, c_time->hour, c_time->minute, c_time->second);
3692  if (db_time_string (&db_time, "", tmp, TIME_BUF_SIZE) != 0)
3693  {
3694  status = C_TO_VALUE_CONVERSION_ERROR;
3695  }
3696  else
3697  {
3698  DB_VALUE tmp_value;
3699  DB_DATA_STATUS data_status;
3700  int length = strlen (tmp);
3701 
3702  if (length == 0)
3703  {
3704  length = 1;
3705  }
3706 
3707  db_make_null (&tmp_value);
3708  qstr_make_typed_string (db_type, &tmp_value, length, tmp, length, LANG_SYS_CODESET, LANG_SYS_COLLATION);
3709 
3710  /*
3711  * If the precision is not specified, fix it to
3712  * the input precision otherwise db_char_string_coerce()
3713  * will fail.
3714  */
3716  {
3717  db_value_domain_init (value, db_type, length, 0);
3718  }
3719 
3720  (void) db_char_string_coerce (&tmp_value, value, &data_status);
3721  if (data_status == DATA_STATUS_TRUNCATED)
3722  {
3723  status = C_TO_VALUE_TRUNCATION_ERROR;
3724  }
3725 
3726  (void) db_value_clear (&tmp_value);
3727  }
3728  }
3729  break;
3730  case DB_TYPE_TIME:
3731  db_make_time (value, c_time->hour, c_time->minute, c_time->second);
3732  break;
3733  default:
3735  break;
3736  }
3737 
3738  return status;
3739 }
3740 
3741 /*
3742  * coerce_timestamp_to_dbvalue() - Coerce a C timestamp type into the
3743  * desired type and place in a DB_VALUE container.
3744  * return :
3745  * C_TO_VALUE_NOERROR - No errors occurred.
3746  * C_TO_VALUE_UNSUPPORTED_CONVERSION - If the conversion to the db_value
3747  * type is not supported.
3748  * C_TO_VALUE_CONVERSION_ERROR - An error occurred during conversion.
3749  *
3750  * value(in/out) : DB_VALUE container for result. This also contains the DB
3751  * type to convert to.
3752  * buf(in) : Pointer to data buffer.
3753  *
3754  */
3755 static int
3757 {
3758  int status = C_TO_VALUE_NOERROR;
3759  DB_TYPE db_type = DB_VALUE_DOMAIN_TYPE (value);
3760  DB_C_TIMESTAMP *timestamp = (DB_C_TIMESTAMP *) buf;
3761 
3762  switch (db_type)
3763  {
3764  case DB_TYPE_CHAR:
3765  case DB_TYPE_VARCHAR:
3766  case DB_TYPE_NCHAR:
3767  case DB_TYPE_VARNCHAR:
3768  {
3769  char tmp[TIME_BUF_SIZE];
3770 
3771  if (db_timestamp_string (timestamp, "", tmp, TIMESTAMP_BUF_SIZE) != 0)
3772  {
3773  status = C_TO_VALUE_CONVERSION_ERROR;
3774  }
3775  else
3776  {
3777  DB_VALUE tmp_value;
3778  DB_DATA_STATUS data_status;
3779  int length = strlen (tmp);
3780 
3781  if (length == 0)
3782  {
3783  length = 1;
3784  }
3785 
3786  db_make_null (&tmp_value);
3787  qstr_make_typed_string (db_type, &tmp_value, length, tmp, length, LANG_SYS_CODESET, LANG_SYS_COLLATION);
3788 
3789  /*
3790  * If the precision is not specified, fix it to
3791  * the input precision otherwise db_char_string_coerce()
3792  * will fail.
3793  */
3795  {
3796  db_value_domain_init (value, db_type, length, 0);
3797  }
3798 
3799  (void) db_char_string_coerce (&tmp_value, value, &data_status);
3800  if (data_status == DATA_STATUS_TRUNCATED)
3801  {
3802  status = C_TO_VALUE_TRUNCATION_ERROR;
3803  }
3804 
3805  (void) db_value_clear (&tmp_value);
3806  }
3807  }
3808  break;
3809  case DB_TYPE_DATE:
3810  {
3811  DB_DATE edate;
3812  DB_TIME etime;
3813 
3814  (void) db_timestamp_decode_ses (timestamp, &edate, &etime);
3815  db_value_put_encoded_date (value, &edate);
3816  }
3817  break;
3818  case DB_TYPE_TIME:
3819  {
3820  DB_DATE edate;
3821  DB_TIME etime;
3822 
3823  (void) db_timestamp_decode_ses (timestamp, &edate, &etime);
3824  db_value_put_encoded_time (value, &etime);
3825  }
3826  break;
3827  case DB_TYPE_TIMESTAMP:
3828  db_make_timestamp (value, *timestamp);
3829  break;
3830  case DB_TYPE_DATETIME:
3831  {
3832  DB_DATETIME tmp_datetime = { 0, 0 };
3833 
3834  (void) db_timestamp_decode_ses (timestamp, &tmp_datetime.date, &tmp_datetime.time);
3835  db_make_datetime (value, &tmp_datetime);
3836  }
3837  break;
3838  default:
3840  break;
3841  }
3842 
3843  return status;
3844 }
3845 
3846 /*
3847  * coerce_datetime_to_dbvalue() - Coerce a C datetime type into the
3848  * desired type and place in a DB_VALUE container.
3849  * return :
3850  * C_TO_VALUE_NOERROR - No errors occured.
3851  * C_TO_VALUE_UNSUPPORTED_CONVERSION - If the conversion to the db_value
3852  * type is not supported.
3853  * C_TO_VALUE_CONVERSION_ERROR - An error occured during conversion.
3854  *
3855  * value(in/out) : DB_VALUE container for result. This also contains the DB
3856  * type to convert to.
3857  * buf(in) : Pointer to data buffer.
3858  *
3859  */
3860 static int
3862 {
3863  int status = C_TO_VALUE_NOERROR;
3864  DB_TYPE db_type = DB_VALUE_DOMAIN_TYPE (value);
3865  DB_DATETIME *datetime = (DB_DATETIME *) buf;
3866 
3867  switch (db_type)
3868  {
3869  case DB_TYPE_CHAR:
3870  case DB_TYPE_VARCHAR:
3871  case DB_TYPE_NCHAR:
3872  case DB_TYPE_VARNCHAR:
3873  {
3874  char tmp[DATETIME_BUF_SIZE];
3875 
3876  if (db_datetime_string (datetime, "", tmp, DATETIME_BUF_SIZE) != 0)
3877  {
3878  status = C_TO_VALUE_CONVERSION_ERROR;
3879  }
3880  else
3881  {
3882  DB_VALUE tmp_value;
3883  DB_DATA_STATUS data_status;
3884  int length = strlen (tmp);
3885 
3886  if (length == 0)
3887  {
3888  length = 1;
3889  }
3890 
3891  db_make_null (&tmp_value);
3892  qstr_make_typed_string (db_type, &tmp_value, length, tmp, length, LANG_SYS_CODESET, LANG_SYS_COLLATION);
3893 
3894  /*
3895  * If the precision is not specified, fix it to
3896  * the input precision otherwise db_char_string_coerce()
3897  * will fail.
3898  */
3900  {
3901  db_value_domain_init (value, db_type, length, 0);
3902  }
3903 
3904  (void) db_char_string_coerce (&tmp_value, value, &data_status);
3905  if (data_status == DATA_STATUS_TRUNCATED)
3906  {
3907  status = C_TO_VALUE_TRUNCATION_ERROR;
3908  }
3909 
3910  (void) db_value_clear (&tmp_value);
3911  }
3912  }
3913  break;
3914  case DB_TYPE_DATE:
3915  {
3916  DB_DATE tmp_date;
3917 
3918  tmp_date = datetime->date;
3919  db_value_put_encoded_date (value, &tmp_date);
3920  }
3921  break;
3922  case DB_TYPE_TIME:
3923  {
3924  DB_TIME tmp_time;
3925 
3926  tmp_time = datetime->time / 1000;
3927  db_value_put_encoded_time (value, &tmp_time);
3928  }
3929  break;
3930  case DB_TYPE_TIMESTAMP:
3931  {
3932  DB_TIMESTAMP tmp_timestamp;
3933  DB_DATE tmp_date;
3934  DB_TIME tmp_time;
3935 
3936  tmp_date = datetime->date;
3937  tmp_time = datetime->time / 1000;
3938  db_value_put_encoded_date (value, &tmp_date);
3939  db_value_put_encoded_time (value, &tmp_time);
3940  if (db_timestamp_encode_ses (&tmp_date, &tmp_time, &tmp_timestamp, NULL) != NO_ERROR)
3941  {
3942  status = C_TO_VALUE_CONVERSION_ERROR;
3943  }
3944  else
3945  {
3946  db_make_timestamp (value, tmp_timestamp);
3947  }
3948  break;
3949  }
3950  case DB_TYPE_DATETIME:
3951  {
3952  db_make_datetime (value, datetime);
3953  break;
3954  }
3955  default:
3957  break;
3958  }
3959 
3960  return status;
3961 }
3962 
3963 /*
3964  * DOMAIN ACCESSORS
3965  */
3966 
3967 /*
3968  * db_domain_next() - This can be used to iterate through a list of domain
3969  * descriptors returned by functions such as db_attribute_domain.
3970  * return : The next domain descriptor(or NULL if at end of list).
3971  * domain(in): domain descriptor.
3972  */
3973 DB_DOMAIN *
3974 db_domain_next (const DB_DOMAIN * domain)
3975 {
3976  DB_DOMAIN *next = NULL;
3977 
3978  if (domain != NULL)
3979  {
3980  next = domain->next;
3981  }
3982 
3983  return (next);
3984 }
3985 
3986 /*
3987  * db_domain_type() - See the note below.
3988  * return : type identifier constant.
3989  * domain(in): domain descriptor.
3990  *
3991  * note:
3992  * Returns the basic type identifier for a domain descriptor.
3993  * This will be a numeric value as defined by the DB_TYPE_ enumeration.
3994  * IFF this value is DB_TYPE_OBJECT then the domain will have additional
3995  * information in the "class" field that can be accessed with
3996  * db_domain_class. This will tell you the specific class that was
3997  * defined for this domain. If the class field is NULL, the domain is
3998  * a generic object and can be a reference to any object. IFF the domain
3999  * type is DB_TYPE_SET, DB_TYPE_MULTISET, or DB_TYPE_SEQUENCE, there
4000  * will be additional domain information in the "set" field of the domain
4001  * descriptor that can be accessed with db_domain_set. This will be
4002  * an additional list of domain descriptors that define the domains of the
4003  * elements of the set.
4004  */
4005 DB_TYPE
4006 db_domain_type (const DB_DOMAIN * domain)
4007 {
4008  return TP_DOMAIN_TYPE (domain);
4009 }
4010 
4011 /*
4012  * db_domain_class() - see the note below.
4013  *
4014  * return : a class pointer
4015  * domain(in) : domain descriptor
4016  * note:
4017  * This can be used to get the specific domain class for a domain whose
4018  * basic type is DB_TYPE_OBJECT. This value may be NULL indicating that
4019  * the domain is the general object domain and can reference any type of
4020  * object.
4021  * This should check to see if the domain class was dropped. This won't
4022  * happen in the ususal case because the domain list is filtered by
4023  * db_attribute_domain and related functions which always serve as the
4024  * sources for this list. Filtering again here would slow it down
4025  * even more. If it is detected as deleted and we downgrade to
4026  * "object", this could leave the containing domain list will multiple
4027  * object domains.
4028  */
4029 DB_OBJECT *
4030 db_domain_class (const DB_DOMAIN * domain)
4031 {
4032  DB_OBJECT *class_mop = NULL;
4033 
4034  if ((domain != NULL) && (domain->type == tp_Type_object))
4035  {
4036  class_mop = domain->class_mop;
4037  }
4038 
4039  return (class_mop);
4040 }
4041 
4042 /*
4043  * db_domain_set() - see the note below.
4044  * return : domain descriptor or NULL.
4045  * domain(in): domain descriptor.
4046  *
4047  * note:
4048  * This can be used to get set domain information for a domain
4049  * whose basic type is DB_TYPE_SET, DB_TYPE_MULTISET, or DB_TYPE_SEQUENCE
4050  * This field will always be NULL for any other kind of basic type.
4051  * This field may be NULL even for set types if there was no additional
4052  * domain information specified when the attribute was defined.
4053  * The returned domain list can be examined just like other domain
4054  * descriptors using the db_domain functions. In theory, domains
4055  * could be fully hierarchical by containing nested sets. Currently,
4056  * this is not allowed by the schema manager but it may be allowed
4057  * in the future.
4058  */
4059 DB_DOMAIN *
4060 db_domain_set (const DB_DOMAIN * domain)
4061 {
4062  DB_DOMAIN *setdomain = NULL;
4063 
4064  if ((domain != NULL) && (pr_is_set_type (TP_DOMAIN_TYPE (domain)) || TP_DOMAIN_TYPE (domain) == DB_TYPE_MIDXKEY))
4065  {
4066  setdomain = domain->setdomain;
4067  }
4068 
4069  return (setdomain);
4070 }
4071 
4072 /*
4073  * db_domain_precision() - Get the precision of the given domain.
4074  * return : precision of domain.
4075  * domain(in): domain descriptor.
4076  *
4077  */
4078 int
4080 {
4081  int precision = 0;
4082 
4083  if (domain != NULL)
4084  {
4085  precision = domain->precision;
4086  }
4087 
4088  return (precision);
4089 }
4090 
4091 /*
4092  * db_domain_scale() - Get the scale of the given domain.
4093  * return : scale of domain.
4094  * domain(in): domain descriptor.
4095  *
4096  */
4097 int
4098 db_domain_scale (const DB_DOMAIN * domain)
4099 {
4100  int scale = 0;
4101 
4102  if (domain != NULL)
4103  {
4104  scale = domain->scale;
4105  }
4106 
4107  return (scale);
4108 }
4109 
4110 /*
4111  * db_domain_codeset() - Get the codeset of the given domain.
4112  * return : codeset of domain.
4113  * domain(in): domain descriptor.
4114  */
4115 int
4117 {
4118  int codeset = 0;
4119 
4120  if (domain != NULL)
4121  {
4122  codeset = domain->codeset;
4123  }
4124 
4125  return (codeset);
4126 }
4127 
4128 /*
4129  * db_domain_collation_id() - Get the collation id of the given domain.
4130  * return : codeset of domain.
4131  * domain(in): domain descriptor.
4132  */
4133 int
4135 {
4136  int collation_id = 0;
4137 
4138  if (domain != NULL)
4139  {
4140  collation_id = domain->collation_id;
4141  }
4142 
4143  return (collation_id);
4144 }
4145 
4146 const char *
4148 {
4149  if (domain == NULL || domain->json_validator == NULL)
4150  {
4151  return NULL;
4152  }
4153 
4155 }
4156 
4157 /*
4158  * db_string_put_cs_and_collation() - Set the charset and collation.
4159  * return : error code
4160  * cs(in) : codeset
4161  * collation_id(in): collation identifier
4162  */
4163 int
4164 db_string_put_cs_and_collation (DB_VALUE * value, const int codeset, const int collation_id)
4165 {
4166  int error = NO_ERROR;
4167 
4168  CHECK_1ARG_ERROR (value);
4169 
4170  if (TP_IS_CHAR_TYPE (value->domain.general_info.type))
4171  {
4172  value->data.ch.info.codeset = (char) codeset;
4173  value->domain.char_info.collation_id = collation_id;
4174  }
4175  else
4176  {
4177  error = ER_QPROC_INVALID_DATATYPE;
4179  }
4180 
4181  return error;
4182 }
4183 
4184 /*
4185  * db_enum_put_cs_and_collation() - Set the charset and collation.
4186  * return : error code
4187  * cs(in) : codeset
4188  * collation_id(in): collation identifier
4189  */
4190 int
4191 db_enum_put_cs_and_collation (DB_VALUE * value, const int codeset, const int collation_id)
4192 {
4193  int error = NO_ERROR;
4194 
4195  CHECK_1ARG_ERROR (value);
4196 
4198  {
4199  value->data.enumeration.str_val.info.codeset = (char) codeset;
4200  value->domain.char_info.collation_id = collation_id;
4201  }
4202  else
4203  {
4204  error = ER_QPROC_INVALID_DATATYPE;
4206  }
4207 
4208  return error;
4209 }
4210 
4211 /*
4212  * vc_append_bytes(): append a string to string buffer
4213  *
4214  * returns: on success, ptr to concatenated string. otherwise, NULL.
4215  * old_string(IN/OUT): original string
4216  * new_tail(IN): string to be appended
4217  * new_tail_length(IN): length of the string to be appended
4218  *
4219  */
4220 static VALCNV_BUFFER *
4221 valcnv_append_bytes (VALCNV_BUFFER * buffer_p, const char *new_tail_p, const size_t new_tail_length)
4222 {
4223  size_t old_length;
4224 
4225  if (new_tail_p == NULL)
4226  {
4227  return buffer_p;
4228  }
4229  else if (buffer_p == NULL)
4230  {
4231  buffer_p = (VALCNV_BUFFER *) malloc (sizeof (VALCNV_BUFFER));
4232  if (buffer_p == NULL)
4233  {
4235  return NULL;
4236  }
4237 
4238  buffer_p->length = 0;
4239  buffer_p->bytes = NULL;
4240  }
4241 
4242  old_length = buffer_p->length;
4243  buffer_p->length += new_tail_length;
4244 
4245  buffer_p->bytes = (unsigned char *) realloc (buffer_p->bytes, buffer_p->length);
4246  if (buffer_p->bytes == NULL)
4247  {
4249  return NULL;
4250  }
4251 
4252  memcpy (&buffer_p->bytes[old_length], new_tail_p, new_tail_length);
4253  return buffer_p;
4254 }
4255 
4256 /*
4257  * vc_append_string(): append a string to string buffer
4258  *
4259  * returns: on success, ptr to concatenated string. otherwise, NULL.
4260  * old_string(IN/OUT): original string
4261  * new_tail(IN): string to be appended
4262  *
4263  */
4264 static VALCNV_BUFFER *
4265 valcnv_append_string (VALCNV_BUFFER * buffer_p, const char *new_tail_p)
4266 {
4267  return valcnv_append_bytes (buffer_p, new_tail_p, strlen (new_tail_p));
4268 }
4269 
4270 /*
4271  * vc_float_to_string(): append float value to string buffer
4272  *
4273  * returns: on success, ptr to converted string. otherwise, NULL.
4274  * buf(IN/OUT): buffer
4275  * value(IN): floating point value which is to be converted
4276  *
4277  */
4278 static VALCNV_BUFFER *
4279 valcnv_convert_float_to_string (VALCNV_BUFFER * buffer_p, const float value)
4280 {
4281  char tbuf[24];
4282 
4283  sprintf (tbuf, "%.17g", value);
4284 
4285 #if defined(HPUX)
4286  /* workaround for HP's broken printf */
4287  if (strstr (tbuf, "++") || strstr (tbuf, "--"))
4288 #else /* HPUX */
4289  if (strstr (tbuf, "Inf"))
4290 #endif /* HPUX */
4291  {
4292  sprintf (tbuf, "%.17g", (value > 0 ? FLT_MAX : -FLT_MAX));
4293  }
4294 
4295  return valcnv_append_string (buffer_p, tbuf);
4296 }
4297 
4298 /*
4299  * vc_double_to_string(): append double value to string buffer
4300  *
4301  * returns: on success, ptr to converted string. otherwise, NULL.
4302  * buf : buffer
4303  * value(IN): double value which is to be converted
4304  *
4305  */
4306 static VALCNV_BUFFER *
4307 valcnv_convert_double_to_string (VALCNV_BUFFER * buffer_p, const double value)
4308 {
4309  char tbuf[24];
4310 
4311  sprintf (tbuf, "%.17g", value);
4312 
4313 #if defined(HPUX)
4314  /* workaround for HP's broken printf */
4315  if (strstr (tbuf, "++") || strstr (tbuf, "--"))
4316 #else /* HPUX */
4317  if (strstr (tbuf, "Inf"))
4318 #endif /* HPUX */
4319  {
4320  sprintf (tbuf, "%.17g", (value > 0 ? DBL_MAX : -DBL_MAX));
4321  }
4322 
4323  return valcnv_append_string (buffer_p, tbuf);
4324 }
4325 
4326 /*
4327  * vc_bit_to_string(): append bit value to string buffer
4328  *
4329  * returns: on success, ptr to converted string. otherwise, NULL.
4330  * buf(IN/OUT): buffer
4331  * value(IN): BIT value which is to be converted
4332  *
4333  */
4334 static VALCNV_BUFFER *
4336 {
4337  const unsigned char *bit_string_p;
4338  int nibble_len, nibbles, count;
4339  char tbuf[10];
4340 
4341  bit_string_p = REINTERPRET_CAST (const unsigned char *, db_get_string (value_p));
4342  nibble_len = (db_get_string_length (value_p) + 3) / 4;
4343 
4344  for (nibbles = 0, count = 0; nibbles < nibble_len - 1; count++, nibbles += 2)
4345  {
4346  sprintf (tbuf, "%02x", bit_string_p[count]);
4347  tbuf[2] = '\0';
4348  buffer_p = valcnv_append_string (buffer_p, tbuf);
4349  if (buffer_p == NULL)
4350  {
4351  return NULL;
4352  }
4353  }
4354 
4355  if (nibbles < nibble_len)
4356  {
4357  sprintf (tbuf, "%1x", bit_string_p[count]);
4358  tbuf[1] = '\0';
4359  buffer_p = valcnv_append_string (buffer_p, tbuf);
4360  if (buffer_p == NULL)
4361  {
4362  return NULL;
4363  }
4364  }
4365 
4366  return buffer_p;
4367 }
4368 
4369 /*
4370  * vc_set_to_string(): append set value to string buffer
4371  *
4372  * returns: on success, ptr to converted string. otherwise, NULL.
4373  * buf(IN/OUT): buffer
4374  * set(IN): SET value which is to be converted
4375  *
4376  */
4377 static VALCNV_BUFFER *
4379 {
4380  DB_VALUE value;
4381  int err, size, max_n, i;
4382 
4383  if (set_p == NULL)
4384  {
4385  return buffer_p;
4386  }
4387 
4388  buffer_p = valcnv_append_string (buffer_p, "{");
4389  if (buffer_p == NULL)
4390  {
4391  return NULL;
4392  }
4393 
4394  size = set_size (set_p);
4395  if (valcnv_Max_set_elements == 0)
4396  {
4397  max_n = size;
4398  }
4399  else
4400  {
4401  max_n = MIN (size, valcnv_Max_set_elements);
4402  }
4403 
4404  for (i = 0; i < max_n; i++)
4405  {
4406  err = set_get_element (set_p, i, &value);
4407  if (err < 0)
4408  {
4409  return NULL;
4410  }
4411 
4412  buffer_p = valcnv_convert_db_value_to_string (buffer_p, &value);
4413  pr_clear_value (&value);
4414  if (i < size - 1)
4415  {
4416  buffer_p = valcnv_append_string (buffer_p, ", ");
4417  if (buffer_p == NULL)
4418  {
4419  return NULL;
4420  }
4421  }
4422  }
4423 
4424  if (i < size)
4425  {
4426  buffer_p = valcnv_append_string (buffer_p, "...");
4427  if (buffer_p == NULL)
4428  {
4429  return NULL;
4430  }
4431  }
4432 
4433  buffer_p = valcnv_append_string (buffer_p, "}");
4434  if (buffer_p == NULL)
4435  {
4436  return NULL;
4437  }
4438 
4439  return buffer_p;
4440 }
4441 
4442 /*
4443  * vc_money_to_string(): append monetary value to string buffer
4444  *
4445  * returns: on success, ptr to converted string. otherwise, NULL.
4446  * value(IN): monetary value which is to be converted
4447  *
4448  */
4449 static VALCNV_BUFFER *
4451 {
4452  char cbuf[LDBL_MAX_10_EXP + 20]; /* 20 == floating fudge factor */
4453 
4454  sprintf (cbuf, "%.2f", value);
4455 
4456 #if defined(HPUX)
4457  /* workaround for HP's broken printf */
4458  if (strstr (cbuf, "++") || strstr (cbuf, "--"))
4459 #else /* HPUX */
4460  if (strstr (cbuf, "Inf"))
4461 #endif /* HPUX */
4462  {
4463  sprintf (cbuf, "%.2f", (value > 0 ? DBL_MAX : -DBL_MAX));
4464  }
4465 
4466  return valcnv_append_string (NULL, cbuf);
4467 }
4468 
4469 /*
4470  * vc_data_to_string(): append a value to string buffer
4471  *
4472  * returns: on success, ptr to converted string. otherwise, NULL.
4473  * buf(IN/OUT): buffer
4474  * value(IN): a value which is to be converted
4475  *
4476  */
4477 static VALCNV_BUFFER *
4479 {
4480  OID *oid_p;
4481  DB_SET *set_p;
4482  DB_ELO *elo_p;
4483  const char *src_p, *end_p, *p;
4484  ptrdiff_t len;
4485 
4486  DB_MONETARY *money_p;
4487  VALCNV_BUFFER *money_string_p;
4488  const char *currency_symbol_p;
4489  double amount;
4490  DB_VALUE dbval;
4491 
4492  char line[1025];
4493 
4494  int cnt;
4495 
4496  if (DB_IS_NULL (value_p))
4497  {
4498  buffer_p = valcnv_append_string (buffer_p, "NULL");
4499  }
4500  else
4501  {
4502  switch (DB_VALUE_TYPE (value_p))
4503  {
4504  case DB_TYPE_INTEGER:
4505  sprintf (line, "%d", db_get_int (value_p));
4506  buffer_p = valcnv_append_string (buffer_p, line);
4507  break;
4508 
4509  case DB_TYPE_BIGINT:
4510  sprintf (line, "%lld", (long long) db_get_bigint (value_p));
4511  buffer_p = valcnv_append_string (buffer_p, line);
4512  break;
4513 
4514  case DB_TYPE_SHORT:
4515  sprintf (line, "%d", (int) db_get_short (value_p));
4516  buffer_p = valcnv_append_string (buffer_p, line);
4517  break;
4518 
4519  case DB_TYPE_FLOAT:
4520  buffer_p = valcnv_convert_float_to_string (buffer_p, db_get_float (value_p));
4521  break;
4522 
4523  case DB_TYPE_DOUBLE:
4524  buffer_p = valcnv_convert_double_to_string (buffer_p, db_get_double (value_p));
4525  break;
4526 
4527  case DB_TYPE_NUMERIC:
4528  buffer_p = valcnv_append_string (buffer_p, numeric_db_value_print (value_p, line));
4529  break;
4530 
4531  case DB_TYPE_BIT:
4532  case DB_TYPE_VARBIT:
4533  buffer_p = valcnv_convert_bit_to_string (buffer_p, value_p);
4534  break;
4535 
4536  case DB_TYPE_CHAR:
4537  case DB_TYPE_NCHAR:
4538  case DB_TYPE_VARCHAR:
4539  case DB_TYPE_VARNCHAR:
4540  src_p = db_get_string (value_p);
4541 
4542  if (src_p != NULL && db_get_string_size (value_p) == 0)
4543  {
4544  buffer_p = valcnv_append_string (buffer_p, "");
4545  return buffer_p;
4546  }
4547 
4548  end_p = src_p + db_get_string_size (value_p);
4549  while (src_p < end_p)
4550  {
4551  for (p = src_p; p < end_p && *p != '\''; p++)
4552  {
4553  ;
4554  }
4555 
4556  if (p < end_p)
4557  {
4558  len = p - src_p + 1;
4559  buffer_p = valcnv_append_bytes (buffer_p, src_p, len);
4560  if (buffer_p == NULL)
4561  {
4562  return NULL;
4563  }
4564 
4565  buffer_p = valcnv_append_string (buffer_p, "'");
4566  if (buffer_p == NULL)
4567  {
4568  return NULL;
4569  }
4570  }
4571  else
4572  {
4573  buffer_p = valcnv_append_bytes (buffer_p, src_p, end_p - src_p);
4574  if (buffer_p == NULL)
4575  {
4576  return NULL;
4577  }
4578  }
4579 
4580  src_p = p + 1;
4581  }
4582  break;
4583 
4584  case DB_TYPE_OID:
4585  oid_p = (OID *) db_get_oid (value_p);
4586 
4587  sprintf (line, "%d", (int) oid_p->volid);
4588  buffer_p = valcnv_append_string (buffer_p, line);
4589  if (buffer_p == NULL)
4590  {
4591  return NULL;
4592  }
4593 
4594  buffer_p = valcnv_append_string (buffer_p, "|");
4595  if (buffer_p == NULL)
4596  {
4597  return NULL;
4598  }
4599 
4600  sprintf (line, "%d", (int) oid_p->pageid);
4601  buffer_p = valcnv_append_string (buffer_p, line);
4602  if (buffer_p == NULL)
4603  {
4604  return NULL;
4605  }
4606 
4607  buffer_p = valcnv_append_string (buffer_p, "|");
4608  if (buffer_p == NULL)
4609  {
4610  return NULL;
4611  }
4612 
4613  sprintf (line, "%d", (int) oid_p->slotid);
4614  buffer_p = valcnv_append_string (buffer_p, line);
4615  if (buffer_p == NULL)
4616  {
4617  return NULL;
4618  }
4619 
4620  break;
4621 
4622  case DB_TYPE_SET:
4623  case DB_TYPE_MULTISET:
4624  case DB_TYPE_SEQUENCE:
4625  set_p = db_get_set (value_p);
4626  if (set_p == NULL)
4627  {
4628  buffer_p = valcnv_append_string (buffer_p, "NULL");
4629  }
4630  else
4631  {
4632  return valcnv_convert_set_to_string (buffer_p, set_p);
4633  }
4634 
4635  break;
4636 
4637  case DB_TYPE_BLOB:
4638  case DB_TYPE_CLOB:
4639  elo_p = db_get_elo (value_p);
4640  if (elo_p == NULL)
4641  {
4642  buffer_p = valcnv_append_string (buffer_p, "NULL");
4643  }
4644  else
4645  {
4646  if (elo_p->type == ELO_FBO)
4647  {
4648  assert (elo_p->locator != NULL);
4649  buffer_p = valcnv_append_string (buffer_p, elo_p->locator);
4650  }
4651  else /* ELO_LO */
4652  {
4653  /* should not happen for now */
4654  assert (0);
4655  }
4656  }
4657  break;
4658 
4659  case DB_TYPE_TIME:
4660  cnt = db_time_to_string (line, VALCNV_TOO_BIG_TO_MATTER, db_get_time (value_p));
4661  if (cnt == 0)
4662  {
4663  return NULL;
4664  }
4665  buffer_p = valcnv_append_string (buffer_p, line);
4666  break;
4667 
4668  case DB_TYPE_TIMESTAMP:
4670  if (cnt == 0)
4671  {
4672  return NULL;
4673  }
4674  buffer_p = valcnv_append_string (buffer_p, line);
4675  break;
4676 
4677  case DB_TYPE_TIMESTAMPTZ:
4678  {
4679  DB_TIMESTAMPTZ *ts_tz = db_get_timestamptz (value_p);
4680 
4681  cnt = db_timestamptz_to_string (line, VALCNV_TOO_BIG_TO_MATTER, &(ts_tz->timestamp), &(ts_tz->tz_id));
4682  if (cnt == 0)
4683  {
4684  return NULL;
4685  }
4686  buffer_p = valcnv_append_string (buffer_p, line);
4687  }
4688  break;
4689 
4690  case DB_TYPE_TIMESTAMPLTZ:
4691  {
4692  TZ_ID tz_id;
4693  DB_TIMESTAMP *utime;
4694 
4695  utime = db_get_timestamp (value_p);
4696  if (tz_create_session_tzid_for_timestamp (utime, &tz_id) != NO_ERROR)
4697  {
4698  return NULL;
4699  }
4700  cnt = db_timestamptz_to_string (line, VALCNV_TOO_BIG_TO_MATTER, utime, &tz_id);
4701  if (cnt == 0)
4702  {
4703  return NULL;
4704  }
4705  buffer_p = valcnv_append_string (buffer_p, line);
4706  }
4707  break;
4708 
4709  case DB_TYPE_DATETIME:
4711  if (cnt == 0)
4712  {
4713  return NULL;
4714  }
4715 
4716  buffer_p = valcnv_append_string (buffer_p, line);
4717  break;
4718 
4719  case DB_TYPE_DATETIMETZ:
4720  {
4721  DB_DATETIMETZ *dt_tz = db_get_datetimetz (value_p);
4722 
4723  cnt = db_datetimetz_to_string (line, VALCNV_TOO_BIG_TO_MATTER, &(dt_tz->datetime), &(dt_tz->tz_id));
4724  if (cnt == 0)
4725  {
4726  return NULL;
4727  }
4728 
4729  buffer_p = valcnv_append_string (buffer_p, line);
4730  }
4731  break;
4732 
4733  case DB_TYPE_DATETIMELTZ:
4734  {
4735  TZ_ID tz_id;
4736  DB_DATETIME *dt;
4737 
4738  dt = db_get_datetime (value_p);
4739  if (tz_create_session_tzid_for_datetime (dt, true, &tz_id) != NO_ERROR)
4740  {
4741  return NULL;
4742  }
4743 
4744  cnt = db_datetimetz_to_string (line, VALCNV_TOO_BIG_TO_MATTER, dt, &tz_id);
4745  if (cnt == 0)
4746  {
4747  return NULL;
4748  }
4749 
4750  buffer_p = valcnv_append_string (buffer_p, line);
4751  }
4752  break;
4753 
4754  case DB_TYPE_DATE:
4755  cnt = db_date_to_string (line, VALCNV_TOO_BIG_TO_MATTER, db_get_date (value_p));
4756  if (cnt == 0)
4757  {
4758  return NULL;
4759  }
4760  buffer_p = valcnv_append_string (buffer_p, line);
4761  break;
4762 
4763  case DB_TYPE_MONETARY:
4764  money_p = db_get_monetary (value_p);
4765  OR_MOVE_DOUBLE (&money_p->amount, &amount);
4766  money_string_p = valcnv_convert_money_to_string (amount);
4767  if (money_string_p == NULL)
4768  {
4769  return NULL;
4770  }
4771 
4772  currency_symbol_p = lang_currency_symbol (money_p->type);
4773  strcpy (line, currency_symbol_p);
4774  strncpy (line + strlen (currency_symbol_p), (char *) money_string_p->bytes, money_string_p->length);
4775  line[strlen (currency_symbol_p) + money_string_p->length] = '\0';
4776 
4777  free_and_init (money_string_p->bytes);
4778  free_and_init (money_string_p);
4779  buffer_p = valcnv_append_string (buffer_p, line);
4780  break;
4781 
4782  case DB_TYPE_ENUMERATION:
4783  if (db_get_enum_short (value_p) == 0 && db_get_enum_string (value_p) == NULL)
4784  {
4785  /* ENUM special error value */
4788  buffer_p = valcnv_convert_data_to_string (buffer_p, &dbval);
4789  }
4790  else if (db_get_enum_string_size (value_p) > 0)
4791  {
4792  db_make_string (&dbval, db_get_enum_string (value_p));
4793 
4794  buffer_p = valcnv_convert_data_to_string (buffer_p, &dbval);
4795  }
4796  break;
4797 
4798  default:
4799  break;
4800  }
4801  }
4802 
4803  return buffer_p;
4804 }
4805 
4806 /*
4807  * vc_db_value_to_string(): append a value to string buffer with a type prefix
4808  *
4809  * returns: on success, ptr to converted string. otherwise, NULL.
4810  * buf(IN/OUT): buffer
4811  * value(IN): a value which is to be converted
4812  *
4813  */
4814 static VALCNV_BUFFER *
4816 {
4817  if (DB_IS_NULL (value_p))
4818  {
4819  buffer_p = valcnv_append_string (buffer_p, "NULL");
4820  }
4821  else
4822  {
4823  switch (DB_VALUE_TYPE (value_p))
4824  {
4825  case DB_TYPE_BIT:
4826  case DB_TYPE_VARBIT:
4827  buffer_p = valcnv_append_string (buffer_p, "X'");
4828  if (buffer_p == NULL)
4829  {
4830  return NULL;
4831  }
4832 
4833  buffer_p = valcnv_convert_data_to_string (buffer_p, value_p);
4834  if (buffer_p == NULL)
4835  {
4836  return NULL;
4837  }
4838 
4839  buffer_p = valcnv_append_string (buffer_p, "'");
4840  break;
4841 
4842  case DB_TYPE_BLOB:
4843  case DB_TYPE_CLOB:
4844  if (DB_VALUE_TYPE (value_p) == DB_TYPE_BLOB)
4845  {
4846  buffer_p = valcnv_append_string (buffer_p, "BLOB'");
4847  }
4848  else
4849  {
4850  buffer_p = valcnv_append_string (buffer_p, "CLOB'");
4851  }
4852 
4853  if (buffer_p == NULL)
4854  {
4855  return NULL;
4856  }
4857 
4858  buffer_p = valcnv_convert_data_to_string (buffer_p, value_p);
4859  if (buffer_p == NULL)
4860  {
4861  return NULL;
4862  }
4863 
4864  buffer_p = valcnv_append_string (buffer_p, "'");
4865  break;
4866 
4867  case DB_TYPE_ENUMERATION:
4868  buffer_p = valcnv_append_string (buffer_p, "'");
4869  if (buffer_p == NULL)
4870  {
4871  return NULL;
4872  }
4873 
4874  buffer_p = valcnv_convert_data_to_string (buffer_p, value_p);
4875  if (buffer_p == NULL)
4876  {
4877  return NULL;
4878  }
4879 
4880  buffer_p = valcnv_append_string (buffer_p, "'");
4881  break;
4882 
4883  default:
4884  buffer_p = valcnv_convert_data_to_string (buffer_p, value_p);
4885  break;
4886  }
4887  }
4888 
4889  return buffer_p;
4890 }
4891 
4892 /*
4893  * valcnv_convert_value_to_string(): convert a value to a string type value
4894  *
4895  * returns: on success, NO_ERROR. otherwise, ER_FAILED.
4896  * value(IN/OUT): a value which is to be converted to string
4897  * Note that the value is cleaned up during conversion.
4898  *
4899  */
4900 int
4902 {
4903  VALCNV_BUFFER buffer = { 0, NULL };
4904  VALCNV_BUFFER *buf_p;
4905  DB_VALUE src_value;
4906 
4907  if (!DB_IS_NULL (value_p))
4908  {
4909  buf_p = &buffer;
4910  buf_p = valcnv_convert_db_value_to_string (buf_p, value_p);
4911  if (buf_p == NULL)
4912  {
4913  return ER_FAILED;
4914  }
4915 
4916  db_make_varchar (&src_value, DB_MAX_STRING_LENGTH, REINTERPRET_CAST (char *, buf_p->bytes),
4918 
4919  pr_clear_value (value_p);
4920  tp_String.setval (value_p, &src_value, true);
4921 
4922  pr_clear_value (&src_value);
4923  free_and_init (buf_p->bytes);
4924  }
4925 
4926  return NO_ERROR;
4927 }
4928 
4929 int
4931 {
4932  return db_Connect_status;
4933 }
4934 
4935 void
4937 {
4938  db_Connect_status = status;
4939 }
4940 
4941 /*
4942  * db_default_expression_string() -
4943  * return : string opcode of default expression
4944  * default_expr_type(in):
4945  */
4946 const char *
4948 {
4949  switch (default_expr_type)
4950  {
4951  case DB_DEFAULT_NONE:
4952  return NULL;
4953  case DB_DEFAULT_SYSDATE:
4954  return "SYS_DATE";
4956  return "SYS_DATETIME";
4958  return "SYS_TIMESTAMP";
4960  return "UNIX_TIMESTAMP()";
4961  case DB_DEFAULT_USER:
4962  return "USER()";
4963  case DB_DEFAULT_CURR_USER:
4964  return "CURRENT_USER";
4966  return "CURRENT_DATETIME";
4968  return "CURRENT_TIMESTAMP";
4970  return "CURRENT_TIME";
4972  return "CURRENT_DATE";
4973  case DB_DEFAULT_SYSTIME:
4974  return "SYS_TIME";
4975  default:
4976  return NULL;
4977  }
4978 }
4979 
4980 int
4982 {
4983  CHECK_2ARGS_ERROR (src, dest);
4984  JSON_DOC *doc = db_get_json_document (src);
4985 
4986  assert (doc != NULL);
4987 
4988  switch (db_json_get_type (doc))
4989  {
4990  case DB_JSON_STRING:
4991  {
4992  const char *str = db_json_get_string_from_document (doc);
4993  int error_code = db_make_string (dest, str);
4994  if (error_code != NO_ERROR)
4995  {
4996  ASSERT_ERROR ();
4997  return error_code;
4998  }
4999  break;
5000  }
5001  case DB_JSON_INT:
5002  {
5003  int val = db_json_get_int_from_document (doc);
5004  db_make_int (dest, val);
5005  break;
5006  }
5007  case DB_JSON_BIGINT:
5008  {
5009  int64_t val = db_json_get_bigint_from_document (doc);
5010  db_make_bigint (dest, val);
5011  break;
5012  }
5013  case DB_JSON_DOUBLE:
5014  {
5015  double val = db_json_get_double_from_document (doc);
5016  db_make_double (dest, val);
5017  break;
5018  }
5019  case DB_JSON_BOOL:
5020  {
5021  char *str = db_json_get_bool_as_str_from_document (doc);
5022  int error_code = db_make_string (dest, str);
5023  if (error_code != NO_ERROR)
5024  {
5025  ASSERT_ERROR ();
5026  return error_code;
5027  }
5028  dest->need_clear = true;
5029  break;
5030  }
5031  case DB_JSON_NULL:
5032  db_make_null (dest);
5033  break;
5034  default:
5035  assert (false);
5036  return ER_FAILED;
5037  }
5038 
5039  return NO_ERROR;
5040 }
5041 
5042 bool
5044 {
5045  switch (type)
5046  {
5047  case DB_TYPE_CHAR:
5048  case DB_TYPE_VARNCHAR:
5049  case DB_TYPE_NCHAR:
5050  case DB_TYPE_VARCHAR:
5051  case DB_TYPE_NULL:
5052  case DB_TYPE_SHORT:
5053  case DB_TYPE_INTEGER:
5054  case DB_TYPE_DOUBLE:
5055  case DB_TYPE_JSON:
5056  case DB_TYPE_NUMERIC:
5057  case DB_TYPE_BIGINT:
5058  case DB_TYPE_ENUMERATION:
5059  return true;
5060  default:
5061  return false;
5062  }
5063 }
5064 
5065 bool
5067 {
5068  switch (type)
5069  {
5070  case DB_TYPE_CHAR:
5071  case DB_TYPE_VARNCHAR:
5072  case DB_TYPE_NCHAR:
5073  case DB_TYPE_VARCHAR:
5074  case DB_TYPE_JSON:
5075  return true;
5076  default:
5077  return false;
5078  }
5079 }
5080 
5081 char *
5083 {
5085 }
5086 
5087 /*
5088  * db_value_is_corrupted(): Check whether the db_value is corrupted
5089  *
5090  * returns: true if corrupted, false otherwise.
5091  * value(in): the value to check
5092  */
5093 bool
5095 {
5096  if (value == NULL || DB_IS_NULL (value))
5097  {
5098  return false;
5099  }
5100 
5101  switch (value->domain.general_info.type)
5102  {
5103  case DB_TYPE_NUMERIC:
5105  {
5106  return true;
5107  }
5108  break;
5109 
5110  case DB_TYPE_BIT:
5112  {
5113  return true;
5114  }
5115  break;
5116 
5117  case DB_TYPE_VARBIT:
5119  {
5120  return true;
5121  }
5122  break;
5123 
5124  case DB_TYPE_CHAR:
5126  {
5127  return true;
5128  }
5129  break;
5130 
5131  case DB_TYPE_NCHAR:
5133  {
5134  return true;
5135  }
5136  break;
5137 
5138  case DB_TYPE_VARCHAR:
5140  {
5141  return true;
5142  }
5143  break;
5144 
5145  case DB_TYPE_VARNCHAR:
5147  {
5148  return true;
5149  }
5150  break;
5151 
5152  default:
5153  break;
5154  }
5155 
5156  return false;
5157 }
DB_TIMESTAMP DB_C_TIMESTAMP
Definition: dbtype_def.h:1211
SESSION_ID db_Session_id
Definition: db_macro.c:79
unsigned int TZ_ID
Definition: dbtype_def.h:756
DB_C_FLOAT db_get_float(const DB_VALUE *value)
struct db_domain_info::char_info char_info
DB_TIME time
Definition: dbtype_def.h:1056
int db_value_put_monetary_currency(DB_VALUE *value, DB_CURRENCY const type)
Definition: db_macro.c:1409
struct db_datetime DB_DATETIME
Definition: dbtype_def.h:773
int db_set_compare(const DB_VALUE *value1, const DB_VALUE *value2)
Definition: db_macro.c:1833
bool db_is_json_doc_type(DB_TYPE type)
Definition: db_macro.c:5066
unsigned char * qstr_pad_string(unsigned char *s, int length, INTL_CODESET codeset)
int db_make_datetime(DB_VALUE *value, const DB_DATETIME *datetime)
long DB_C_LONG
Definition: dbtype_def.h:1151
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
short sh
Definition: dbtype_def.h:1050
int db_value_put_null(DB_VALUE *value)
Definition: db_macro.c:122
const char * lang_currency_symbol(DB_CURRENCY curr)
DB_NUMERIC num
Definition: dbtype_def.h:1069
#define DB_ROW_COUNT_NOT_SET
Definition: dbtype_def.h:486
DB_COLLECTION * db_get_set(const DB_VALUE *value)
#define DB_MAX_BIT_PRECISION
Definition: dbtype_def.h:549
char buf[DB_SMALL_CHAR_BUF_SIZE]
Definition: dbtype_def.h:991
#define LANG_SYS_COLLATION
unsigned char codeset
Definition: dbtype_def.h:980
int db_timestamptz_to_string(char *buf, int bufsize, DB_TIMESTAMP *utime, const TZ_ID *tz_id)
Definition: db_date.c:4090
int db_value_domain_min(DB_VALUE *value, const DB_TYPE type, const int precision, const int scale, const int codeset, const int collation_id, const DB_ENUMERATION *enumeration)
Definition: db_macro.c:413
DB_VALUE_COMPARE_RESULT tp_value_compare(const DB_VALUE *value1, const DB_VALUE *value2, int allow_coercion, int total_order)
bool db_value_type_is_collection(const DB_VALUE *value)
Definition: db_macro.c:1144
double db_json_get_double_from_document(const JSON_DOC *doc)
Definition: db_json.cpp:2537
DB_VALUE * vals
Definition: dbtype_def.h:1100
#define ASSERT_ERROR()
int db_domain_scale(const DB_DOMAIN *domain)
Definition: db_macro.c:4098
int db_string_put_cs_and_collation(DB_VALUE *value, const int codeset, const int collation_id)
Definition: db_macro.c:4164
int intl_pad_size(INTL_CODESET codeset)
const char * schema_raw
Definition: dbtype_def.h:1039
#define CHECK_2ARGS_ERROR(obj1, obj2)
Definition: db.h:195
unsigned char codeset
Definition: object_domain.h:91
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)
#define TP_IS_SET_TYPE(typenum)
DB_CONST_C_NCHAR db_get_nchar(const DB_VALUE *value, int *length)
JSON_DOC * db_get_json_document(const DB_VALUE *value)
#define DB_MAX_STRING_LENGTH
Definition: dbtype_def.h:516
int db_domain_precision(const DB_DOMAIN *domain)
Definition: db_macro.c:4079
int db_bit_string_coerce(const DB_VALUE *src_string, DB_VALUE *dest_string, DB_DATA_STATUS *data_status)
int db_date_to_string(char *buf, int bufsize, DB_DATE *date)
Definition: db_date.c:3953
int db_make_bigint(DB_VALUE *value, const DB_BIGINT num)
int db_get_int(const DB_VALUE *value)
DB_TIMESTAMP timestamp
Definition: dbtype_def.h:766
DB_TYPE
Definition: dbtype_def.h:670
int tp_value_equal(const DB_VALUE *value1, const DB_VALUE *value2, int do_coercion)
unsigned short count
Definition: dbtype_def.h:1033
int db_datetime_string(const DB_DATETIME *the_datetime, const char *datetime_format, char *string, int max_size)
Definition: cnv.c:8425
DB_C_DOUBLE db_get_double(const DB_VALUE *value)
#define ER_FAILED
Definition: error_code.h:47
static VALCNV_BUFFER * valcnv_append_string(VALCNV_BUFFER *old_string, const char *new_tail)
Definition: db_macro.c:4265
DB_IDENTIFIER oid
Definition: dbtype_def.h:1068
int db_make_varchar(DB_VALUE *value, const int max_char_length, DB_CONST_C_CHAR str, const int char_str_byte_size, const int codeset, const int collation_id)
int db_get_string_collation(const DB_VALUE *value)
DB_ENUM_ELEMENT enumeration
Definition: dbtype_def.h:1072
struct tp_domain * setdomain
Definition: object_domain.h:82
char * db_json_get_json_body_from_document(const JSON_DOC &doc)
Definition: db_json.cpp:1370
DB_ELO_TYPE type
Definition: dbtype_def.h:950
int db_timestamp_encode_ses(const DB_DATE *date, const DB_TIME *timeval, DB_TIMESTAMP *utime, TZ_ID *dest_tz_id)
Definition: db_date.c:597
DB_TYPE db_domain_type(const DB_DOMAIN *domain)
Definition: db_macro.c:4006
static int coerce_numeric_to_dbvalue(DB_VALUE *value, char *buf, const DB_TYPE_C c_type)
Definition: db_macro.c:3150
int db_value_clone(DB_VALUE *src, DB_VALUE *dest)
Definition: db_macro.c:1564
DB_DATETIME datetime
Definition: dbtype_def.h:1060
void db_value_domain_init_default(DB_VALUE *value, const DB_TYPE type)
Definition: db_macro.c:394
int db_make_numeric(DB_VALUE *value, const DB_C_NUMERIC num, const int precision, const int scale)
const TZ_ID * tz_get_utc_tz_id(void)
Definition: tz_support.c:816
DB_DOMAIN * db_domain_next(const DB_DOMAIN *domain)
Definition: db_macro.c:3974
int db_get_enum_string_size(const DB_VALUE *value)
char * db_get_json_raw_body(const DB_VALUE *value)
Definition: db_macro.c:5082
#define DB_MAX_NCHAR_PRECISION
Definition: dbtype_def.h:541
int db_make_object(DB_VALUE *value, DB_C_OBJECT *obj)
DB_C_NUMERIC db_get_numeric(const DB_VALUE *value)
#define DB_DATE_MIN
Definition: dbtype_def.h:649
int db_value_compare(const DB_VALUE *value1, const DB_VALUE *value2)
Definition: db_macro.c:1855
JSON_DOC * db_json_get_copy_of_doc(const JSON_DOC *doc)
Definition: db_json.cpp:1627
#define DATETIME_BUF_SIZE
Definition: string_opfunc.h:92
int db_domain_collation_id(const DB_DOMAIN *domain)
Definition: db_macro.c:4134
double DB_C_DOUBLE
Definition: dbtype_def.h:1153
int db_make_date(DB_VALUE *value, const int month, const int day, const int year)
DB_DATETIMETZ * db_get_datetimetz(const DB_VALUE *value)
DB_CONST_C_CHAR db_get_char(const DB_VALUE *value, int *length)
int db_Connect_status
Definition: db_macro.c:88
#define DATE_BUF_SIZE
Definition: string_opfunc.h:90
bool db_is_json_value_type(DB_TYPE type)
Definition: db_macro.c:5043
int db_make_sequence(DB_VALUE *value, DB_C_SET *set)
#define CAST_STRLEN
Definition: porting.h:470
const char * db_default_expression_string(DB_DEFAULT_EXPR_TYPE default_expr_type)
Definition: db_macro.c:4947
static int coerce_date_to_dbvalue(DB_VALUE *value, char *buf)
Definition: db_macro.c:3594
#define CHECK_1ARG_FALSE(obj)
Definition: db.h:180
static int transfer_string(char *dst, int *xflen, int *outlen, const int dstlen, const char *src, const int srclen, const DB_TYPE_C type, const INTL_CODESET codeset)
Definition: db_macro.c:1896
int numeric_db_value_coerce_to_num(DB_VALUE *src, DB_VALUE *dest, DB_DATA_STATUS *data_status)
#define ER_UCI_NULL_IND_NEEDED
Definition: error_code.h:543
double db_value_get_monetary_amount_as_double(const DB_VALUE *value)
Definition: db_macro.c:1505
DB_SET * db_set_create_multi(MOP classop, const char *name)
Definition: db_set.c:192
int set_size(DB_COLLECTION *set)
Definition: set_object.c:3036
int db_value_equal(const DB_VALUE *value1, const DB_VALUE *value2)
Definition: db_macro.c:1803
#define DB_VALUE_PRECISION(value)
Definition: dbtype.h:73
enum tp_domain_status TP_DOMAIN_STATUS
int db_value_domain_zero(DB_VALUE *value, const DB_TYPE type, const int precision, const int scale)
Definition: db_macro.c:903
PR_TYPE tp_Char
unsigned char style
Definition: dbtype_def.h:979
PR_TYPE * tp_Type_object
#define DB_DEFAULT_NUMERIC_SCALE
Definition: dbtype_def.h:567
int numeric_coerce_num_to_num(DB_C_NUMERIC src_num, int src_prec, int src_scale, int dest_prec, int dest_scale, DB_C_NUMERIC dest_num)
DB_DOMAIN_INFO domain
Definition: dbtype_def.h:1082
#define DB_VALUE_SCALE(value)
Definition: dbtype.h:74
DB_ELO * db_get_elo(const DB_VALUE *value)
int db_datetimetz_to_string(char *buf, int bufsize, DB_DATETIME *dt, const TZ_ID *tz_id)
Definition: db_date.c:4302
short DB_C_SHORT
Definition: dbtype_def.h:1150
void qstr_bit_to_hex_coerce(char *buffer, int buffer_size, const char *src, int src_length, int pad_flag, int *copy_size, int *truncation)
#define NULL_PAGEID
int db_init_db_json_pointers(DB_JSON *val)
Definition: db_macro.c:2042
#define REINTERPRET_CAST(dest_type, expr)
Definition: porting.h:1080
int db_enum_put_cs_and_collation(DB_VALUE *value, const int codeset, const int collation_id)
Definition: db_macro.c:4191
DB_TIMESTAMPTZ * db_get_timestamptz(const DB_VALUE *value)
int db_date_encode(DB_DATE *date, int month, int day, int year)
Definition: db_date.c:275
int db_make_short(DB_VALUE *value, const DB_C_SHORT num)
#define DB_TIME_MAX
Definition: dbtype_def.h:653
int db_timestamp_to_string(char *buf, int bufsize, DB_TIMESTAMP *utime)
Definition: db_date.c:4054
DB_ELO elo
Definition: dbtype_def.h:1066
int pr_free_ext_value(DB_VALUE *value)
int db_make_string(DB_VALUE *value, DB_CONST_C_CHAR str)
DB_MONETARY * db_get_monetary(const DB_VALUE *value)
#define TIME_BUF_SIZE
Definition: broker_tester.c:57
DB_BIGINT bigint
Definition: dbtype_def.h:1051
bool pr_is_set_type(DB_TYPE type)
#define DB_CONNECTION_STATUS_CONNECTED
Definition: db.h:47
DB_DATA data
Definition: dbtype_def.h:1083
DB_CURRENCY
Definition: dbtype_def.h:799
DB_JSON json
Definition: dbtype_def.h:1073
#define CHECK_1ARG_ZERO(obj)
Definition: db.h:201
unsigned int DB_TIMESTAMP
Definition: dbtype_def.h:759
#define DB_MAX_VARBIT_PRECISION
Definition: dbtype_def.h:552
TP_DOMAIN * tp_domain_resolve_default(DB_TYPE type)
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
int db_value_put_encoded_time(DB_VALUE *value, const DB_TIME *time)
Definition: db_macro.c:1357
int db_make_enumeration(DB_VALUE *value, unsigned short index, DB_CONST_C_CHAR str, int size, unsigned char codeset, const int collation_id)
#define DB_MAX_VARCHAR_PRECISION
Definition: dbtype_def.h:536
#define DB_MAX_NUMERIC_PRECISION
Definition: dbtype_def.h:522
#define DB_INT32_MIN
Definition: dbtype_def.h:632
#define assert(x)
const char * db_string_value(const char *string, int str_size, const char *format, DB_VALUE *value)
Definition: cnv.c:6501
int db_make_monetary(DB_VALUE *value, const DB_CURRENCY type, const double amount)
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 input()
Definition: cnvlex.c:1661
unsigned char * bytes
Definition: db_macro.c:76
#define QSTR_NUM_BYTES(a)
Definition: string_opfunc.h:58
int db_make_set(DB_VALUE *value, DB_C_SET *set)
struct db_domain_info::numeric_info numeric_info
char * db_private_strdup(THREAD_ENTRY *thrd, const char *s)
Definition: memory_alloc.c:675
int db_make_multiset(DB_VALUE *value, DB_C_SET *set)
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)
struct db_char::@52 info
int db_get_connect_status(void)
Definition: db_macro.c:4930
DB_TYPE_C
Definition: dbtype_def.h:1116
int db_time_string(const DB_TIME *the_time, const char *time_format, char *string, int max_size)
Definition: cnv.c:7847
#define ER_OUT_OF_VIRTUAL_MEMORY
Definition: error_code.h:50
DB_TYPE db_value_type(const DB_VALUE *value)
const char * db_json_get_schema_raw_from_validator(JSON_VALIDATOR *val)
Definition: db_json.cpp:2310
int db_time_encode(DB_TIME *timeval, int hour, int minute, int second)
Definition: db_date.c:370
void db_set_connect_status(int status)
Definition: db_macro.c:4936
#define CHECK_1ARG_ERROR(obj)
Definition: db.h:186
#define TIMESTAMP_BUF_SIZE
Definition: string_opfunc.h:91
int compressed_size
Definition: dbtype_def.h:1001
JSON_DOC * document
Definition: dbtype_def.h:1040
DB_DATETIME datetime
Definition: dbtype_def.h:783
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
int db_value_free(DB_VALUE *value)
Definition: db_macro.c:1610
#define DB_INT32_MAX
Definition: dbtype_def.h:633
PR_TYPE tp_NChar
char * compressed_buf
Definition: dbtype_def.h:1002
int db_convert_json_into_scalar(const DB_VALUE *src, DB_VALUE *dest)
Definition: db_macro.c:4981
#define TP_IS_NUMERIC_TYPE(typeid)
static VALCNV_BUFFER * valcnv_append_bytes(VALCNV_BUFFER *old_string, const char *new_tail, const size_t new_tail_length)
Definition: db_macro.c:4221
DB_OBJECT * db_domain_class(const DB_DOMAIN *domain)
Definition: db_macro.c:4030
#define ER_INVALID_CURRENCY_TYPE
Definition: error_code.h:756
bool IS_INVALID_PRECISION(int p, int m)
Definition: db_macro.c:137
static int valcnv_Max_set_elements
Definition: db_macro.c:83
#define CHECK_1ARG_NULL(obj)
Definition: db.h:171
const char * db_domain_raw_json_schema(const DB_DOMAIN *domain)
Definition: db_macro.c:4147
static VALCNV_BUFFER * valcnv_convert_data_to_string(VALCNV_BUFFER *buf, const DB_VALUE *value)
Definition: db_macro.c:4478
int db_timestamp_string(const DB_TIMESTAMP *the_timestamp, const char *timestamp_format, char *string, int max_size)
Definition: cnv.c:8138
int db_json_get_int_from_document(const JSON_DOC *doc)
Definition: db_json.cpp:2525
std::int64_t db_json_get_bigint_from_document(const JSON_DOC *doc)
Definition: db_json.cpp:2531
DB_BIGINT DB_C_BIGINT
Definition: dbtype_def.h:1148
DB_OBJECT * db_get_object(const DB_VALUE *value)
unsigned char buf[DB_NUMERIC_BUF_SIZE]
Definition: dbtype_def.h:794
DB_VALUE * db_value_copy(DB_VALUE *value)
Definition: db_macro.c:1537
int db_char_string_coerce(const DB_VALUE *src_string, DB_VALUE *dest_string, DB_DATA_STATUS *data_status)
#define TP_DOMAIN_TYPE(dom)
DB_VALUE * db_value_create(void)
Definition: db_macro.c:1517
#define DB_DATE_MAX
Definition: dbtype_def.h:650
#define ER_DB_UNSUPPORTED_CONVERSION
Definition: error_code.h:760
#define NULL
Definition: freelistheap.h:34
int db_domain_codeset(const DB_DOMAIN *domain)
Definition: db_macro.c:4116
static VALCNV_BUFFER * valcnv_convert_set_to_string(VALCNV_BUFFER *buf, DB_SET *set)
Definition: db_macro.c:4378
unsigned short db_get_enum_short(const DB_VALUE *value)
int db_string_truncate(DB_VALUE *value, const int precision)
Definition: db_macro.c:962
void db_value_print(const DB_VALUE *value)
Definition: db_macro.c:1663
void db_value_fprint(FILE *fp, const DB_VALUE *value)
Definition: db_macro.c:1681
struct pr_type * type
Definition: object_domain.h:76
DB_CHAR ch
Definition: dbtype_def.h:1070
#define DB_NUMBER_ZERO
Definition: db_macro.c:60
unsigned char size
Definition: dbtype_def.h:990
PR_TYPE tp_VarBit
DB_CURRENCY type
Definition: dbtype_def.h:832
static VALCNV_BUFFER * valcnv_convert_double_to_string(VALCNV_BUFFER *buf, const double value)
Definition: db_macro.c:4307
DB_DATE date
Definition: dbtype_def.h:1057
bool db_value_is_corrupted(const DB_VALUE *value)
Definition: db_macro.c:5094
DB_TIMESTAMPTZ timestamptz
Definition: dbtype_def.h:1059
int db_value_domain_max(DB_VALUE *value, const DB_TYPE type, const int precision, const int scale, const int codeset, const int collation_id, const DB_ENUMERATION *enumeration)
Definition: db_macro.c:581
DB_VALUE * pr_make_ext_value(void)
#define err(fd,...)
Definition: porting.h:431
int db_value_put_monetary_amount_as_double(DB_VALUE *value, const double amount)
Definition: db_macro.c:1470
int db_value_clear_array(DB_VALUE_ARRAY *value_array)
Definition: db_macro.c:1633
int db_value_put_encoded_date(DB_VALUE *value, const DB_DATE *date)
Definition: db_macro.c:1383
#define DB_EMPTY_SESSION
Definition: dbtype_def.h:483
DB_SET * db_set_create_basic(MOP classop, const char *name)
Definition: db_set.c:134
unsigned char is_max_string
Definition: dbtype_def.h:981
#define db_private_free(thrd, ptr)
Definition: memory_alloc.h:229
#define NUM_BUF_SIZE
Definition: string_opfunc.h:88
#define db_private_alloc(thrd, size)
Definition: memory_alloc.h:227
int intl_char_size(const unsigned char *src, int length_in_chars, INTL_CODESET src_codeset, int *byte_count)
#define ER_INVALID_PRECISION
Definition: error_code.h:783
int set_get_element(DB_COLLECTION *set, int index, DB_VALUE *value)
Definition: set_object.c:2575
need_clear_type need_clear
Definition: dbtype_def.h:1084
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 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)
DB_CURRENCY lang_currency()
DB_JSON_TYPE db_json_get_type(const JSON_DOC *doc)
Definition: db_json.cpp:2519
int db_get_deep_copy_of_json(const DB_JSON *src, DB_JSON *dst)
Definition: db_macro.c:2022
int db_Row_count
Definition: db_macro.c:81
int db_time_to_string(char *buf, int bufsize, DB_TIME *time)
Definition: db_date.c:3994
DB_DOMAIN * db_type_to_db_domain(const DB_TYPE type)
Definition: db_macro.c:1710
#define DB_DEFAULT_NUMERIC_PRECISION
Definition: dbtype_def.h:564
int db_value_domain_default(DB_VALUE *value, const DB_TYPE type, const int precision, const int scale, const int codeset, const int collation_id, DB_ENUMERATION *enumeration)
Definition: db_macro.c:756
int db_make_time(DB_VALUE *value, const int hour, const int minute, const int second)
int db_datetime_to_string(char *buf, int bufsize, DB_DATETIME *datetime)
Definition: db_date.c:4225
#define DB_DEFAULT_SCALE
Definition: dbtype_def.h:561
struct db_domain_info::general_info general_info
int64_t DB_BIGINT
Definition: dbtype_def.h:751
DB_CONST_C_CHAR db_get_enum_string(const DB_VALUE *value)
#define TP_IS_CHAR_TYPE(typeid)
static void error(const char *msg)
Definition: gencat.c:331
int valcnv_convert_value_to_string(DB_VALUE *value_p)
Definition: db_macro.c:4901
int db_make_float(DB_VALUE *value, const DB_C_FLOAT num)
#define DB_DEFAULT_PRECISION
Definition: dbtype_def.h:558
PR_TYPE tp_Bit
static VALCNV_BUFFER * valcnv_convert_float_to_string(VALCNV_BUFFER *buf, const float value)
Definition: db_macro.c:4279
static int coerce_time_to_dbvalue(DB_VALUE *value, char *buf)
Definition: db_macro.c:3675
static VALCNV_BUFFER * valcnv_convert_money_to_string(const double value)
Definition: db_macro.c:4450
char * numeric_db_value_print(const DB_VALUE *val, char *buf)
unsigned char compressed_need_clear
Definition: dbtype_def.h:982
#define CHECK_CONNECT_NULL()
Definition: db.h:91
#define ER_UCI_INVALID_DATA_TYPE
Definition: error_code.h:550
#define ARG_FILE_LINE
Definition: error_manager.h:44
PR_TYPE tp_String
static int transfer_bit_string(char *buf, int *xflen, int *outlen, const int buflen, const DB_VALUE *src, const DB_TYPE_C c_type)
Definition: db_macro.c:1979
#define DB_BIGINT_MAX
Definition: dbtype_def.h:640
int pr_clone_value(const DB_VALUE *src, DB_VALUE *dest)
OID * db_get_oid(const DB_VALUE *value)
const char * db_json_get_string_from_document(const JSON_DOC *doc)
Definition: db_json.cpp:2543
#define WS_OID(mop)
Definition: work_space.h:293
#define DB_INT16_MAX
Definition: dbtype_def.h:630
unsigned int DB_TIME
Definition: dbtype_def.h:754
int db_make_varbit(DB_VALUE *value, const int max_bit_length, DB_CONST_C_BIT bit_str, const int bit_str_bit_size)
unsigned int DB_DATE
Definition: dbtype_def.h:771
#define DB_BIGINT_MIN
Definition: dbtype_def.h:641
DB_DATA_STATUS
void db_fprint_value(FILE *fp, const db_value *value)
char * locator
Definition: dbtype_def.h:948
static int coerce_char_to_dbvalue(DB_VALUE *value, char *buf, const int buflen)
Definition: db_macro.c:2964
#define free_and_init(ptr)
Definition: memory_alloc.h:147
void numeric_coerce_dec_str_to_num(const char *dec_str, DB_C_NUMERIC result)
#define strlen(s1)
Definition: intl_support.c:43
DB_DATE * db_get_date(const DB_VALUE *value)
DB_ENUM_ELEMENT * elements
Definition: dbtype_def.h:1031
#define DB_UTIME_MAX
Definition: dbtype_def.h:657
float DB_C_FLOAT
Definition: dbtype_def.h:1152
#define ER_OBJ_INVALID_ARGUMENTS
Definition: error_code.h:275
DB_MONETARY DB_C_MONETARY
Definition: dbtype_def.h:1213
#define OR_MOVE_DOUBLE(src, dst)
Definition: byte_order.h:89
unsigned int date
Definition: dbtype_def.h:776
unsigned int SESSION_ID
Definition: dbtype_def.h:480
int db_value_put(DB_VALUE *value, const DB_TYPE_C c_type, void *input, const int input_length)
Definition: db_macro.c:1256
enum intl_codeset INTL_CODESET
Definition: intl_support.h:190
int intl_char_count(const unsigned char *src, int length_in_bytes, INTL_CODESET src_codeset, int *char_count)
Definition: intl_support.c:983
JSON_VALIDATOR * json_validator
DB_TIMESTAMP * db_get_timestamp(const DB_VALUE *value)
int db_get_string_size(const DB_VALUE *value)
DB_C_SHORT db_get_short(const DB_VALUE *value)
int db_value_get(DB_VALUE *value, const DB_TYPE_C c_type, void *buf, const int buflen, int *xflen, int *outlen)
Definition: db_macro.c:2077
PR_TYPE tp_VarNChar
void elo_init_structure(DB_ELO *elo)
Definition: elo.c:127
int db_make_varnchar(DB_VALUE *value, const int max_nchar_length, DB_CONST_C_NCHAR str, const int nchar_str_byte_size, const int codeset, const int collation_id)
#define TP_FLOATING_PRECISION_VALUE
#define CHECK_CONNECT_ZERO()
Definition: db.h:94
DB_CURRENCY db_value_get_monetary_currency(const DB_VALUE *value)
Definition: db_macro.c:1492
#define DB_VALUE_TYPE(value)
Definition: dbtype.h:72
#define DB_CURRENCY_DEFAULT
Definition: dbtype.h:46
static int coerce_timestamp_to_dbvalue(DB_VALUE *value, char *buf)
Definition: db_macro.c:3756
int i
Definition: dynamic_load.c:954
int db_make_null(DB_VALUE *value)
size_t length
Definition: db_macro.c:75
static int coerce_binary_to_dbvalue(DB_VALUE *value, char *buf, const int buflen)
Definition: db_macro.c:3426
#define DB_IS_NULL(value)
Definition: dbtype.h:63
struct tp_domain * next
Definition: object_domain.h:74
DB_COLLECTION * set
Definition: dbtype_def.h:1063
int db_make_double(DB_VALUE *value, const DB_C_DOUBLE num)
union db_numeric::@51 d
DB_DATETIME * db_get_datetime(const DB_VALUE *value)
static VALCNV_BUFFER * valcnv_convert_bit_to_string(VALCNV_BUFFER *buf, const DB_VALUE *value)
Definition: db_macro.c:4335
#define CHECK_1ARG_ZERO_WITH_TYPE(obj1, RETURN_TYPE)
Definition: db.h:204
#define DB_MAX_VARNCHAR_PRECISION
Definition: dbtype_def.h:546
#define DB_NUMERIC_BUF_SIZE
Definition: dbtype_def.h:573
DB_CURRENCY db_get_currency_default()
Definition: db_macro.c:1870
int db_value_clear(DB_VALUE *value)
Definition: db_macro.c:1588
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)
struct db_object * class_mop
Definition: object_domain.h:81
int DB_C_INT
Definition: dbtype_def.h:1149
int db_make_char(DB_VALUE *value, const int char_length, DB_CONST_C_CHAR str, const int char_str_byte_size, const int codeset, const int collation_id)
static VALCNV_BUFFER * valcnv_convert_db_value_to_string(VALCNV_BUFFER *buf, const DB_VALUE *value)
Definition: db_macro.c:4815
#define LANG_SYS_CODESET
int collation_id
Definition: object_domain.h:92
#define DB_UTIME_MIN
Definition: dbtype_def.h:656
DB_TIME * db_get_time(const DB_VALUE *value)
#define ER_QPROC_INVALID_DATATYPE
Definition: error_code.h:534
int numeric_coerce_string_to_num(const char *astring, int astring_length, INTL_CODESET codeset, DB_VALUE *result)
static int coerce_datetime_to_dbvalue(DB_VALUE *value, char *buf)
Definition: db_macro.c:3861
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
DB_DATA * db_value_get_db_data(DB_VALUE *value)
Definition: db_macro.c:1211
#define CHECK_CONNECT_VOID()
Definition: db.h:70
double amount
Definition: dbtype_def.h:831
TP_DOMAIN_STATUS tp_value_cast_force(const DB_VALUE *src, DB_VALUE *dest, const TP_DOMAIN *desired_domain, bool implicit_coercion)
char * db_json_get_bool_as_str_from_document(const JSON_DOC *doc)
Definition: db_json.cpp:2549
int db_make_bit(DB_VALUE *value, const int bit_length, DB_CONST_C_BIT bit_str, const int bit_str_bit_size)
int db_get_string_codeset(const DB_VALUE *value)
float f
Definition: dbtype_def.h:1052
#define DB_CONNECTION_STATUS_NOT_CONNECTED
Definition: db.h:46
const char ** p
Definition: dynamic_load.c:945
DB_VALUE_COMPARE_RESULT tp_set_compare(const DB_VALUE *value1, const DB_VALUE *value2, int do_coercion, int total_order)
DB_CONST_C_CHAR db_get_string(const DB_VALUE *value)
double d
Definition: dbtype_def.h:1053
int db_Disable_modifications
Definition: db_macro.c:90
DB_MONETARY money
Definition: dbtype_def.h:1062
struct db_char::@54 medium
unsigned int time
Definition: dbtype_def.h:777
DB_DEFAULT_EXPR_TYPE
Definition: dbtype_def.h:1181
#define DB_ENUM_ELEMENTS_MAX
Definition: dbtype_def.h:643
#define DB_TIME_MIN
Definition: dbtype_def.h:652
int db_make_nchar(DB_VALUE *value, const int nchar_length, DB_CONST_C_NCHAR str, const int nchar_str_byte_size, const int codeset, const int collation_id)
DB_DOMAIN * db_domain_set(const DB_DOMAIN *domain)
Definition: db_macro.c:4060
#define CHECK_CONNECT_ERROR()
Definition: db.h:88
int db_value_domain_init(DB_VALUE *value, const DB_TYPE type, const int precision, const int scale)
Definition: db_macro.c:153
#define VALCNV_TOO_BIG_TO_MATTER
Definition: db_macro.c:62
int db_value_alter_type(DB_VALUE *value, const DB_TYPE type)
Definition: db_macro.c:1225
#define DB_MAX_CHAR_PRECISION
Definition: dbtype_def.h:533
DB_DATETIMETZ datetimetz
Definition: dbtype_def.h:1061