Solved

Converting An IP Address To An Integer Using MySQL

Posted on 2013-06-15
9
421 Views
Last Modified: 2013-06-17
Hello experts.
I'm trying to use this tutorial:
http://www.bennadel.com/index.cfm?event=blog.viewcode&id=1833&index=1
but i get an error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @ipAsNumber = INET_ATON( @ipAddress ); SET @ipAsAddress = INET_NTOA(' at line 4

error line:
SET @ipAddress = '#ipAddress#';

I'm using local cf9 , mysql 5.5

Any help?
0
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39250147
Is your DSN configured to allow multiple statements?  It's disabled by default to protect you against sql injection.  When it's disabled, that example would cause an error because it contains multiple SQL statements.
 
http://www.bennadel.com/blog/1542-MySQL-3-4-com-mysql-jdbc-Driver-And-allowMultiQueries-true.htm

Edit  But don't really need multiple statements. You could nest the functions instead:

      SELECT
      <cfqueryparam value="#ipAddress#" cfsqltype="cf_sql_varchar"> AS original
      , INET_ATON( <cfqueryparam value="#ipAddress#" cfsqltype="cf_sql_varchar"> ) AS ipAsNumber
      , INET_NTOA ( INET_ATON(<cfqueryparam value="#ipAddress#" cfsqltype="cf_sql_varchar">) ) AS ipAsAddress
       , CAST( INET_NTOA( INET_ATON(<cfqueryparam value="#ipAddress#" cfsqltype="cf_sql_varchar">) ) AS CHAR ) AS ipAsAddressString
0
 
LVL 2

Author Comment

by:Panos
ID: 39250529
Always something new. This is the exciting part. Thank you very much again.
I need your advise.
I read here http://cfsimplicity.com/63/saving-ip-addresses-as-integers-with-coldfusion-orm-and-mysql 
about converting ip to ineger using orm . i tried the example and it is working for me
I never have use it until now. What is your opinion?
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 39250544
Thank you
regards
panos
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 48

Expert Comment

by:PortletPaul
ID: 39250920
you may want to be aware that INET_ATON &  INET_NTOA are for IPv4 only

there are IPv6 equivalent functions (that deal with both IPv4 & IPv6)

INET6_ATON
https://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_inet6-aton
INET6_NTOA
https://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_inet6-ntoa
0
 
LVL 2

Author Comment

by:Panos
ID: 39250962
Hi PortletPaul
Thank you very much for your advise
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39251000
seems I've been too late in just about everything today - but it would be a shame to work purely on IPv4 then discover you need to change for IPv6 some time later - particularly when this is avoidable.
0
 
LVL 2

Author Comment

by:Panos
ID: 39251098
Yes PortletPaul
You are absolutely right.
I'm very thankful for your post because without that i would go on with INET_ATON &  INET_NTOA.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39251111
:) happy coding
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39252999
> there are IPv6 equivalent functions

Nice one, I didn't realize they'd added v6 functions!

@panosms - Just double check the max value. I'm not sure it always fits inside a "long"...

http://stackoverflow.com/questions/420680/how-to-store-ipv6-compatible-address-in-a-relational-database
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Creating and Managing Databases with phpMyAdmin in cPanel.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question