Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Reading (the same) data in different ways & memory usage

by BrowserUk (Patriarch)
on Apr 19, 2011 at 15:30 UTC ( [id://900149]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Reading (the same) data in different ways & memory usage
in thread Reading (the same) data in different ways & memory usage

the returned data-structure to be 385251506 bytes, which, for some reason is smaller than the data-structure retrieved from the db

Perhaps the DBI code doesn't trim leading/trailing spaces on string fields?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^3: Reading (the same) data in different ways & memory usage

Replies are listed 'Best First'.
Re^4: Reading (the same) data in different ways & memory usage
by Tux (Canon) on Apr 19, 2011 at 18:42 UTC

    If the target fields in the database are of type CHAR (not VARCHAR), you can make DBI do so by:

    $dbh->{ChopBlanks} = 1;

    Some DBD's do extend this behavior to VARCHAR fields (when the database it too stupid to do so itself, as the ANSI standard tells it to) or when VARCHAR effectively is a CHAR internally (because the database doesn't support VARCHAR).

    YMMV


    Enjoy, Have FUN! H.Merijn
      (when the database it too stupid to do so itself, as the ANSI standard tells it to)

      Erm. If I store the string 'fred          ' into a DB, I'd expect to get that same string back. Does ANSI mandate otherwise?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Try to read (and understand) this sheet from one of my presentations. All Orange fields do NOT meet my expectations or the standard.

        The page is old, but most of those still hold true.


        Enjoy, Have FUN! H.Merijn
Re^4: Reading (the same) data in different ways & memory usage
by Neighbour (Friar) on Apr 21, 2011 at 06:49 UTC
    Well, one thing I found is that all FLOAT (and probably DOUBLE) values are returned as string (for example "0.00" for a column defined as FLOAT(7,2)).
    Using DBD::MySQL 4.0.18 (should that matter) with default connection options.
      one thing I found is that all FLOAT (and probably DOUBLE) values are returned as string

      That does make a certain amount of sense.

      If you converted floats to their binary numeric representation, then you could introduce typical floating point representation errors. If you are going to do math with them in your perl code, then that will happen anyway and you'd have to deal with it.

      But if you are only going to display them, or store them into another table somewhere, then returning them as strings means that you don't have to deal with those errors.

      Whether that is the reasoning behind it I cannot say, but it could be.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I would expect this to be the case for Fixed-Point values (DECIMAL and NUMERIC types), but not for FLOAT and DOUBLE, which already suffer from floating point representation errors because, well, that's what they are (even inside MySQL).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://900149]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2025-07-08 08:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.