Kevman has asked for the wisdom of the Perl Monks concerning the following question:


Hi Monks,

I have a value in a numeric field (database is SYBASE)
Value is "999999999999.0012"

Select the Value back with DBI and it always comes
back as"999999999999".

I am desperate - despite checking both DBI & Sybase, I
cant >get the value to come back with the .0012

Anyone, anywhere help a desperate bloke whose spent 2 days
on this!!!

Thanks People,

Kevman

Replies are listed 'Best First'.
Re: Bug in DBI? (Surely Not??)
by cybear (Monk) on Jun 14, 2002 at 14:40 UTC
    Kevman,

    Could you help me narrow down where your problem might be?
    How is it that you are viewing the value? If you are using
    a PERL print statement then printf or sprintf might help.
    If you are using sometype of SQL query, perhaps there is something in the
    Tool you are using that truncates the value.

    Just trying to help.:-)


      Bringing code back with a selectall_arrayref
      Then view with print of the individual fields in STDERR

      Note:- I alse tried prepare/execute to bring back val.

      Kevman
Re: Bug in DBI? (Surely Not??)
by dda (Friar) on Jun 14, 2002 at 14:38 UTC
    Please post your code and table desription as well..

    --dda


      Code is simply a select from any table
      Didnt post as it could be any code...
      EG.

      SELECT amount
      FROM amount_table

      Field is float, Length 8, precision NULL.

      Hope that helps???

      Kevman
Re: Bug in DBI? (Surely Not??)
by biograd (Friar) on Jun 14, 2002 at 14:40 UTC
    I'm interested in the problem. Could we see some of the code you used to extract the number?

    Update: *Looks above*...man, you just can't wait a minute before posting this stuff...:) I swear two other people hadn't said exactly the same thing as me when I checked. C'est la vie.

    -ljb

Re: Bug in DBI? (Surely Not??)
by stajich (Chaplain) on Jun 14, 2002 at 14:42 UTC
    what happens when you execute this select from the isql> prompt? Do you get the same behavior if you just do a
    isql>SELECT "999999999999.0012";
    or execute that same query in your perl code?

    It works fine for me with mysql. You may ping the sybperl mailing list or mpeppler or check out the docs at his page author of DBD::sybase.

      Comes back correct Eg. with the .0012 Code I select is:-
      SELECT internal_id, ctrpty_id, agreement_number, master_agreement_type, agreement_type, agreement_ccy, one_two_way, business_unit, substitution, recall_period, reset_agreement, valuation_freq, our_threshold_marker, our_threshold_ccy, our_threshold_amount, cparty_threshold_marker, cparty_threshold_ccy, cparty_threshold_amount, our_mta_ccy, our_mta_amount, cparty_mta_ccy, cparty_mta_amount, finance_net_amount, finance_nominal, finance_base_ccy, gcs_pre_haircut, gcs_post_haircut FROM history..collateral_agreement_h WHERE effective_to = '01-jan-2079' AND internal_id = 1059 AND ctrpty_id = 2383
        Please post the perl code that you use to retrieve records.

        --dda

        Just for giggles you could try and cast it to a varchar and see what you are getting - to keep the debugging simple I would just stick with the simpliest SQL that reproduces your bug, i.e. SELECT 9999999999999.012. I'm forgetting my transact-SQL syntax but something like SELECT varchar(999999999999.021) and see what perl reports - that BETTER work. I'm guessing there is some sort of binding under the hood to a NUMERIC which is not recognizing the precision length of your query. Making a bug report with just this simple example would allow mpeppler to hopefully reproduce and identify the problen quickly. Of course your version of DBD::sybase is the most recent and you're not using an ancient sybase version, right?
Re: Bug in DBI? (Surely Not??)
by Kevman (Pilgrim) on Jun 14, 2002 at 15:28 UTC

    Kudos to Cybear!!! Many +++++++'s

    If I put a sprintf to the number fields, they come out
    correct. Bit messy, but works.

    Strange thing is, I was updating a database table using
    the contents of selectall_arrayref, and the code
    doesnt work correctly, UNLESS I do a sprintf on the
    numeric items in the array.... Bit naff.....

    But It works!!! 2 days are over!!! Im Free!!!1

    Kevman
      A couple of comments.

      First, the table is defined as a "float", and with Sybase that means IEEE float if the platform supports it. As such it's an imprecise data type (and one that I would NOT use for money amounts!). You will almost by definition get data that is different from what you insert.
      For example, I created a dummy table with a single float column, and inserted your 999999999999.0012 value. Running a select on that value with sqsh gives me 999999999999.001221.

      Second - when you fetch a float value DBD::Sybase will store that internally as a perl "numeric" value (an NV). There shouldn't be any loss of precision there, but it's a float, so, as stated above, there are no guarantees.

      For handling precise amounts (financial transactions, etc) I would strongly recommend using either the Sybase MONEY datatype (which is an 8 byte value with an implied 4 decimal places) or using a NUMERIC datatype.

      Michael

      >Im Free!!!

      So, you are gone and we will not see the code? :)

      --dda