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-04-26 00:35:57 Functions: 142 275 51.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        1406 : FUN(do_,TP1,_dec2dec_,TP2) (TP2 *restrict res, int s1, TP1 val, int p, int s2)
      15             : {
      16        1406 :         ValRecord v1, v2;
      17             : 
      18        1406 :         VALset(&v1, TPE(TP1), &val);
      19        1406 :         v2.bat = false;
      20        1406 :         v2.vtype = TPE(TP2);
      21        1406 :         if (VARconvert(&v2, &v1, s1, s2, p) != GDK_SUCCEED)
      22          15 :                 throw(SQL, STRNG(FUN(,TP1,_2_,TP2)), GDK_EXCEPTION);
      23        1391 :         *res = *(TP2 *) VALptr(&v2);
      24        1391 :         return MAL_SUCCEED;
      25             : }
      26             : 
      27             : #if IS_NUMERIC(TP1)
      28             : str
      29         190 : FUN(,TP1,_dec2_,TP2) (TP2 *res, const int *s1, const TP1 *v)
      30             : {
      31         190 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *s1, *v, 0, 0);
      32             : }
      33             : 
      34             : str
      35         757 : FUN(,TP1,_dec2dec_,TP2) (TP2 *res, const int *S1, const TP1 *v, const int *d2, const int *S2)
      36             : {
      37         757 :         return FUN(do_,TP1,_dec2dec_,TP2) (res, *S1, *v, *d2, *S2);
      38             : }
      39             : #endif
      40             : 
      41             : str
      42         459 : FUN(,TP1,_num2dec_,TP2) (TP2 *res, const TP1 *v, const int *d2, const int *s2)
      43             : {
      44         459 :         return FUN(do_,TP1,_dec2dec_,TP2)(res, 0, *v, *d2, *s2);
      45             : }
      46             : 
      47             : #if IS_NUMERIC(TP1)
      48             : str
      49         175 : FUN(bat,TP1,_dec2_,TP2) (bat *res, const int *s1, const bat *bid, const bat *sid)
      50             : {
      51         175 :         BAT *b, *s = NULL, *bn;
      52             : 
      53         175 :         if ((b = BATdescriptor(*bid)) == NULL) {
      54           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      55             :         }
      56         175 :         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         175 :         bn = BATconvert(b, s, TPE(TP2), *s1, 0, 0);
      61         172 :         BBPunfix(b->batCacheid);
      62         174 :         BBPreclaim(s);
      63         174 :         if (bn == NULL)
      64           1 :                 throw(SQL, "sql."STRNG(FUN(dec,TP1,_2_,TP2)), GDK_EXCEPTION);
      65         173 :         *res = bn->batCacheid;
      66         173 :         BBPkeepref(bn);
      67         173 :         return MAL_SUCCEED;
      68             : }
      69             : 
      70             : str
      71         704 : FUN(bat,TP1,_dec2dec_,TP2) (bat *res, const int *S1, const bat *bid, const bat *sid, const int *d2, const int *S2)
      72             : {
      73         704 :         BAT *b, *s = NULL, *bn;
      74             : 
      75         704 :         if ((b = BATdescriptor(*bid)) == NULL) {
      76           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_dec2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
      77             :         }
      78         706 :         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         706 :         bn = BATconvert(b, s, TPE(TP2), *S1, *S2, *d2);
      83         703 :         BBPunfix(b->batCacheid);
      84         707 :         BBPreclaim(s);
      85         707 :         if (bn == NULL)
      86           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_dec2dec_,TP2)), GDK_EXCEPTION);
      87             : 
      88         707 :         *res = bn->batCacheid;
      89         707 :         BBPkeepref(bn);
      90         707 :         return MAL_SUCCEED;
      91             : }
      92             : #endif
      93             : 
      94             : str
      95         839 : FUN(bat,TP1,_num2dec_,TP2) (bat *res, const bat *bid, const bat *sid, const int *d2, const int *s2)
      96             : {
      97         839 :         BAT *b, *s = NULL, *bn;
      98             : 
      99         839 :         if ((b = BATdescriptor(*bid)) == NULL) {
     100           0 :                 throw(SQL, "batcalc."STRNG(FUN(,TP1,_num2dec_,TP2)), SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
     101             :         }
     102         840 :         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         840 :         bn = BATconvert(b, s, TPE(TP2), 0, *s2, *d2);
     107         836 :         BBPunfix(b->batCacheid);
     108         838 :         BBPreclaim(s);
     109         838 :         if (bn == NULL)
     110           0 :                 throw(SQL, "sql."STRNG(FUN(,TP1,_num2dec_,TP2)), GDK_EXCEPTION);
     111         838 :         *res = bn->batCacheid;
     112         838 :         BBPkeepref(bn);
     113         838 :         return MAL_SUCCEED;
     114             : }

Generated by: LCOV version 1.14