in reply to Re: Problems with values expressed in scientific notation not being returned through DBI
in thread Problems with values expressed in scientific notation not being returned through DBI

Interesting, Devel::Peek is a look into the internals of Perl that I never thought I'd need to see. Not as disturbing as watching sausage being made but some gory details about variable storage exposed with this method.

To see how nulls in the DB ('undef' as far as Perl is concerned) look when dumped, I added a fifth column (E) to the database table with a null value and added that to the query and dumped output. It seems that Dump sends its output to stderr and so I had to comingle the output streams when running this from a DOS command prompt (and then edit the result to collate the two streams). This is the result of the first case where the Single database columns containing values expressed in scientific notation (columns B & C) are returned with a "missing" value (a null byte--not quite the same as an empty string):

a=6.02518 SV = PV(0x277ae34) at 0x47d2b4 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x275664c "6.02518"\0 CUR = 7 LEN = 10 COW_REFCNT = 1 b= SV = PV(0x277ae5c) at 0x47da94 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x275672c "\0"\0 CUR = 1 LEN = 10 c= SV = PV(0x277ae54) at 0x47da34 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x27567ac "\0"\0 CUR = 1 LEN = 10 d=8.99280607700348E-2 SV = PV(0x277ae4c) at 0x47d134 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) PV = 0x28ac1bc "8.99280607700348E-2"\0 CUR = 19 LEN = 21 COW_REFCNT = 1 e= SV = PV(0x277aeac) at 0x47d1f4 REFCNT = 1 FLAGS = () PV = 0

As expected, in the second query where I added zeros to the columns (A+0, B+0, C+0, D+0, E+0) in the query, the problematic B and C columns are recast as double precision values and show up properly and look normal using Dump(). I'm not much on Perl internals and haven't needed to immerse myself in perlguts just yet so I'm hoping that something in the output above sheds some light on why Single values expressed in scientific notation cannot seem to be reliably returned with a fetch using DBI.

  • Comment on Re^2: Problems with values expressed in scientific notation not being returned through DBI
  • Download Code

Replies are listed 'Best First'.
Re^3: Problems with values expressed in scientific notation not being returned through DBI
by huck (Prior) on Dec 07, 2017 at 18:03 UTC

    While unsure about what is going on, i must admit that was a totally unexpected result

    i was wondering if you had run into something called a dualvar.

    use strict; use warnings; $|=1; use Scalar::Util qw(dualvar); use Devel::Peek; print "nv1\n"; my $nv1 = 1e-2 ;Dump($nv1); print "nv1: +$nv1 ".($nv1+0)."\n"; Dump($nv1); print "dv2\n"; my $dv2 = dualvar( 1e-2, "hi" );Dump($dv2); print "dv2: +$dv2 ".($dv2+0)."\n"; Dump($dv2);
    Result
    nv1 SV = NV(0xa7c024) at 0xa3e614 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) NV = 0.01 nv1:0.01 0.01 SV = PVNV(0x3f7364) at 0xa3e614 REFCNT = 1 FLAGS = (PADMY,NOK,pIOK,pNOK) IV = 0 NV = 0.01 PV = 0xa959d4 "0.01"\0 CUR = 4 LEN = 36 dv2 SV = PVNV(0x3f73c4) at 0xa8facc REFCNT = 1 FLAGS = (PADMY,NOK,POK,pNOK,pPOK) IV = 0 NV = 0.01 PV = 0xa45c5c "hi"\0 CUR = 2 LEN = 10 dv2:hi 0.01 SV = PVNV(0x3f73c4) at 0xa8facc REFCNT = 1 FLAGS = (PADMY,NOK,POK,pIOK,pNOK,pPOK) IV = 0 NV = 0.01 PV = 0xa45c5c "hi"\0 CUR = 2 LEN = 10
    Of particular interest here is the line "dv2:hi 0.01" where in string context you get hi, but in numeric you get 0.1. But it doesnt seem that dualvars are your problem.