Ip address Data Type DBI

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'm using perl DBI, and I am trying to insert data into a table, but i
having trouble using the right data type for ip address. It will insert
the address but it truncates it. will look like 10
I've tried almost every type , but no luck. Any suggesstions?

Thank you,

Re: Ip address Data Type DBI

onlineviewer wrote:
Quoted text here. Click to load it

If you don't care about in-database comparisons, what's wrong with
varchar (ie, a string)?

If you do care about comparisons and you're only dealing with IPv4,
convert the ip to a number (see below - code contains no error
checking!) and store the number (don't forget to convert back when you
retrieve it - I'll leave that as an excercise for the reader :) )

sub ip4_to_num {
   my ($ip) = @_;
   my ($num, $pow) = (0, 3);
   for my $oct (split /\./, $ip) {
     $num += $oct * 256 ** $pow--;
   return $num;


Re: Ip address Data Type DBI

much appreaciated,,,


Site Timeline