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: 48 59 81.4 %
Date: 2024-04-25 20:03:45 Functions: 131 275 47.6 %

          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        1446 : FUN(do_,TP1,_dec2dec_,TP2) (TP2 *restrict res, int s1, TP1 val, int p, int s2)
      15             : {
      16        1446 :         ValRecord v1, v2;
      17             : 
      18        1446 :         VALset(&v1, TPE(TP1), &val);
      19        1446 :         v2.vtype = TPE(TP2);
      20        1446 :         if (VARconvert(&v2, &v1, s1, s2, p) != GDK_SUCCEED)
      21          15 :                 throw(SQL, STRNG(FUN(,TP1,_2_,TP2)), GDK_EXCEPTION);
      22        1431 :         *res = *(TP2 *) VALptr(&v2);
      23        1431 :         return MAL_SUCCEED;
      24             : }
      25             : 
      26             : #if IS_NUMERIC(TP1)
      27             : str
      28         203 : FUN(,TP1,_dec2_,TP2) (TP2 *res, const int *s1, const TP1 *v)
      29             : {
      30         203 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *s1, *v, 0, 0);
      31             : }
      32             : 
      33             : str
      34         706 : FUN(,TP1,_dec2dec_,TP2) (TP2 *res, const int *S1, const TP1 *v, const int *d2, const int *S2)
      35             : {
      36         706 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *S1, *v, *d2, *S2);
      37             : }
      38             : #endif
      39             : 
      40             : str
      41         537 : FUN(,TP1,_num2dec_,TP2) (TP2 *res, const TP1 *v, const int *d2, const int *s2)
      42             : {
      43         537 :         return FUN(do_,TP1,_dec2dec_,TP2)(res, 0, *v, *d2, *s2);
      44             : }
      45             : 
      46             : #if IS_NUMERIC(TP1)
      47             : str
      48         160 : FUN(bat,TP1,_dec2_,TP2) (bat *res, const int *s1, const bat *bid, const bat *sid)
      49             : {
      50         160 :         BAT *b, *s = NULL, *bn;
      51             : 
      52         160 :         if ((b = BATdescriptor(*bid)) == NULL) {
      53           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      54             :         }
      55         160 :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
      56           0 :                 BBPunfix(b->batCacheid);
      57           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      58             :         }
      59         160 :         bn = BATconvert(b, s, TPE(TP2), *s1, 0, 0);
      60         160 :         BBPunfix(b->batCacheid);
      61         160 :         BBPreclaim(s);
      62         160 :         if (bn == NULL)
      63           1 :                 throw(SQL, "sql."STRNG(FUN(dec,TP1,_2_,TP2)), GDK_EXCEPTION);
      64         159 :         *res = bn->batCacheid;
      65         159 :         BBPkeepref(bn);
      66         159 :         return MAL_SUCCEED;
      67             : }
      68             : 
      69             : str
      70         533 : FUN(bat,TP1,_dec2dec_,TP2) (bat *res, const int *S1, const bat *bid, const bat *sid, const int *d2, const int *S2)
      71             : {
      72         533 :         BAT *b, *s = NULL, *bn;
      73             : 
      74         533 :         if ((b = BATdescriptor(*bid)) == NULL) {
      75           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      76             :         }
      77         534 :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
      78           0 :                 BBPunfix(b->batCacheid);
      79           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      80             :         }
      81         534 :         bn = BATconvert(b, s, TPE(TP2), *S1, *S2, *d2);
      82         534 :         BBPunfix(b->batCacheid);
      83         534 :         BBPreclaim(s);
      84         534 :         if (bn == NULL)
      85           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_dec2dec_,TP2)), GDK_EXCEPTION);
      86             : 
      87         534 :         *res = bn->batCacheid;
      88         534 :         BBPkeepref(bn);
      89         534 :         return MAL_SUCCEED;
      90             : }
      91             : #endif
      92             : 
      93             : str
      94         823 : FUN(bat,TP1,_num2dec_,TP2) (bat *res, const bat *bid, const bat *sid, const int *d2, const int *s2)
      95             : {
      96         823 :         BAT *b, *s = NULL, *bn;
      97             : 
      98         823 :         if ((b = BATdescriptor(*bid)) == NULL) {
      99           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_num2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     100             :         }
     101         823 :         if (sid && !is_bat_nil(*sid) && (s = BATdescriptor(*sid)) == NULL) {
     102           0 :                 BBPunfix(b->batCacheid);
     103           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     104             :         }
     105         823 :         bn = BATconvert(b, s, TPE(TP2), 0, *s2, *d2);
     106         823 :         BBPunfix(b->batCacheid);
     107         823 :         BBPreclaim(s);
     108         823 :         if (bn == NULL)
     109           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_num2dec_,TP2)), GDK_EXCEPTION);
     110         823 :         *res = bn->batCacheid;
     111         823 :         BBPkeepref(bn);
     112         823 :         return MAL_SUCCEED;
     113             : }

Generated by: LCOV version 1.14