Peter J. Holzer wrote:
On 2009-01-27 15:21:55 +0000, Martin Evans wrote:
I'm working with DBD::Oracle at the moment and getting a little frustrated with integer numbers. I'd like my database returned integers to look like integers to Perl but they currently don't until I add 0 to them. Here is the problem:

I think this is on purpose. Oracle numbers have a huge precision (38
decimal digits), so in general you cannot convert them to a perl number
without losing precision.

Yes, that is a good point I had not thought of. My columns are defined with integer but I believe that is just a synonym for number(38).

DBD::Oracle could be smart enough to recognize
the safe cases (integers with at most 9 (32 bit) resp. 18 (64 bit)
digits), but AFAIK it isn't. Your best bet is probably explicitely
binding with an approriate type (SQL_INTEGER).

I tried that and it makes no difference.

I guess this is a lost cause. Even if I could make it work for smaller numbers it would fail for larger numbers :-( To be honest, I tried putting a big number into the column and it fails later in the JSON::XS if 0 is added:

$num as returned from database:
SV = PV(0x8be6660) at 0x8ba1424
  REFCNT = 2
  FLAGS = (PADBUSY,PADMY,POK,pPOK,UTF8)
  PV = 0x8c3f7a0 "1234567891234567"\0 [UTF8 "1234567891234567"]
  CUR = 16
  LEN = 20

$num after adding 0:
SV = PVMG(0x8aeab90) at 0x8ba1424
  REFCNT = 2
  FLAGS = (PADBUSY,PADMY,SMG,NOK,pNOK)
  IV = -1
  NV = 1.23456789123457e+15
  PV = 0x8c3f7a0 "1234567891234567"\0
  CUR = 16
  LEN = 20
  MAGIC = 0x8c47820
    MG_VIRTUAL = &PL_vtbl_utf8
    MG_TYPE = PERL_MAGIC_utf8(w)
    MG_LEN = -1

JSONified string:

[1.23456789123457e+15]

If 0 is not added to it, you can round-trip currently with JSON::XS.

Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Reply via email to