Click here to get back home

Ip address Data Type DBI

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Ip address Data Type DBI onlineviewer 05-10-2006
Posted by onlineviewer on May 10, 2006, 4:38 pm
Please log in for more thread options


Hello,

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

Thank you,


Posted by Matthew Braid on May 11, 2006, 12:19 am
Please log in for more thread options


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

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;
}

MB

Posted by onlineviewer on May 11, 2006, 9:44 am
Please log in for more thread options


much appreaciated,,,

thanks,


Similar ThreadsPosted
Manipulating ANY type of email January 3, 2006, 5:03 pm
How to detect an image type with GD November 8, 2006, 12:10 pm
GD: How to know image type? (JPEG, PNG, ..) January 15, 2008, 6:36 am
Can't find Module IP::Address February 27, 2008, 3:42 pm
Email address syntax check? December 2, 2006, 2:58 pm
Term::Cap -- Setting terminal type under Windows XP May 24, 2006, 1:46 pm
Term::Cap -- Setting terminal type under Windows XP May 29, 2006, 9:22 pm
Looking for module that will expands domain/username to email address October 23, 2004, 12:56 am
IPV6 socket connection, with a link-local address January 11, 2008, 1:12 pm
HTTP::Request::Form - Problem pressing input type=image button February 1, 2005, 7:56 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap