Inserting unsigned integers (10 digits)

smayberry

Member
In Oracle8i I have a column defined as Number(10) to store a 32-bit IP address in. In order to perform comparisons on the address, I need it to be stored as an unsigned 32-bit integer. I have tried declaring the query field as otInteger, otFloat, otString... pretty much everything. But it is being inserted as a negative number. For example, 3323018795 gets stored as -971948501. While these are equivalent values when looking at the bits, they are not equivalent according to Oracle. The following query does not return a row:

Code:
SELECT 1 FROM dual WHERE 3323018795 = -971948501;
So, does anyone know how to force an integer to be stored as unsigned? Oh, I am using Delphi5 and the IP address is kept in a longword, which causes Delphi to treat them as unsigned so that less-than/greater-than comparisons work.
 
I figured out what I needed to do to get this to work. Use the otFloat type in the query, and a double variable in Delphi. I had tried just using a cast to double from cardinal (I switched to cardinal from longword since Delphi help says it is faster) but the compiler would complain about that. What I needed to do was define a temporary double variable and assign the cardinal to it. Now the value goes into Oracle as unsigned. If anyone sees a problem with this method or you know of a better way, please let me know. :)
 
This is probably the best method. Direct Oracle Access treats number(10) and larger as float fields by default.
 
Back
Top