CUBRID Engine  latest
dbtype_function.i
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  * dbtype_function.i - API/inlined functions related to db_make and db_get
21  *
22  */
23 
24 #include "dbtype_def.h"
25 
26 #if !defined (_NO_INLINE_DBTYPE_FUNCTION_)
27 #include "porting_inline.hpp"
28 
29 STATIC_INLINE int db_get_int (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
30 STATIC_INLINE DB_C_SHORT db_get_short (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
31 STATIC_INLINE DB_BIGINT db_get_bigint (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
32 STATIC_INLINE DB_CONST_C_CHAR db_get_string (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
33 STATIC_INLINE DB_C_FLOAT db_get_float (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
34 STATIC_INLINE DB_C_DOUBLE db_get_double (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
35 STATIC_INLINE DB_OBJECT *db_get_object (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
36 STATIC_INLINE DB_COLLECTION *db_get_set (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
37 STATIC_INLINE DB_MIDXKEY *db_get_midxkey (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
38 STATIC_INLINE DB_C_POINTER db_get_pointer (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
39 STATIC_INLINE DB_TIME *db_get_time (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
40 STATIC_INLINE DB_TIMESTAMP *db_get_timestamp (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
41 STATIC_INLINE DB_TIMESTAMPTZ *db_get_timestamptz (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
42 STATIC_INLINE DB_DATETIME *db_get_datetime (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
43 STATIC_INLINE DB_DATETIMETZ *db_get_datetimetz (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
44 STATIC_INLINE DB_DATE *db_get_date (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
45 STATIC_INLINE DB_MONETARY *db_get_monetary (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
46 STATIC_INLINE int db_get_error (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
47 STATIC_INLINE DB_ELO *db_get_elo (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
48 STATIC_INLINE DB_C_NUMERIC db_get_numeric (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
49 STATIC_INLINE DB_CONST_C_BIT db_get_bit (const DB_VALUE * value, int *length) __attribute__ ((ALWAYS_INLINE));
50 STATIC_INLINE DB_CONST_C_CHAR db_get_char (const DB_VALUE * value, int *length) __attribute__ ((ALWAYS_INLINE));
51 STATIC_INLINE DB_CONST_C_NCHAR db_get_nchar (const DB_VALUE * value, int *length) __attribute__ ((ALWAYS_INLINE));
52 STATIC_INLINE int db_get_string_size (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
53 STATIC_INLINE unsigned short db_get_enum_short (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
54 STATIC_INLINE DB_CONST_C_CHAR db_get_enum_string (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
55 STATIC_INLINE int db_get_enum_string_size (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
56 STATIC_INLINE DB_C_CHAR db_get_method_error_msg (void) __attribute__ ((ALWAYS_INLINE));
57 STATIC_INLINE DB_RESULTSET db_get_resultset (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
58 STATIC_INLINE INTL_CODESET db_get_string_codeset (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
59 STATIC_INLINE int db_get_string_collation (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
60 STATIC_INLINE int db_get_enum_codeset (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
61 STATIC_INLINE int db_get_enum_collation (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
62 STATIC_INLINE OID *db_get_oid (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
63 STATIC_INLINE DB_TYPE db_value_type (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
64 STATIC_INLINE int db_value_precision (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
65 STATIC_INLINE int db_value_scale (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
66 STATIC_INLINE JSON_DOC *db_get_json_document (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
67 
68 STATIC_INLINE int db_make_db_char (DB_VALUE * value, INTL_CODESET codeset, const int collation_id, DB_CONST_C_CHAR str,
69  const int size) __attribute__ ((ALWAYS_INLINE));
70 
71 STATIC_INLINE int db_make_null (DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
72 STATIC_INLINE int db_make_int (DB_VALUE * value, const int num) __attribute__ ((ALWAYS_INLINE));
73 STATIC_INLINE int db_make_float (DB_VALUE * value, const DB_C_FLOAT num) __attribute__ ((ALWAYS_INLINE));
74 STATIC_INLINE int db_make_double (DB_VALUE * value, const DB_C_DOUBLE num) __attribute__ ((ALWAYS_INLINE));
75 STATIC_INLINE int db_make_object (DB_VALUE * value, DB_C_OBJECT * obj) __attribute__ ((ALWAYS_INLINE));
76 STATIC_INLINE int db_make_midxkey (DB_VALUE * value, DB_MIDXKEY * midxkey) __attribute__ ((ALWAYS_INLINE));
77 STATIC_INLINE int db_make_timestamp (DB_VALUE * value, const DB_C_TIMESTAMP timeval) __attribute__ ((ALWAYS_INLINE));
78 STATIC_INLINE int db_make_timestampltz (DB_VALUE * value, const DB_C_TIMESTAMP ts_val) __attribute__ ((ALWAYS_INLINE));
79 STATIC_INLINE int db_make_timestamptz (DB_VALUE * value, const DB_C_TIMESTAMPTZ * ts_tz_val)
80  __attribute__ ((ALWAYS_INLINE));
81 STATIC_INLINE int db_make_datetime (DB_VALUE * value, const DB_DATETIME * datetime) __attribute__ ((ALWAYS_INLINE));
82 STATIC_INLINE int db_make_datetimeltz (DB_VALUE * value, const DB_DATETIME * datetime) __attribute__ ((ALWAYS_INLINE));
83 STATIC_INLINE int db_make_datetimetz (DB_VALUE * value, const DB_DATETIMETZ * datetimetz)
84  __attribute__ ((ALWAYS_INLINE));
85 STATIC_INLINE int db_make_monetary (DB_VALUE * value, const DB_CURRENCY type, const double amount)
86  __attribute__ ((ALWAYS_INLINE));
87 STATIC_INLINE int db_make_pointer (DB_VALUE * value, DB_C_POINTER ptr) __attribute__ ((ALWAYS_INLINE));
88 STATIC_INLINE int db_make_error (DB_VALUE * value, const int errcode) __attribute__ ((ALWAYS_INLINE));
89 STATIC_INLINE int db_make_method_error (DB_VALUE * value, const int errcode, const char *errmsg)
90  __attribute__ ((ALWAYS_INLINE));
91 STATIC_INLINE int db_make_short (DB_VALUE * value, const DB_C_SHORT num) __attribute__ ((ALWAYS_INLINE));
92 STATIC_INLINE int db_make_bigint (DB_VALUE * value, const DB_BIGINT num) __attribute__ ((ALWAYS_INLINE));
93 STATIC_INLINE int db_make_numeric (DB_VALUE * value, const DB_C_NUMERIC num, const int precision, const int scale)
94  __attribute__ ((ALWAYS_INLINE));
95 STATIC_INLINE int db_make_bit (DB_VALUE * value, const int bit_length, DB_CONST_C_BIT bit_str,
96  const int bit_str_bit_size) __attribute__ ((ALWAYS_INLINE));
97 STATIC_INLINE int db_make_varbit (DB_VALUE * value, const int max_bit_length, DB_CONST_C_BIT bit_str,
98  const int bit_str_bit_size) __attribute__ ((ALWAYS_INLINE));
99 STATIC_INLINE int db_make_char (DB_VALUE * value, const int char_length, DB_CONST_C_CHAR str,
100  const int char_str_byte_size, const int codeset, const int collation_id)
101  __attribute__ ((ALWAYS_INLINE));
102 STATIC_INLINE int db_make_varchar (DB_VALUE * value, const int max_char_length, DB_CONST_C_CHAR str,
103  const int char_str_byte_size, const int codeset, const int collation_id)
104  __attribute__ ((ALWAYS_INLINE));
105 STATIC_INLINE int db_make_nchar (DB_VALUE * value, const int nchar_length, DB_CONST_C_NCHAR str,
106  const int nchar_str_byte_size, const int codeset, const int collation_id)
107  __attribute__ ((ALWAYS_INLINE));
108 STATIC_INLINE int db_make_varnchar (DB_VALUE * value, const int max_nchar_length, DB_CONST_C_NCHAR str,
109  const int nchar_str_byte_size, const int codeset, const int collation_id)
110  __attribute__ ((ALWAYS_INLINE));
111 STATIC_INLINE int db_make_enumeration (DB_VALUE * value, unsigned short index, DB_CONST_C_CHAR str, int size,
112  unsigned char codeset, const int collation_id) __attribute__ ((ALWAYS_INLINE));
113 STATIC_INLINE int db_make_resultset (DB_VALUE * value, const DB_RESULTSET handle) __attribute__ ((ALWAYS_INLINE));
114 
115 STATIC_INLINE int db_make_string (DB_VALUE * value, DB_CONST_C_CHAR str) __attribute__ ((ALWAYS_INLINE));
116 STATIC_INLINE int db_make_string_copy (DB_VALUE * value, DB_CONST_C_CHAR str) __attribute__ ((ALWAYS_INLINE));
117 
118 STATIC_INLINE int db_make_oid (DB_VALUE * value, const OID * oid) __attribute__ ((ALWAYS_INLINE));
119 
120 STATIC_INLINE int db_make_set (DB_VALUE * value, DB_C_SET * set) __attribute__ ((ALWAYS_INLINE));
121 STATIC_INLINE int db_make_multiset (DB_VALUE * value, DB_C_SET * set) __attribute__ ((ALWAYS_INLINE));
122 STATIC_INLINE int db_make_sequence (DB_VALUE * value, DB_C_SET * set) __attribute__ ((ALWAYS_INLINE));
123 STATIC_INLINE int db_make_collection (DB_VALUE * value, DB_C_SET * set) __attribute__ ((ALWAYS_INLINE));
124 
125 STATIC_INLINE int db_make_elo (DB_VALUE * value, DB_TYPE type, const DB_ELO * elo) __attribute__ ((ALWAYS_INLINE));
126 
127 STATIC_INLINE int db_make_time (DB_VALUE * value, const int hour, const int minute, const int second)
128  __attribute__ ((ALWAYS_INLINE));
129 STATIC_INLINE int db_make_date (DB_VALUE * value, const int month, const int day, const int year)
130  __attribute__ ((ALWAYS_INLINE));
131 
132 STATIC_INLINE int db_make_json (DB_VALUE * value, JSON_DOC * json_document, bool need_clear)
133  __attribute__ ((ALWAYS_INLINE));
134 
135 STATIC_INLINE int db_get_compressed_size (DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
136 STATIC_INLINE void db_set_compressed_string (DB_VALUE * value, char *compressed_string,
137  int compressed_size, bool compressed_need_clear)
138  __attribute__ ((ALWAYS_INLINE));
139 
140 STATIC_INLINE bool db_value_is_null (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
141 STATIC_INLINE DB_TYPE db_value_domain_type (const DB_VALUE * value) __attribute__ ((ALWAYS_INLINE));
142 #endif // !NO_INLINE_DBTYPE_FUNCTION
143 
144 #include <assert.h>
145 
146 /*
147  * db_get_int() -
148  * return :
149  * value(in):
150  */
151 int
152 db_get_int (const DB_VALUE * value)
153 {
154 #if defined (API_ACTIVE_CHECKS)
155  CHECK_1ARG_ZERO (value);
156 #endif
157 
158  assert (value->domain.general_info.type == DB_TYPE_INTEGER);
159 
160  return value->data.i;
161 }
162 
163 /*
164  * db_get_short() -
165  * return :
166  * value(in):
167  */
168 short
169 db_get_short (const DB_VALUE * value)
170 {
171 #if defined (API_ACTIVE_CHECKS)
172  CHECK_1ARG_ZERO (value);
173 #endif
174 
175  assert (value->domain.general_info.type == DB_TYPE_SHORT);
176 
177  return value->data.sh;
178 }
179 
180 /*
181  * db_get_bigint() -
182  * return :
183  * value(in):
184  */
185 DB_BIGINT
186 db_get_bigint (const DB_VALUE * value)
187 {
188 #if defined (API_ACTIVE_CHECKS)
189  CHECK_1ARG_ZERO (value);
190 #endif
191 
192  assert (value->domain.general_info.type == DB_TYPE_BIGINT);
193 
194  return value->data.bigint;
195 }
196 
197 /*
198  * db_get_string() -
199  * return :
200  * value(in):
201  */
202 DB_CONST_C_CHAR
203 db_get_string (const DB_VALUE * value)
204 {
205  const char *str = NULL;
206 
207 #if defined (API_ACTIVE_CHECKS)
208  CHECK_1ARG_NULL (value);
209 #endif
210 
211  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
212  {
213  return NULL;
214  }
215 
216  switch (value->data.ch.info.style)
217  {
218  case SMALL_STRING:
219  str = value->data.ch.sm.buf;
220  break;
221  case MEDIUM_STRING:
222  str = value->data.ch.medium.buf;
223  break;
224  case LARGE_STRING:
225  /* Currently not implemented */
226  str = NULL;
227  break;
228  }
229 
230  return str;
231 }
232 
233 /*
234  * db_get_float() -
235  * return :
236  * value(in):
237  */
238 float
239 db_get_float (const DB_VALUE * value)
240 {
241 #if defined (API_ACTIVE_CHECKS)
242  CHECK_1ARG_ZERO (value);
243 #endif
244 
245  assert (value->domain.general_info.type == DB_TYPE_FLOAT);
246 
247  return value->data.f;
248 }
249 
250 /*
251  * db_get_double() -
252  * return :
253  * value(in):
254  */
255 double
256 db_get_double (const DB_VALUE * value)
257 {
258 #if defined (API_ACTIVE_CHECKS)
259  CHECK_1ARG_ZERO (value);
260 #endif
261 
262  assert (value->domain.general_info.type == DB_TYPE_DOUBLE);
263 
264  return value->data.d;
265 }
266 
267 /*
268  * db_get_object() -
269  * return :
270  * value(in):
271  */
272 DB_OBJECT *
273 db_get_object (const DB_VALUE * value)
274 {
275 #if defined (API_ACTIVE_CHECKS)
276  CHECK_1ARG_NULL (value);
277 #endif
278 
279  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
280  {
281  return NULL;
282  }
283  else
284  {
285  return value->data.op;
286  }
287 }
288 
289 /*
290  * db_get_set() -
291  * return :
292  * value(in):
293  */
294 DB_SET *
295 db_get_set (const DB_VALUE * value)
296 {
297 #if defined (API_ACTIVE_CHECKS)
298  CHECK_1ARG_NULL (value);
299 #endif
300 
301  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
302  {
303  return NULL;
304  }
305  else
306  {
307  return value->data.set;
308  }
309 }
310 
311 /*
312  * db_get_midxkey() -
313  * return :
314  * value(in):
315  */
316 DB_MIDXKEY *
317 db_get_midxkey (const DB_VALUE * value)
318 {
319 #if defined (API_ACTIVE_CHECKS)
320  CHECK_1ARG_NULL (value);
321 #endif
322 
323  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
324  {
325  return NULL;
326  }
327  else
328  {
329  return (DB_MIDXKEY *) (&(value->data.midxkey));
330  }
331 }
332 
333 /*
334  * db_get_pointer() -
335  * return :
336  * value(in):
337  */
338 void *
339 db_get_pointer (const DB_VALUE * value)
340 {
341 #if defined (API_ACTIVE_CHECKS)
342  CHECK_1ARG_NULL (value);
343 #endif
344 
345  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
346  {
347  return NULL;
348  }
349  else
350  {
351  return value->data.p;
352  }
353 }
354 
355 /*
356  * db_get_time() -
357  * return :
358  * value(in):
359  */
360 DB_TIME *
361 db_get_time (const DB_VALUE * value)
362 {
363 #if defined (API_ACTIVE_CHECKS)
364  CHECK_1ARG_NULL (value);
365 #endif
366 
367  assert (value->domain.general_info.type == DB_TYPE_TIME);
368 
369  // todo: Assess how to better handle const types, here we should return explicit values, not pointers. Same for below.
370  return (DB_TIME *) (&value->data.time);
371 }
372 
373 /*
374  * db_get_timestamp() -
375  * return :
376  * value(in):
377  */
378 DB_TIMESTAMP *
379 db_get_timestamp (const DB_VALUE * value)
380 {
381 #if defined (API_ACTIVE_CHECKS)
382  CHECK_1ARG_NULL (value);
383 #endif
384 
385  assert (value->domain.general_info.type == DB_TYPE_TIMESTAMP
386  || value->domain.general_info.type == DB_TYPE_TIMESTAMPLTZ);
387 
388  return ((DB_TIMESTAMP *) (&value->data.utime));
389 }
390 
391 /*
392  * db_get_timestamptz() -
393  * return :
394  * value(in):
395  */
396 DB_TIMESTAMPTZ *
397 db_get_timestamptz (const DB_VALUE * value)
398 {
399 #if defined (API_ACTIVE_CHECKS)
400  CHECK_1ARG_NULL (value);
401 #endif
402 
403  assert (value->domain.general_info.type == DB_TYPE_TIMESTAMPTZ);
404 
405  return ((DB_TIMESTAMPTZ *) (&value->data.timestamptz));
406 }
407 
408 /*
409  * db_get_datetime() -
410  * return :
411  * value(in):
412  */
413 DB_DATETIME *
414 db_get_datetime (const DB_VALUE * value)
415 {
416 #if defined (API_ACTIVE_CHECKS)
417  CHECK_1ARG_NULL (value);
418 #endif
419 
420  assert (value->domain.general_info.type == DB_TYPE_DATETIME
421  || value->domain.general_info.type == DB_TYPE_DATETIMELTZ);
422 
423  return ((DB_DATETIME *) (&value->data.datetime));
424 }
425 
426 /*
427  * db_get_datetimetz() -
428  * return :
429  * value(in):
430  */
431 DB_DATETIMETZ *
432 db_get_datetimetz (const DB_VALUE * value)
433 {
434 #if defined (API_ACTIVE_CHECKS)
435  CHECK_1ARG_NULL (value);
436 #endif
437 
438  assert (value->domain.general_info.type == DB_TYPE_DATETIMETZ);
439 
440  return ((DB_DATETIMETZ *) (&value->data.datetimetz));
441 }
442 
443 /*
444  * db_get_date() -
445  * return :
446  * value(in):
447  */
448 DB_DATE *
449 db_get_date (const DB_VALUE * value)
450 {
451 #if defined (API_ACTIVE_CHECKS)
452  CHECK_1ARG_NULL (value);
453 #endif
454 
455  assert (value->domain.general_info.type == DB_TYPE_DATE);
456 
457  return ((DB_DATE *) (&value->data.date));
458 }
459 
460 /*
461  * db_get_monetary() -
462  * return :
463  * value(in):
464  */
465 DB_MONETARY *
466 db_get_monetary (const DB_VALUE * value)
467 {
468 #if defined (API_ACTIVE_CHECKS)
469  CHECK_1ARG_NULL (value);
470 #endif
471 
472  assert (value->domain.general_info.type == DB_TYPE_MONETARY);
473 
474  return ((DB_MONETARY *) (&value->data.money));
475 }
476 
477 /*
478  * db_get_error() -
479  * return :
480  * value(in):
481  */
482 int
483 db_get_error (const DB_VALUE * value)
484 {
485 #if defined (API_ACTIVE_CHECKS)
486  CHECK_1ARG_ZERO (value);
487 #endif
488 
489  assert (value->domain.general_info.type == DB_TYPE_ERROR);
490 
491  return value->data.error;
492 }
493 
494 /*
495  * db_get_elo() -
496  * return :
497  * value(in):
498  */
499 DB_ELO *
500 db_get_elo (const DB_VALUE * value)
501 {
502 #if defined (API_ACTIVE_CHECKS)
503  CHECK_1ARG_NULL (value);
504 #endif
505 
506  if (value->domain.general_info.is_null || DB_VALUE_DOMAIN_TYPE (value) == DB_TYPE_ERROR)
507  {
508  return NULL;
509  }
510  else if (value->data.elo.type == ELO_NULL)
511  {
512  return NULL;
513  }
514  else
515  {
516  return ((DB_ELO *) (&value->data.elo));
517  }
518 }
519 
520 /*
521  * db_get_numeric() -
522  * return :
523  * value(in):
524  */
525 DB_C_NUMERIC
526 db_get_numeric (const DB_VALUE * value)
527 {
528 #if defined (API_ACTIVE_CHECKS)
529  CHECK_1ARG_ZERO (value);
530 #endif
531 
532  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
533  {
534  return NULL;
535  }
536  else
537  {
538  return (DB_C_NUMERIC) (value->data.num.d.buf);
539  }
540 }
541 
542 /*
543  * db_get_bit() -
544  * return :
545  * value(in):
546  * length(out):
547  */
548 DB_CONST_C_BIT
549 db_get_bit (const DB_VALUE * value, int *length)
550 {
551  const char *str = NULL;
552 
553 #if defined (API_ACTIVE_CHECKS)
554  CHECK_1ARG_NULL (value);
555  CHECK_1ARG_NULL (length);
556 #endif
557 
558  if (value->domain.general_info.is_null)
559  {
560  return NULL;
561  }
562 
563  switch (value->data.ch.info.style)
564  {
565  case SMALL_STRING:
566  {
567  *length = value->data.ch.sm.size;
568  str = value->data.ch.sm.buf;
569  }
570  break;
571  case MEDIUM_STRING:
572  {
573  *length = value->data.ch.medium.size;
574  str = value->data.ch.medium.buf;
575  }
576  break;
577  case LARGE_STRING:
578  {
579  /* Currently not implemented */
580  *length = 0;
581  str = NULL;
582  }
583  break;
584  }
585 
586  return str;
587 }
588 
589 /*
590  * db_get_char() -
591  * return :
592  * value(in):
593  * length(out):
594  */
595 DB_CONST_C_CHAR
596 db_get_char (const DB_VALUE * value, int *length)
597 {
598  const char *str = NULL;
599 
600 #if defined (API_ACTIVE_CHECKS)
601  CHECK_1ARG_NULL (value);
602  CHECK_1ARG_NULL (length);
603 #endif
604 
605  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
606  {
607  return NULL;
608  }
609 
610  switch (value->data.ch.info.style)
611  {
612  case SMALL_STRING:
613  {
614  str = value->data.ch.sm.buf;
615  intl_char_count ((unsigned char *) str, value->data.ch.sm.size,
616  (INTL_CODESET) value->data.ch.info.codeset, length);
617  }
618  break;
619  case MEDIUM_STRING:
620  {
621  str = value->data.ch.medium.buf;
622  intl_char_count ((unsigned char *) str, value->data.ch.medium.size,
623  (INTL_CODESET) value->data.ch.info.codeset, length);
624  }
625  break;
626  case LARGE_STRING:
627  {
628  /* Currently not implemented */
629  str = NULL;
630  *length = 0;
631  }
632  break;
633  }
634 
635  return str;
636 }
637 
638 /*
639  * db_get_nchar() -
640  * return :
641  * value(in):
642  * length(out):
643  */
644 DB_CONST_C_NCHAR
645 db_get_nchar (const DB_VALUE * value, int *length)
646 {
647  return db_get_char (value, length);
648 }
649 
650 /*
651  * db_get_string_size() -
652  * return :
653  * value(in):
654  */
655 int
656 db_get_string_size (const DB_VALUE * value)
657 {
658  int size = 0;
659 
660 #if defined (API_ACTIVE_CHECKS)
661  CHECK_1ARG_ZERO (value);
662 #endif
663 
664  switch (value->data.ch.info.style)
665  {
666  case SMALL_STRING:
667  size = value->data.ch.sm.size;
668  break;
669  case MEDIUM_STRING:
670  size = value->data.ch.medium.size;
671  break;
672  case LARGE_STRING:
673  /* Currently not implemented */
674  size = 0;
675  break;
676  }
677 
678  /* Convert the number of bits to the number of bytes */
679  if (value->domain.general_info.type == DB_TYPE_BIT || value->domain.general_info.type == DB_TYPE_VARBIT)
680  {
681  size = (size + 7) / 8;
682  }
683 
684  return size;
685 }
686 
687 /*
688  * db_get_enum_short () -
689  * return :
690  * value(in):
691  */
692 unsigned short
693 db_get_enum_short (const DB_VALUE * value)
694 {
695 #if defined (API_ACTIVE_CHECKS)
696  CHECK_1ARG_ZERO (value);
697 #endif
698 
699  assert (value->domain.general_info.type == DB_TYPE_ENUMERATION);
700 
701  return value->data.enumeration.short_val;
702 }
703 
704 /*
705  * db_get_enum_string () -
706  * return :
707  * value(in):
708  */
709 DB_CONST_C_CHAR
710 db_get_enum_string (const DB_VALUE * value)
711 {
712 #if defined (API_ACTIVE_CHECKS)
713  CHECK_1ARG_ZERO (value);
714 #endif
715 
716  if (value->domain.general_info.is_null || value->domain.general_info.type == DB_TYPE_ERROR)
717  {
718  return NULL;
719  }
720  return value->data.enumeration.str_val.medium.buf;
721 }
722 
723 /*
724  * db_get_enum_string_size () -
725  * return :
726  * value(in):
727  */
728 int
729 db_get_enum_string_size (const DB_VALUE * value)
730 {
731 #if defined (API_ACTIVE_CHECKS)
732  CHECK_1ARG_ZERO (value);
733 #endif
734 
735  assert (value->domain.general_info.type == DB_TYPE_ENUMERATION);
736 
737  return value->data.enumeration.str_val.medium.size;
738 }
739 
740 /*
741  * db_get_method_error_msg() -
742  * return :
743  */
744 char *
745 db_get_method_error_msg (void)
746 {
747 #if !defined(SERVER_MODE)
748  return obj_Method_error_msg;
749 #else
750  return NULL;
751 #endif
752 }
753 
754 /*
755  * db_get_resultset() -
756  * return :
757  * value(in):
758  */
759 DB_RESULTSET
760 db_get_resultset (const DB_VALUE * value)
761 {
762 #if defined (API_ACTIVE_CHECKS)
763  CHECK_1ARG_ZERO (value);
764 #endif
765 
766  assert (value->domain.general_info.type == DB_TYPE_RESULTSET);
767 
768  return value->data.rset;
769 }
770 
771 /*
772  * db_get_string_codeset() -
773  * return :
774  * value(in):
775  */
776 INTL_CODESET
777 db_get_string_codeset (const DB_VALUE * value)
778 {
779 #if defined (API_ACTIVE_CHECKS)
780  CHECK_1ARG_ZERO_WITH_TYPE (value, INTL_CODESET);
781 #endif
782 
783  return (INTL_CODESET) value->data.ch.info.codeset;
784 }
785 
786 /*
787  * db_get_string_collation() -
788  * return :
789  * value(in):
790  */
791 int
792 db_get_string_collation (const DB_VALUE * value)
793 {
794 #if defined (API_ACTIVE_CHECKS)
795  CHECK_1ARG_ZERO_WITH_TYPE (value, int);
796 #endif
797 
798  return value->domain.char_info.collation_id;
799 }
800 
801 /*
802  * db_get_enum_codeset() -
803  * return :
804  * value(in):
805  */
806 int
807 db_get_enum_codeset (const DB_VALUE * value)
808 {
809 #if defined (API_ACTIVE_CHECKS)
810  CHECK_1ARG_ZERO_WITH_TYPE (value, INTL_CODESET);
811 #endif
812 
813  return value->data.enumeration.str_val.info.codeset;
814 }
815 
816 /*
817  * db_get_enum_collation() -
818  * return :
819  * value(in):
820  */
821 int
822 db_get_enum_collation (const DB_VALUE * value)
823 {
824 #if defined (API_ACTIVE_CHECKS)
825  CHECK_1ARG_ZERO_WITH_TYPE (value, int);
826 #endif
827 
828  return value->domain.char_info.collation_id;
829 }
830 
831 /*
832  * db_get_oid() -
833  * return :
834  * value(in):
835  */
836 OID *
837 db_get_oid (const DB_VALUE * value)
838 {
839 #if defined (API_ACTIVE_CHECKS)
840  CHECK_1ARG_NULL (value);
841 #endif
842 
843  assert (value->domain.general_info.type == DB_TYPE_OID);
844 
845  return ((OID *) (&value->data.oid));
846 }
847 
848 /*
849  * db_value_type()
850  * return : DB_TYPE of value's domain or DB_TYPE_NULL
851  * value(in) : Pointer to a DB_VALUE
852  */
853 DB_TYPE
854 db_value_type (const DB_VALUE * value)
855 {
856 #if defined (API_ACTIVE_CHECKS)
857  CHECK_1ARG_UNKNOWN (value);
858 #else
859  if (value == NULL)
860  {
861  // todo: Should this ever happen?
862  assert (false);
863  return DB_TYPE_NULL;
864  }
865 #endif
866 
867  if (value->domain.general_info.is_null)
868  {
869  return DB_TYPE_NULL;
870  }
871  else
872  {
873  return DB_VALUE_DOMAIN_TYPE (value);
874  }
875 }
876 
877 /*
878  * db_value_precision() - get the precision of value.
879  * return : precision of given value.
880  * value(in) : Pointer to a DB_VALUE.
881  */
882 int
883 db_value_precision (const DB_VALUE * value)
884 {
885 #if defined (API_ACTIVE_CHECKS)
886  CHECK_1ARG_ZERO (value);
887 #else
888  if (value == NULL)
889  {
890  // todo : Should this ever happen?
891  assert (false);
892  return 0;
893  }
894 #endif
895 
896  switch (value->domain.general_info.type)
897  {
898  case DB_TYPE_NUMERIC:
899  case DB_TYPE_SHORT:
900  case DB_TYPE_INTEGER:
901  case DB_TYPE_BIGINT:
902  case DB_TYPE_FLOAT:
903  case DB_TYPE_DOUBLE:
904  case DB_TYPE_TIME:
905  case DB_TYPE_TIMESTAMP:
906  case DB_TYPE_TIMESTAMPTZ:
907  case DB_TYPE_TIMESTAMPLTZ:
908  case DB_TYPE_DATE:
909  case DB_TYPE_DATETIME:
910  case DB_TYPE_DATETIMETZ:
911  case DB_TYPE_DATETIMELTZ:
912  case DB_TYPE_MONETARY:
913  return value->domain.numeric_info.precision;
914  case DB_TYPE_BIT:
915  case DB_TYPE_VARBIT:
916  case DB_TYPE_CHAR:
917  case DB_TYPE_VARCHAR:
918  case DB_TYPE_NCHAR:
919  case DB_TYPE_VARNCHAR:
920  return value->domain.char_info.length;
921  case DB_TYPE_OBJECT:
922  case DB_TYPE_SET:
923  case DB_TYPE_MULTISET:
924  case DB_TYPE_SEQUENCE:
925  case DB_TYPE_BLOB:
926  case DB_TYPE_CLOB:
927  case DB_TYPE_VARIABLE:
928  case DB_TYPE_SUB:
929  case DB_TYPE_POINTER:
930  case DB_TYPE_ERROR:
931  case DB_TYPE_VOBJ:
932  case DB_TYPE_OID:
933  default:
934  return 0;
935  }
936 }
937 
938 /*
939  * db_value_scale() - get the scale of value.
940  * return : scale of given value.
941  * value(in) : Pointer to a DB_VALUE.
942  */
943 int
944 db_value_scale (const DB_VALUE * value)
945 {
946 #if defined (API_ACTIVE_CHECKS)
947  CHECK_1ARG_ZERO (value);
948 #else
949  if (value == NULL)
950  {
951  // todo: Should this ever happen?
952  assert (false);
953  return 0;
954  }
955 #endif
956 
957  if (value->domain.general_info.type == DB_TYPE_NUMERIC
958  || value->domain.general_info.type == DB_TYPE_DATETIME
959  || value->domain.general_info.type == DB_TYPE_DATETIMETZ
960  || value->domain.general_info.type == DB_TYPE_DATETIMELTZ)
961  {
962  return value->domain.numeric_info.scale;
963  }
964  else
965  {
966  return 0;
967  }
968 }
969 
970 JSON_DOC *
971 db_get_json_document (const DB_VALUE * value)
972 {
973 #if defined (API_ACTIVE_CHECKS)
974  CHECK_1ARG_ZERO (value);
975 #endif
976 
977  assert (value->domain.general_info.type == DB_TYPE_JSON);
978 
979  return value->data.json.document;
980 }
981 
982 /***********************************************************/
983 /* db_make family of functions. */
984 
985 /*
986  * db_make_db_char() -
987  * return :
988  * value(out) :
989  * codeset(in):
990  * collation_id(in):
991  * str(in):
992  * size(in):
993  */
994 int
995 db_make_db_char (DB_VALUE * value, const INTL_CODESET codeset, const int collation_id, DB_CONST_C_CHAR str,
996  const int size)
997 {
998 #if defined (API_ACTIVE_CHECKS)
999  CHECK_1ARG_ERROR (value);
1000 #endif
1001 
1002  value->data.ch.info.style = MEDIUM_STRING;
1003  value->data.ch.info.is_max_string = false;
1004  value->data.ch.info.compressed_need_clear = false;
1005  value->data.ch.medium.codeset = codeset;
1006  value->data.ch.medium.size = size;
1007  value->data.ch.medium.buf = str;
1008  value->data.ch.medium.compressed_buf = NULL;
1009  value->data.ch.medium.compressed_size = 0;
1010  value->domain.general_info.is_null = ((void *) str != NULL) ? 0 : 1;
1011  value->domain.general_info.is_null = ((size == 0 && prm_get_bool_value (PRM_ID_ORACLE_STYLE_EMPTY_STRING))
1012  ? 1 : DB_IS_NULL (value));
1013  value->domain.char_info.collation_id = collation_id;
1014  value->need_clear = false;
1015 
1016  return NO_ERROR;
1017 }
1018 
1019 /*
1020  * db_make_null() -
1021  * return :
1022  * value(out) :
1023  */
1024 int
1025 db_make_null (DB_VALUE * value)
1026 {
1027 #if defined (API_ACTIVE_CHECKS)
1028  CHECK_1ARG_ERROR (value);
1029 #endif
1030 
1031  value->domain.general_info.type = DB_TYPE_NULL;
1032  value->domain.general_info.is_null = 1;
1033  value->need_clear = false;
1034 
1035  return NO_ERROR;
1036 }
1037 
1038 /*
1039  * db_make_int() -
1040  * return :
1041  * value(out) :
1042  * num(in):
1043  */
1044 int
1045 db_make_int (DB_VALUE * value, const int num)
1046 {
1047 #if defined (API_ACTIVE_CHECKS)
1048  CHECK_1ARG_ERROR (value);
1049 #endif
1050 
1051  value->domain.general_info.type = DB_TYPE_INTEGER;
1052  value->data.i = num;
1053  value->domain.general_info.is_null = 0;
1054  value->need_clear = false;
1055 
1056  return NO_ERROR;
1057 }
1058 
1059 /*
1060  * db_make_float() -
1061  * return :
1062  * value(out) :
1063  * num(in):
1064  */
1065 int
1066 db_make_float (DB_VALUE * value, const float num)
1067 {
1068 #if defined (API_ACTIVE_CHECKS)
1069  CHECK_1ARG_ERROR (value);
1070 #endif
1071 
1072  value->domain.general_info.type = DB_TYPE_FLOAT;
1073  value->data.f = num;
1074  value->domain.general_info.is_null = 0;
1075  value->need_clear = false;
1076 
1077  return NO_ERROR;
1078 }
1079 
1080 /*
1081  * db_make_double() -
1082  * return :
1083  * value(out) :
1084  * num(in):
1085  */
1086 int
1087 db_make_double (DB_VALUE * value, const double num)
1088 {
1089 #if defined (API_ACTIVE_CHECKS)
1090  CHECK_1ARG_ERROR (value);
1091 #endif
1092 
1093  value->domain.general_info.type = DB_TYPE_DOUBLE;
1094  value->data.d = num;
1095  value->domain.general_info.is_null = 0;
1096  value->need_clear = false;
1097 
1098  return NO_ERROR;
1099 }
1100 
1101 /*
1102  * db_make_object() -
1103  * return :
1104  * value(out) :
1105  * obj(in):
1106  */
1107 int
1108 db_make_object (DB_VALUE * value, DB_OBJECT * obj)
1109 {
1110 #if defined (API_ACTIVE_CHECKS)
1111  CHECK_1ARG_ERROR (value);
1112 #endif
1113 
1114  value->domain.general_info.type = DB_TYPE_OBJECT;
1115  value->data.op = obj;
1116  if (obj)
1117  {
1118  value->domain.general_info.is_null = 0;
1119  }
1120  else
1121  {
1122  value->domain.general_info.is_null = 1;
1123  }
1124 
1125  value->need_clear = false;
1126 
1127  return NO_ERROR;
1128 }
1129 
1130 /*
1131  * db_make_midxkey() -
1132  * return :
1133  * value(out) :
1134  * midxkey(in):
1135  */
1136 int
1137 db_make_midxkey (DB_VALUE * value, DB_MIDXKEY * midxkey)
1138 {
1139  int error = NO_ERROR;
1140 
1141 #if defined (API_ACTIVE_CHECKS)
1142  CHECK_1ARG_ERROR (value);
1143 #endif
1144 
1145  value->domain.general_info.type = DB_TYPE_MIDXKEY;
1146 
1147  if (midxkey == NULL)
1148  {
1149  value->domain.general_info.is_null = 1;
1150  value->data.midxkey.ncolumns = -1;
1151  value->data.midxkey.domain = NULL;
1152  value->data.midxkey.size = 0;
1153  value->data.midxkey.buf = NULL;
1154  value->data.midxkey.min_max_val.position = -1;
1155  value->data.midxkey.min_max_val.type = MIN_COLUMN;
1156  }
1157  else
1158  {
1159  value->domain.general_info.is_null = 0;
1160  value->data.midxkey = *midxkey;
1161  }
1162 
1163  value->need_clear = false;
1164 
1165  return error;
1166 }
1167 
1168 /*
1169  * db_make_timestamp() -
1170  * return :
1171  * value(out):
1172  * timeval(in):
1173  */
1174 int
1175 db_make_timestamp (DB_VALUE * value, const DB_TIMESTAMP timeval)
1176 {
1177 #if defined (API_ACTIVE_CHECKS)
1178  CHECK_1ARG_ERROR (value);
1179 #endif
1180 
1181  value->domain.general_info.type = DB_TYPE_TIMESTAMP;
1182  value->data.utime = timeval;
1183  value->domain.general_info.is_null = 0;
1184  value->need_clear = false;
1185 
1186  return NO_ERROR;
1187 }
1188 
1189 /*
1190  * db_make_timestampltz() -
1191  * return :
1192  * value(out):
1193  * timeval(in):
1194  */
1195 int
1196 db_make_timestampltz (DB_VALUE * value, const DB_TIMESTAMP ts_val)
1197 {
1198 #if defined (API_ACTIVE_CHECKS)
1199  CHECK_1ARG_ERROR (value);
1200 #endif
1201 
1202  value->domain.general_info.type = DB_TYPE_TIMESTAMPLTZ;
1203  value->data.utime = ts_val;
1204  value->domain.general_info.is_null = 0;
1205  value->need_clear = false;
1206 
1207  return NO_ERROR;
1208 }
1209 
1210 /*
1211  * db_make_timestamptz() -
1212  * return :
1213  * value(out):
1214  * timeval(in):
1215  */
1216 int
1217 db_make_timestamptz (DB_VALUE * value, const DB_TIMESTAMPTZ * ts_tz_val)
1218 {
1219 #if defined (API_ACTIVE_CHECKS)
1220  CHECK_1ARG_ERROR (value);
1221 #endif
1222 
1223  value->domain.general_info.type = DB_TYPE_TIMESTAMPTZ;
1224  if (ts_tz_val)
1225  {
1226  value->data.timestamptz = *ts_tz_val;
1227  value->domain.general_info.is_null = 0;
1228  }
1229  else
1230  {
1231  value->domain.general_info.is_null = 1;
1232  }
1233  value->need_clear = false;
1234 
1235  return NO_ERROR;
1236 }
1237 
1238 /*
1239  * db_make_datetime() -
1240  * return :
1241  * value(out):
1242  * date(in):
1243  */
1244 int
1245 db_make_datetime (DB_VALUE * value, const DB_DATETIME * datetime)
1246 {
1247 #if defined (API_ACTIVE_CHECKS)
1248  CHECK_1ARG_ERROR (value);
1249 #endif
1250 
1251  value->domain.general_info.type = DB_TYPE_DATETIME;
1252  if (datetime)
1253  {
1254  value->data.datetime = *datetime;
1255  value->domain.general_info.is_null = 0;
1256  }
1257  else
1258  {
1259  value->domain.general_info.is_null = 1;
1260  }
1261  value->need_clear = false;
1262 
1263  return NO_ERROR;
1264 }
1265 
1266 /*
1267  * db_make_datetimeltz() -
1268  * return :
1269  * value(out):
1270  * date(in):
1271  */
1272 int
1273 db_make_datetimeltz (DB_VALUE * value, const DB_DATETIME * datetime)
1274 {
1275 #if defined (API_ACTIVE_CHECKS)
1276  CHECK_1ARG_ERROR (value);
1277 #endif
1278 
1279  value->domain.general_info.type = DB_TYPE_DATETIMELTZ;
1280  if (datetime)
1281  {
1282  value->data.datetime = *datetime;
1283  value->domain.general_info.is_null = 0;
1284  }
1285  else
1286  {
1287  value->domain.general_info.is_null = 1;
1288  }
1289  value->need_clear = false;
1290 
1291  return NO_ERROR;
1292 }
1293 
1294 /*
1295  * db_make_datetimetz() -
1296  * return :
1297  * value(out):
1298  * date(in):
1299  */
1300 int
1301 db_make_datetimetz (DB_VALUE * value, const DB_DATETIMETZ * datetimetz)
1302 {
1303 #if defined (API_ACTIVE_CHECKS)
1304  CHECK_1ARG_ERROR (value);
1305 #endif
1306 
1307  value->domain.general_info.type = DB_TYPE_DATETIMETZ;
1308  if (datetimetz)
1309  {
1310  value->data.datetimetz = *datetimetz;
1311  value->domain.general_info.is_null = 0;
1312  }
1313  else
1314  {
1315  value->domain.general_info.is_null = 1;
1316  }
1317  value->need_clear = false;
1318 
1319  return NO_ERROR;
1320 }
1321 
1322 /*
1323  * db_make_monetary() -
1324  * return :
1325  * value(out):
1326  * type(in):
1327  * amount(in):
1328  */
1329 int
1330 db_make_monetary (DB_VALUE * value, const DB_CURRENCY type, const double amount)
1331 {
1332  int error;
1333 
1334 #if defined (API_ACTIVE_CHECKS)
1335  CHECK_1ARG_ERROR (value);
1336 #endif
1337 
1338  /* check for valid currency type don't put default case in the switch!!! */
1339  error = ER_INVALID_CURRENCY_TYPE;
1340  switch (type)
1341  {
1342  case DB_CURRENCY_DOLLAR:
1343  case DB_CURRENCY_YEN:
1344  case DB_CURRENCY_WON:
1345  case DB_CURRENCY_TL:
1346  case DB_CURRENCY_BRITISH_POUND:
1347  case DB_CURRENCY_CAMBODIAN_RIEL:
1348  case DB_CURRENCY_CHINESE_RENMINBI:
1349  case DB_CURRENCY_INDIAN_RUPEE:
1350  case DB_CURRENCY_RUSSIAN_RUBLE:
1351  case DB_CURRENCY_AUSTRALIAN_DOLLAR:
1352  case DB_CURRENCY_CANADIAN_DOLLAR:
1353  case DB_CURRENCY_BRASILIAN_REAL:
1354  case DB_CURRENCY_ROMANIAN_LEU:
1355  case DB_CURRENCY_EURO:
1356  case DB_CURRENCY_SWISS_FRANC:
1357  case DB_CURRENCY_DANISH_KRONE:
1358  case DB_CURRENCY_NORWEGIAN_KRONE:
1359  case DB_CURRENCY_BULGARIAN_LEV:
1360  case DB_CURRENCY_VIETNAMESE_DONG:
1361  case DB_CURRENCY_CZECH_KORUNA:
1362  case DB_CURRENCY_POLISH_ZLOTY:
1363  case DB_CURRENCY_SWEDISH_KRONA:
1364  case DB_CURRENCY_CROATIAN_KUNA:
1365  case DB_CURRENCY_SERBIAN_DINAR:
1366  error = NO_ERROR; /* it's a type we expect */
1367  break;
1368  default:
1369  break;
1370  }
1371 
1372  if (error != NO_ERROR)
1373  {
1374  er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, error, 1, type);
1375  return error;
1376  }
1377 
1378  value->domain.general_info.type = DB_TYPE_MONETARY;
1379  value->data.money.type = type;
1380  value->data.money.amount = amount;
1381  value->domain.general_info.is_null = 0;
1382  value->need_clear = false;
1383 
1384  return error;
1385 }
1386 
1387 /*
1388  * db_make_pointer() -
1389  * return :
1390  * value(out) :
1391  * ptr(in):
1392  */
1393 int
1394 db_make_pointer (DB_VALUE * value, void *ptr)
1395 {
1396 #if defined (API_ACTIVE_CHECKS)
1397  CHECK_1ARG_ERROR (value);
1398 #endif
1399 
1400  value->domain.general_info.type = DB_TYPE_POINTER;
1401  value->data.p = ptr;
1402  if (ptr)
1403  {
1404  value->domain.general_info.is_null = 0;
1405  }
1406  else
1407  {
1408  value->domain.general_info.is_null = 1;
1409  }
1410  value->need_clear = false;
1411 
1412  return NO_ERROR;
1413 }
1414 
1415 /*
1416  * db_make_error() -
1417  * return :
1418  * value(out):
1419  * errcode(in):
1420  */
1421 int
1422 db_make_error (DB_VALUE * value, const int errcode)
1423 {
1424 #if defined (API_ACTIVE_CHECKS)
1425  CHECK_1ARG_ERROR (value);
1426 #endif
1427 
1428  assert (errcode != NO_ERROR);
1429 
1430  value->domain.general_info.type = DB_TYPE_ERROR;
1431  value->data.error = errcode;
1432  value->domain.general_info.is_null = 0;
1433  value->need_clear = false;
1434 
1435  return NO_ERROR;
1436 }
1437 
1438 /*
1439  * db_make_method_error() -
1440  * return :
1441  * value(out):
1442  * errcode(in):
1443  * errmsg(in);
1444  */
1445 int
1446 db_make_method_error (DB_VALUE * value, const int errcode, const char *errmsg)
1447 {
1448 #if defined (API_ACTIVE_CHECKS)
1449  CHECK_1ARG_ERROR (value);
1450 #endif
1451 
1452  value->domain.general_info.type = DB_TYPE_ERROR;
1453  value->data.error = errcode;
1454  value->domain.general_info.is_null = 0;
1455  value->need_clear = false;
1456 
1457 #if !defined(SERVER_MODE)
1458  if (obj_Method_error_msg)
1459  {
1460  free (obj_Method_error_msg); /* free old last error */
1461  }
1462  obj_Method_error_msg = NULL;
1463  if (errmsg)
1464  {
1465  obj_Method_error_msg = strdup (errmsg);
1466  }
1467 #endif
1468 
1469  return NO_ERROR;
1470 }
1471 
1472 /*
1473  * db_make_short() -
1474  * return :
1475  * value(out) :
1476  * num(in) :
1477  */
1478 int
1479 db_make_short (DB_VALUE * value, const short num)
1480 {
1481 #if defined (API_ACTIVE_CHECKS)
1482  CHECK_1ARG_ERROR (value);
1483 #endif
1484 
1485  value->domain.general_info.type = DB_TYPE_SHORT;
1486  value->data.sh = num;
1487  value->domain.general_info.is_null = 0;
1488  value->need_clear = false;
1489 
1490  return NO_ERROR;
1491 }
1492 
1493 /*
1494  * db_make_bigint() -
1495  * return :
1496  * value(out) :
1497  * num(in) :
1498  */
1499 int
1500 db_make_bigint (DB_VALUE * value, const DB_BIGINT num)
1501 {
1502 #if defined (API_ACTIVE_CHECKS)
1503  CHECK_1ARG_ERROR (value);
1504 #endif
1505 
1506  value->domain.general_info.type = DB_TYPE_BIGINT;
1507  value->data.bigint = num;
1508  value->domain.general_info.is_null = 0;
1509  value->need_clear = false;
1510 
1511  return NO_ERROR;
1512 }
1513 
1514 /*
1515  * db_make_numeric() -
1516  * return :
1517  * value(out) :
1518  * num(in):
1519  * precision(in):
1520  * scale(in):
1521  */
1522 int
1523 db_make_numeric (DB_VALUE * value, const DB_C_NUMERIC num, const int precision, const int scale)
1524 {
1525  int error = NO_ERROR;
1526 
1527 #if defined (API_ACTIVE_CHECKS)
1528  CHECK_1ARG_ERROR (value);
1529 #endif
1530 
1531  error = db_value_domain_init (value, DB_TYPE_NUMERIC, precision, scale);
1532  if (error != NO_ERROR)
1533  {
1534  return error;
1535  }
1536 
1537  if (num)
1538  {
1539  value->domain.general_info.is_null = 0;
1540  memcpy (value->data.num.d.buf, num, DB_NUMERIC_BUF_SIZE);
1541  }
1542  else
1543  {
1544  value->domain.general_info.is_null = 1;
1545  }
1546  return error;
1547 }
1548 
1549 /*
1550  * db_make_bit() -
1551  * return :
1552  * value(out) :
1553  * bit_length(in):
1554  * bit_str(in):
1555  * bit_str_bit_size(in):
1556  */
1557 int
1558 db_make_bit (DB_VALUE * value, const int bit_length, DB_CONST_C_BIT bit_str, const int bit_str_bit_size)
1559 {
1560  int error;
1561 
1562 #if defined (API_ACTIVE_CHECKS)
1563  CHECK_1ARG_ERROR (value);
1564 #endif
1565 
1566  error = db_value_domain_init (value, DB_TYPE_BIT, bit_length, 0);
1567  if (error != NO_ERROR)
1568  {
1569  return error;
1570  }
1571 
1572  error = db_make_db_char (value, INTL_CODESET_RAW_BITS, 0, bit_str, bit_str_bit_size);
1573  return error;
1574 }
1575 
1576 /*
1577  * db_make_varbit() -
1578  * return :
1579  * value(out) :
1580  * max_bit_length(in):
1581  * bit_str(in):
1582  * bit_str_bit_size(in):
1583  */
1584 int
1585 db_make_varbit (DB_VALUE * value, const int max_bit_length, DB_CONST_C_BIT bit_str, const int bit_str_bit_size)
1586 {
1587  int error;
1588 
1589 #if defined (API_ACTIVE_CHECKS)
1590  CHECK_1ARG_ERROR (value);
1591 #endif
1592 
1593  error = db_value_domain_init (value, DB_TYPE_VARBIT, max_bit_length, 0);
1594  if (error != NO_ERROR)
1595  {
1596  return error;
1597  }
1598 
1599  error = db_make_db_char (value, INTL_CODESET_RAW_BITS, 0, bit_str, bit_str_bit_size);
1600 
1601  return error;
1602 }
1603 
1604 /*
1605  * db_make_char() -
1606  * return :
1607  * value(out) :
1608  * char_length(in):
1609  * str(in):
1610  * char_str_byte_size(in):
1611  */
1612 int
1613 db_make_char (DB_VALUE * value, const int char_length, DB_CONST_C_CHAR str, const int char_str_byte_size,
1614  const int codeset, const int collation_id)
1615 {
1616  int error;
1617 
1618 #if defined (API_ACTIVE_CHECKS)
1619  CHECK_1ARG_ERROR (value);
1620 #endif
1621 
1622  error = db_value_domain_init (value, DB_TYPE_CHAR, char_length, 0);
1623  if (error == NO_ERROR)
1624  {
1625  error = db_make_db_char (value, (INTL_CODESET) codeset, collation_id, str, char_str_byte_size);
1626  }
1627 
1628  return error;
1629 }
1630 
1631 /*
1632  * db_make_varchar() -
1633  * return :
1634  * value(out) :
1635  * max_char_length(in):
1636  * str(in):
1637  * char_str_byte_size(in):
1638  */
1639 int
1640 db_make_varchar (DB_VALUE * value, const int max_char_length, DB_CONST_C_CHAR str, const int char_str_byte_size,
1641  const int codeset, const int collation_id)
1642 {
1643  int error;
1644 
1645 #if defined (API_ACTIVE_CHECKS)
1646  CHECK_1ARG_ERROR (value);
1647 #endif
1648 
1649  error = db_value_domain_init (value, DB_TYPE_VARCHAR, max_char_length, 0);
1650  if (error == NO_ERROR)
1651  {
1652  error = db_make_db_char (value, (INTL_CODESET) codeset, collation_id, str, char_str_byte_size);
1653  }
1654 
1655  return error;
1656 }
1657 
1658 /*
1659  * db_make_nchar() -
1660  * return :
1661  * value(out) :
1662  * nchar_length(in):
1663  * str(in):
1664  * nchar_str_byte_size(in):
1665  */
1666 int
1667 db_make_nchar (DB_VALUE * value, const int nchar_length, DB_CONST_C_NCHAR str, const int nchar_str_byte_size,
1668  const int codeset, const int collation_id)
1669 {
1670  int error;
1671 
1672 #if defined (API_ACTIVE_CHECKS)
1673  CHECK_1ARG_ERROR (value);
1674 #endif
1675 
1676  error = db_value_domain_init (value, DB_TYPE_NCHAR, nchar_length, 0);
1677  if (error == NO_ERROR)
1678  {
1679  error = db_make_db_char (value, (INTL_CODESET) codeset, collation_id, str, nchar_str_byte_size);
1680  }
1681 
1682  return error;
1683 }
1684 
1685 /*
1686  * db_make_varnchar() -
1687  * return :
1688  * value(out) :
1689  * max_nchar_length(in):
1690  * str(in):
1691  * nchar_str_byte_size(in):
1692  */
1693 int
1694 db_make_varnchar (DB_VALUE * value, const int max_nchar_length, DB_CONST_C_NCHAR str, const int nchar_str_byte_size,
1695  const int codeset, const int collation_id)
1696 {
1697  int error;
1698 
1699 #if defined (API_ACTIVE_CHECKS)
1700  CHECK_1ARG_ERROR (value);
1701 #endif
1702 
1703  error = db_value_domain_init (value, DB_TYPE_VARNCHAR, max_nchar_length, 0);
1704  if (error == NO_ERROR)
1705  {
1706  error = db_make_db_char (value, (INTL_CODESET) codeset, collation_id, str, nchar_str_byte_size);
1707  }
1708 
1709  return error;
1710 }
1711 
1712 /*
1713  * db_make_enumeration() -
1714  * return :
1715  * value(out):
1716  * index(in):
1717  * str(in):
1718  * size(in):
1719  * codeset(in):
1720  * collation_id(in):
1721  */
1722 int
1723 db_make_enumeration (DB_VALUE * value, unsigned short index, DB_CONST_C_CHAR str, int size, unsigned char codeset,
1724  const int collation_id)
1725 {
1726 #if defined (API_ACTIVE_CHECKS)
1727  CHECK_1ARG_ERROR (value);
1728 #endif
1729 
1730  value->domain.general_info.type = DB_TYPE_ENUMERATION;
1731  value->data.enumeration.short_val = index;
1732  value->data.enumeration.str_val.info.codeset = codeset;
1733  value->domain.char_info.collation_id = collation_id;
1734  value->data.enumeration.str_val.info.style = MEDIUM_STRING;
1735  value->data.ch.info.is_max_string = false;
1736  value->data.ch.info.compressed_need_clear = false;
1737  value->data.ch.medium.compressed_buf = NULL;
1738  value->data.ch.medium.compressed_size = 0;
1739  value->data.enumeration.str_val.medium.size = size;
1740  value->data.enumeration.str_val.medium.buf = str;
1741  value->domain.general_info.is_null = 0;
1742  value->need_clear = false;
1743 
1744  return NO_ERROR;
1745 }
1746 
1747 /*
1748  * db_make_resultset() -
1749  * return :
1750  * value(out):
1751  * handle(in):
1752  */
1753 int
1754 db_make_resultset (DB_VALUE * value, const DB_RESULTSET handle)
1755 {
1756 #if defined (API_ACTIVE_CHECKS)
1757  CHECK_1ARG_ERROR (value);
1758 #endif
1759 
1760  value->domain.general_info.type = DB_TYPE_RESULTSET;
1761  value->data.rset = handle;
1762  value->domain.general_info.is_null = 0;
1763  value->need_clear = false;
1764 
1765  return NO_ERROR;
1766 }
1767 
1768 /*
1769  * db_make_oid() -
1770  * return :
1771  * value(out):
1772  * oid(in):
1773  */
1774 int
1775 db_make_oid (DB_VALUE * value, const OID * oid)
1776 {
1777 #if defined (API_ACTIVE_CHECKS)
1778  CHECK_2ARGS_ERROR (value, oid);
1779 #endif
1780 
1781  if (oid == NULL)
1782  {
1783  value->domain.general_info.is_null = 1;
1784  return NO_ERROR;
1785  }
1786 
1787  value->domain.general_info.type = DB_TYPE_OID;
1788  value->data.oid.pageid = oid->pageid;
1789  value->data.oid.slotid = oid->slotid;
1790  value->data.oid.volid = oid->volid;
1791  value->domain.general_info.is_null = OID_ISNULL (oid);
1792  value->need_clear = false;
1793 
1794  return NO_ERROR;
1795 }
1796 
1797 /*
1798  * db_make_string() -
1799  * return :
1800  * value(out) :
1801  * str(in):
1802  */
1803 int
1804 db_make_string (DB_VALUE * value, DB_CONST_C_CHAR str)
1805 {
1806  int error;
1807  int size;
1808 
1809 #if defined (API_ACTIVE_CHECKS)
1810  CHECK_1ARG_ERROR (value);
1811 #endif
1812 
1813  error = db_value_domain_init (value, DB_TYPE_VARCHAR, TP_FLOATING_PRECISION_VALUE, 0);
1814  if (error == NO_ERROR)
1815  {
1816  if (str)
1817  {
1818  size = (int) strlen (str);
1819  }
1820  else
1821  {
1822  size = 0;
1823  }
1824  error = db_make_db_char (value, LANG_SYS_CODESET, LANG_SYS_COLLATION, str, size);
1825  }
1826  return error;
1827 }
1828 
1829 /*
1830  * db_make_string_copy() - alloc buffer and copy str into the buffer.
1831  * need_clear will set as true.
1832  * return :
1833  * value(out) :
1834  * str(in):
1835  */
1836 int
1837 db_make_string_copy (DB_VALUE * value, DB_CONST_C_CHAR str)
1838 {
1839  int error;
1840  char *copy_str;
1841 
1842 #if defined (API_ACTIVE_CHECKS)
1843  CHECK_1ARG_ERROR (value);
1844 #endif
1845 
1846  if (str == NULL)
1847  {
1848  db_make_null (value);
1849  return NO_ERROR;
1850  }
1851 
1852  copy_str = db_private_strdup (NULL, str);
1853 
1854  if (copy_str == NULL)
1855  {
1856  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, strlen (str) + 1);
1857  return ER_OUT_OF_VIRTUAL_MEMORY;
1858  }
1859 
1860  error = db_make_string (value, copy_str);
1861 
1862  if (error != NO_ERROR)
1863  {
1864  db_private_free (NULL, copy_str);
1865  return error;
1866  }
1867 
1868  /* Set need_clear to true. */
1869  value->need_clear = true;
1870 
1871  return error;
1872 }
1873 
1874 /*
1875  * db_make_set() -
1876  * return :
1877  * value(out) :
1878  * set(in):
1879  */
1880 int
1881 db_make_set (DB_VALUE * value, DB_SET * set)
1882 {
1883  int error = NO_ERROR;
1884 
1885 #if defined (API_ACTIVE_CHECKS)
1886  CHECK_1ARG_ERROR (value);
1887 #endif
1888 
1889  value->domain.general_info.type = DB_TYPE_SET;
1890  value->data.set = set;
1891  if (set)
1892  {
1893  if ((set->set && setobj_type (set->set) == DB_TYPE_SET) || set->disk_set)
1894  {
1895  value->domain.general_info.is_null = 0;
1896  }
1897  else
1898  {
1899  error = ER_QPROC_INVALID_DATATYPE;
1900  er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_QPROC_INVALID_DATATYPE, 0);
1901  }
1902  }
1903  else
1904  {
1905  value->domain.general_info.is_null = 1;
1906  }
1907 
1908  value->need_clear = false;
1909 
1910  return error;
1911 }
1912 
1913 /*
1914  * db_make_multiset() -
1915  * return :
1916  * value(out) :
1917  * set(in):
1918  */
1919 int
1920 db_make_multiset (DB_VALUE * value, DB_SET * set)
1921 {
1922  int error = NO_ERROR;
1923 
1924 #if defined (API_ACTIVE_CHECKS)
1925  CHECK_1ARG_ERROR (value);
1926 #endif
1927 
1928  value->domain.general_info.type = DB_TYPE_MULTISET;
1929  value->data.set = set;
1930  if (set)
1931  {
1932  if ((set->set && setobj_type (set->set) == DB_TYPE_MULTISET) || set->disk_set)
1933  {
1934  value->domain.general_info.is_null = 0;
1935  }
1936  else
1937  {
1938  error = ER_QPROC_INVALID_DATATYPE;
1939  er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_QPROC_INVALID_DATATYPE, 0);
1940  }
1941  }
1942  else
1943  {
1944  value->domain.general_info.is_null = 1;
1945  }
1946 
1947  value->need_clear = false;
1948 
1949  return error;
1950 }
1951 
1952 /*
1953  * db_make_sequence() -
1954  * return :
1955  * value(out) :
1956  * set(in):
1957  */
1958 int
1959 db_make_sequence (DB_VALUE * value, DB_SET * set)
1960 {
1961  int error = NO_ERROR;
1962 
1963 #if defined (API_ACTIVE_CHECKS)
1964  CHECK_1ARG_ERROR (value);
1965 #endif
1966 
1967  value->domain.general_info.type = DB_TYPE_SEQUENCE;
1968  value->data.set = set;
1969  if (set)
1970  {
1971  if ((set->set && setobj_type (set->set) == DB_TYPE_SEQUENCE) || set->disk_set)
1972  {
1973  value->domain.general_info.is_null = 0;
1974  }
1975  else
1976  {
1977  error = ER_QPROC_INVALID_DATATYPE;
1978  er_set (ER_WARNING_SEVERITY, ARG_FILE_LINE, ER_QPROC_INVALID_DATATYPE, 0);
1979  }
1980  }
1981  else
1982  {
1983  value->domain.general_info.is_null = 1;
1984  }
1985 
1986  value->need_clear = false;
1987 
1988  return error;
1989 }
1990 
1991 /*
1992  * db_make_collection() -
1993  * return :
1994  * value(out) :
1995  * col(in):
1996  */
1997 int
1998 db_make_collection (DB_VALUE * value, DB_COLLECTION * col)
1999 {
2000  int error = NO_ERROR;
2001 
2002 #if defined (API_ACTIVE_CHECKS)
2003  CHECK_1ARG_ERROR (value);
2004 #endif
2005 
2006  /* Rather than being DB_TYPE_COLLECTION, the value type is taken from the base type of the collection. */
2007  if (col == NULL)
2008  {
2009  value->domain.general_info.type = DB_TYPE_SEQUENCE; /* undefined */
2010  value->data.set = NULL;
2011  value->domain.general_info.is_null = 1;
2012  }
2013  else
2014  {
2015  value->domain.general_info.type = db_col_type (col);
2016  value->data.set = col;
2017  /* note, we have been testing set->set for non-NULL here in order to set the is_null flag, this isn't
2018  * appropriate, the set pointer can be NULL if the set has been swapped out.The existance of a set handle alone
2019  * determines the nullness of the value. Actually, the act of calling db_col_type above will have resulted in a
2020  * re-fetch of the referenced set if it had been swapped out. */
2021  value->domain.general_info.is_null = 0;
2022  }
2023  value->need_clear = false;
2024 
2025  return error;
2026 }
2027 
2028 /*
2029  * db_make_elo () -
2030  * return:
2031  * value(out):
2032  * type(in):
2033  * elo(in):`
2034  */
2035 int
2036 db_make_elo (DB_VALUE * value, DB_TYPE type, const DB_ELO * elo)
2037 {
2038 #if defined (API_ACTIVE_CHECKS)
2039  CHECK_1ARG_ERROR (value);
2040 #endif
2041 
2042  value->domain.general_info.type = type;
2043  if (elo == NULL || elo->size < 0 || elo->type == ELO_NULL)
2044  {
2045  elo_init_structure (&value->data.elo);
2046  value->domain.general_info.is_null = 1;
2047  }
2048  else
2049  {
2050  value->data.elo = *elo;
2051  value->domain.general_info.is_null = 0;
2052  }
2053  value->need_clear = false;
2054 
2055  return NO_ERROR;
2056 }
2057 
2058 /*
2059  * db_make_time() -
2060  * return :
2061  * value(out) :
2062  * hour(in):
2063  * min(in):
2064  * sec(in):
2065  */
2066 int
2067 db_make_time (DB_VALUE * value, const int hour, const int min, const int sec)
2068 {
2069 #if defined (API_ACTIVE_CHECKS)
2070  CHECK_1ARG_ERROR (value);
2071 #endif
2072 
2073  value->domain.general_info.type = DB_TYPE_TIME;
2074  value->domain.general_info.is_null = 0;
2075  value->need_clear = false;
2076  return db_time_encode (&value->data.time, hour, min, sec);
2077 }
2078 
2079 /*
2080  * db_make_date() -
2081  * return :
2082  * value(out):
2083  * mon(in):
2084  * day(in):
2085  * year(in):
2086  */
2087 int
2088 db_make_date (DB_VALUE * value, const int mon, const int day, const int year)
2089 {
2090 #if defined (API_ACTIVE_CHECKS)
2091  CHECK_1ARG_ERROR (value);
2092 #endif
2093 
2094  value->domain.general_info.type = DB_TYPE_DATE;
2095  value->domain.general_info.is_null = 0;
2096  value->need_clear = false;
2097  return db_date_encode (&value->data.date, mon, day, year);
2098 }
2099 
2100 int
2101 db_make_json (DB_VALUE * value, JSON_DOC * json_document, bool need_clear)
2102 {
2103 #if defined (API_ACTIVE_CHECKS)
2104  CHECK_1ARG_ERROR (value);
2105 #else
2106  if (value == NULL)
2107  {
2108  /* todo: Should this happen? */
2109  assert (false);
2110  return ER_FAILED;
2111  }
2112 #endif
2113 
2114  value->domain.general_info.type = DB_TYPE_JSON;
2115  value->domain.general_info.is_null = 0;
2116  value->data.json.document = json_document;
2117  value->data.json.schema_raw = NULL;
2118  value->need_clear = need_clear;
2119 
2120  return NO_ERROR;
2121 }
2122 
2123 int
2124 db_get_compressed_size (DB_VALUE * value)
2125 {
2126  DB_TYPE type;
2127 
2128  if (value == NULL || DB_IS_NULL (value))
2129  {
2130  return 0;
2131  }
2132 
2133  type = DB_VALUE_DOMAIN_TYPE (value);
2134 
2135  /* Preliminary check */
2136  assert (type == DB_TYPE_VARCHAR || type == DB_TYPE_VARNCHAR);
2137 
2138  return value->data.ch.medium.compressed_size;
2139 }
2140 
2141 /*
2142  * db_set_compressed_string() - Sets the compressed string, its size and its need for clear in the DB_VALUE
2143  *
2144  * value(in/out) : The DB_VALUE
2145  * compressed_string(in) :
2146  * compressed_size(in) :
2147  * compressed_need_clear(in) :
2148  */
2149 void
2150 db_set_compressed_string (DB_VALUE * value, char *compressed_string, int compressed_size, bool compressed_need_clear)
2151 {
2152  DB_TYPE type;
2153 
2154  if (value == NULL || DB_IS_NULL (value))
2155  {
2156  return;
2157  }
2158  type = DB_VALUE_DOMAIN_TYPE (value);
2159 
2160  /* Preliminary check */
2161  assert (type == DB_TYPE_VARCHAR || type == DB_TYPE_VARNCHAR);
2162 
2163  value->data.ch.medium.compressed_buf = compressed_string;
2164  value->data.ch.medium.compressed_size = compressed_size;
2165  value->data.ch.info.compressed_need_clear = compressed_need_clear;
2166 }
2167 
2168 /*
2169  * db_value_is_null() -
2170  * return :
2171  * value(in) :
2172  */
2173 bool
2174 db_value_is_null (const DB_VALUE * value)
2175 {
2176 #if defined (API_ACTIVE_CHECKS)
2177  CHECK_1ARG_TRUE (value);
2178 #endif
2179 
2180  if (value == NULL)
2181  {
2182  return true;
2183  }
2184 
2185  return (value->domain.general_info.is_null != 0);
2186 }
2187 
2188 /*
2189  * db_value_domain_type() - get the type of value's domain.
2190  * return : DB_TYPE of value's domain
2191  * value(in) : Pointer to a DB_VALUE
2192  */
2193 DB_TYPE
2194 db_value_domain_type (const DB_VALUE * value)
2195 {
2196 #if defined (API_ACTIVE_CHECKS)
2197  CHECK_1ARG_UNKNOWN (value);
2198 #else
2199 
2200  if (value == NULL)
2201  {
2202  // todo: does this ever happen?
2203  assert (false);
2204  return DB_TYPE_UNKNOWN;
2205  }
2206 #endif
2207 
2208  return (DB_TYPE) value->domain.general_info.type;
2209 }