LCOV - code coverage report
Current view: top level - sql/backends/monet5 - sql_cast_impl_int.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 49 60 81.7 %
Date: 2024-12-19 20:05:57 Functions: 143 275 52.0 %

          Line data    Source code
       1             : /*
       2             :  * SPDX-License-Identifier: MPL-2.0
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * Copyright 2024 MonetDB Foundation;
       9             :  * Copyright August 2008 - 2023 MonetDB B.V.;
      10             :  * Copyright 1997 - July 2008 CWI.
      11             :  */
      12             : 
      13             : static inline str
      14        1465 : FUN(do_,TP1,_dec2dec_,TP2) (TP2 *restrict res, int s1, TP1 val, int p, int s2)
      15             : {
      16        1465 :         ValRecord v1, v2;
      17             : 
      18        1465 :         VALset(&v1, TPE(TP1), &val);
      19        1465 :         v2.bat = false;
      20        1465 :         v2.vtype = TPE(TP2);
      21        1465 :         if (VARconvert(&v2, &v1, s1, s2, p) != GDK_SUCCEED)
      22          15 :                 throw(SQL, STRNG(FUN(,TP1,_2_,TP2)), GDK_EXCEPTION);
      23        1450 :         *res = *(TP2 *) VALptr(&v2);
      24        1450 :         return MAL_SUCCEED;
      25             : }
      26             : 
      27             : #if IS_NUMERIC(TP1)
      28             : str
      29         197 : FUN(,TP1,_dec2_,TP2) (TP2 *res, const int *s1, const TP1 *v)
      30             : {
      31         197 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *s1, *v, 0, 0);
      32             : }
      33             : 
      34             : str
      35         792 : FUN(,TP1,_dec2dec_,TP2) (TP2 *res, const int *S1, const TP1 *v, const int *d2, const int *S2)
      36             : {
      37         792 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *S1, *v, *d2, *S2);
      38             : }
      39             : #endif
      40             : 
      41             : str
      42         476 : FUN(,TP1,_num2dec_,TP2) (TP2 *res, const TP1 *v, const int *d2, const int *s2)
      43             : {
      44         476 :         return FUN(do_,TP1,_dec2dec_,TP2)(res, 0, *v, *d2, *s2);
      45             : }
      46             : 
      47             : #if IS_NUMERIC(TP1)
      48             : str
      49         165 : FUN(bat,TP1,_dec2_,TP2) (bat *res, const int *s1, const bat *bid, const bat *sid)
      50             : {
      51         165 :         BAT *b, *s = NULL, *bn;
      52             : 
      53         165 :         if ((b = BATdescriptor(*bid)) == NULL) {
      54           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      55             :         }
      56         165 :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
      57           0 :                 BBPunfix(b->batCacheid);
      58           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      59             :         }
      60         165 :         bn = BATconvert(b, s, TPE(TP2), *s1, 0, 0);
      61         165 :         BBPunfix(b->batCacheid);
      62         165 :         BBPreclaim(s);
      63         165 :         if (bn == NULL)
      64           1 :                 throw(SQL, "sql."STRNG(FUN(dec,TP1,_2_,TP2)), GDK_EXCEPTION);
      65         164 :         *res = bn->batCacheid;
      66         164 :         BBPkeepref(bn);
      67         164 :         return MAL_SUCCEED;
      68             : }
      69             : 
      70             : str
      71         630 : FUN(bat,TP1,_dec2dec_,TP2) (bat *res, const int *S1, const bat *bid, const bat *sid, const int *d2, const int *S2)
      72             : {
      73         630 :         BAT *b, *s = NULL, *bn;
      74             : 
      75         630 :         if ((b = BATdescriptor(*bid)) == NULL) {
      76           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      77             :         }
      78         630 :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
      79           0 :                 BBPunfix(b->batCacheid);
      80           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      81             :         }
      82         630 :         bn = BATconvert(b, s, TPE(TP2), *S1, *S2, *d2);
      83         630 :         BBPunfix(b->batCacheid);
      84         630 :         BBPreclaim(s);
      85         630 :         if (bn == NULL)
      86           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_dec2dec_,TP2)), GDK_EXCEPTION);
      87             : 
      88         630 :         *res = bn->batCacheid;
      89         630 :         BBPkeepref(bn);
      90         630 :         return MAL_SUCCEED;
      91             : }
      92             : #endif
      93             : 
      94             : str
      95         701 : FUN(bat,TP1,_num2dec_,TP2) (bat *res, const bat *bid, const bat *sid, const int *d2, const int *s2)
      96             : {
      97         701 :         BAT *b, *s = NULL, *bn;
      98             : 
      99         701 :         if ((b = BATdescriptor(*bid)) == NULL) {
     100           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_num2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     101             :         }
     102         701 :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
     103           0 :                 BBPunfix(b->batCacheid);
     104           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     105             :         }
     106         701 :         bn = BATconvert(b, s, TPE(TP2), 0, *s2, *d2);
     107         701 :         BBPunfix(b->batCacheid);
     108         701 :         BBPreclaim(s);
     109         701 :         if (bn == NULL)
     110           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_num2dec_,TP2)), GDK_EXCEPTION);
     111         701 :         *res = bn->batCacheid;
     112         701 :         BBPkeepref(bn);
     113         701 :         return MAL_SUCCEED;
     114             : }

Generated by: LCOV version 1.14