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-11-14 20:04:02 Functions: 145 275 52.7 %

          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        1541 : FUN(do_,TP1,_dec2dec_,TP2) (TP2 *restrict res, int s1, TP1 val, int p, int s2)
      15             : {
      16        1541 :         ValRecord v1, v2;
      17             : 
      18        1541 :         VALset(&v1, TPE(TP1), &val);
      19        1541 :         v2.bat = false;
      20        1541 :         v2.vtype = TPE(TP2);
      21        1541 :         if (VARconvert(&v2, &v1, s1, s2, p) != GDK_SUCCEED)
      22          16 :                 throw(SQL, STRNG(FUN(,TP1,_2_,TP2)), GDK_EXCEPTION);
      23        1525 :         *res = *(TP2 *) VALptr(&v2);
      24        1525 :         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         866 : FUN(,TP1,_dec2dec_,TP2) (TP2 *res, const int *S1, const TP1 *v, const int *d2, const int *S2)
      36             : {
      37         866 :         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         690 : FUN(bat,TP1,_dec2dec_,TP2) (bat *res, const int *S1, const bat *bid, const bat *sid, const int *d2, const int *S2)
      72             : {
      73         690 :         BAT *b, *s = NULL, *bn;
      74             : 
      75         690 :         if ((b = BATdescriptor(*bid)) == NULL) {
      76           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      77             :         }
      78         690 :         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         690 :         bn = BATconvert(b, s, TPE(TP2), *S1, *S2, *d2);
      83         690 :         BBPunfix(b->batCacheid);
      84         690 :         BBPreclaim(s);
      85         690 :         if (bn == NULL)
      86           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_dec2dec_,TP2)), GDK_EXCEPTION);
      87             : 
      88         690 :         *res = bn->batCacheid;
      89         690 :         BBPkeepref(bn);
      90         690 :         return MAL_SUCCEED;
      91             : }
      92             : #endif
      93             : 
      94             : str
      95         713 : FUN(bat,TP1,_num2dec_,TP2) (bat *res, const bat *bid, const bat *sid, const int *d2, const int *s2)
      96             : {
      97         713 :         BAT *b, *s = NULL, *bn;
      98             : 
      99         713 :         if ((b = BATdescriptor(*bid)) == NULL) {
     100           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_num2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     101             :         }
     102         713 :         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         713 :         bn = BATconvert(b, s, TPE(TP2), 0, *s2, *d2);
     107         713 :         BBPunfix(b->batCacheid);
     108         713 :         BBPreclaim(s);
     109         713 :         if (bn == NULL)
     110           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_num2dec_,TP2)), GDK_EXCEPTION);
     111         713 :         *res = bn->batCacheid;
     112         713 :         BBPkeepref(bn);
     113         713 :         return MAL_SUCCEED;
     114             : }

Generated by: LCOV version 1.14