Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: OT: Is MD5 ALWAYS 32 character long?

by sth (Priest)
on Dec 18, 2003 at 12:32 UTC ( #315505=note: print w/ replies, xml ) Need Help??


in reply to Re: OT: Is MD5 ALWAYS 32 character long?
in thread OT: Is MD5 ALWAYS 32 character long?

If it is a char(32) there will be trailing spaces if the value is not 32 chars long. This could affect a lookup. If the match value is not sent in with trailing spaces to make it 32 chars long, the match will fail. At least this is the case in Oracle.

sth


Comment on Re: Re: OT: Is MD5 ALWAYS 32 character long?
Re: Re: Re: OT: Is MD5 ALWAYS 32 character long?
by tilly (Archbishop) on Dec 18, 2003 at 15:19 UTC
    If the match value is not sent in with trailing spaces to make it 32 chars long, the match will fail. At least this is the case in Oracle.

    Judging from what my copy of Oracle does, the output of select 'yes' from dual where 'hello ' = 'hello'; may surprise you.

    The SQL-92 standard says that trailing spaces should not affect whether two things are =, and Oracle seems to be in compliance. I think that any other behaviour would be a bug.

    Trailing spaces will affect like, decode, and so on though. And, of course, if you are actually fetching back the value and comparing in Perl, then you will definitely see the difference.

    So depending on how you intend to do the lookup, trailing spaces might not matter to you.

      Hrm, looks like PostgreSQL isn't compliant. Which is something I've been bitten by before.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated

      Judging from what my copy of Oracle does, the output of select 'yes' from dual where 'hello ' = 'hello';

      ..Are you sure that Oracle is not treating the strings as varchar2's, within that statement? Granted I ran into this problem with Oracle 8.0.5, but there was a column in a table that was defined as char(18) and I was using DBI to do lookups against that table. Some of the lookup values did not have trailing spaces and the matched failed. DBD::Oracle trims trailling spaces by default, which can be overriden. I eventually changed the column to be a varchar2 and the trailing spaces were not an issue anymore.

        My strong guess is that Oracle actually is treating the strings as varchar2's. However if a varchar2 and a char get treated differently, I think that that is a bug.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-12-26 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls