in reply to DBI: when 1 != '1'
I'll pass on the ability of Perl to distinguish between 1 and '1'. To my knowledge there's no way to separate them, hence all the questions about using a regex to determine whether a variable contains a number or not.
Anyway... Oracle (about which I know) certainly has a problem when you pass it queries such as SELECT name FROM user WHERE id = '1', if id is a numeric value. Every other language will also have the same problem, since it's trying to compare a number with a string.
Oracle's rule used to be (but it's changed now, and I'm not entirely sure what to) that the left-hand value got converted to the type of the right-hand value before the comparison is made. So, if you coded id = '1.0' the test would always fail (as the id 1 would get converted to '1'), whereas '1.0' = id would suceed (as '1.0' would be converted to 1).
This caused some problem with writing general comparisons across different types: if a is numeric and b is a string, then a = b could fail (as above). However, b = a could actually cause a database error if b ever ended up holding a value which it was not possible to interpret as a numeric value.
--
Tommy
Too stupid to live.
Too stubborn to die.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: DBI: when 1 != '1'
by rdfield (Priest) on Sep 27, 2002 at 12:51 UTC | |
by tommyw (Hermit) on Sep 27, 2002 at 14:21 UTC | |
|
Re: Re: DBI: when 1 != '1'
by bart (Canon) on Sep 27, 2002 at 23:55 UTC |