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-10-04 20:04:04 Functions: 141 275 51.3 %

          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        1458 : FUN(do_,TP1,_dec2dec_,TP2) (TP2 *restrict res, int s1, TP1 val, int p, int s2)
      15             : {
      16        1458 :         ValRecord v1, v2;
      17             : 
      18        1458 :         VALset(&v1, TPE(TP1), &val);
      19        1458 :         v2.bat = false;
      20        1458 :         v2.vtype = TPE(TP2);
      21        1458 :         if (VARconvert(&v2, &v1, s1, s2, p) != GDK_SUCCEED)
      22          15 :                 throw(SQL, STRNG(FUN(,TP1,_2_,TP2)), GDK_EXCEPTION);
      23        1443 :         *res = *(TP2 *) VALptr(&v2);
      24        1443 :         return MAL_SUCCEED;
      25             : }
      26             : 
      27             : #if IS_NUMERIC(TP1)
      28             : str
      29         199 : FUN(,TP1,_dec2_,TP2) (TP2 *res, const int *s1, const TP1 *v)
      30             : {
      31         199 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *s1, *v, 0, 0);
      32             : }
      33             : 
      34             : str
      35         820 : FUN(,TP1,_dec2dec_,TP2) (TP2 *res, const int *S1, const TP1 *v, const int *d2, const int *S2)
      36             : {
      37         820 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *S1, *v, *d2, *S2);
      38             : }
      39             : #endif
      40             : 
      41             : str
      42         439 : FUN(,TP1,_num2dec_,TP2) (TP2 *res, const TP1 *v, const int *d2, const int *s2)
      43             : {
      44         439 :         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         615 : FUN(bat,TP1,_dec2dec_,TP2) (bat *res, const int *S1, const bat *bid, const bat *sid, const int *d2, const int *S2)
      72             : {
      73         615 :         BAT *b, *s = NULL, *bn;
      74             : 
      75         615 :         if ((b = BATdescriptor(*bid)) == NULL) {
      76           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      77             :         }
      78         615 :         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         615 :         bn = BATconvert(b, s, TPE(TP2), *S1, *S2, *d2);
      83         615 :         BBPunfix(b->batCacheid);
      84         615 :         BBPreclaim(s);
      85         615 :         if (bn == NULL)
      86           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_dec2dec_,TP2)), GDK_EXCEPTION);
      87             : 
      88         615 :         *res = bn->batCacheid;
      89         615 :         BBPkeepref(bn);
      90         615 :         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