| Author |
Message |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 17/10/2007 15:05:28
|
BuildSmart
Joined: 07/10/2007 07:27:15
Messages: 23
Offline
|
I'm having a hell of a time getting the engine to provide integer number.
Seems even when I try to force the int result it still provided an exponential value.
example.
Code:
<cfset myDottedIP = "192.168.1.1">
<cfset num1 = ListFirst(myDottedIP,".")>
<cfset num1_rest = ListRest(myDottedIP, ".")>
<cfset num2 = ListFirst(num1_rest, ".")>
<cfset num2_rest = ListRest(num1_rest, ".")>
<cfset num3 = ListFirst(num2_rest, ".")>
<cfset num3_rest = ListRest(num2_rest,".")>
<cfset num4 = ListFirst(num3_rest, ".")>
<cfset num_out = int (int(16777216 * num1) + int(65536 * num2) + int(256 * num3) + int(num4))>
<br />num_out: <cfoutput>#num_out#</cfoutput><br />
should provide an int value but it's providing an exponential value and causing me all kinds of grief.
Is this method wrong or does smithcf have a bug?
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 17/10/2007 16:55:46
|
orcus
Joined: 22/01/2007 16:10:52
Messages: 136
Offline
|
Hi BuildSmart,
the following should do the trick:
Code:
<cfset num_out = BitOr(
BitOr( BitSHLN(num1, 24), BitSHLN(num2, 16) ),
BitOr( BitSHLN(num3, 8), num4 )) />
You can look in FuncLib.java for list of available functions.
Now, the result (in binary) is as follows:
Code:
192 .168 .1 .1
11000000 10101000 00000001 00000001
and since 'int' is a singed four-byte value and the MSB (Most Significant Bit) is 1, the resulting int value will be negative (i.e. you will get -1062731519 instead of 3232235777), but that should not be a problem for comparision.
orcus
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/10/2007 00:10:52
|
tomdonovan
Joined: 11/06/2007 20:20:23
Messages: 38
Offline
|
or more simply:
Code:
<cfoutput>#NumberFormat(num_out, "_")#</cfoutput>
See the NumberFormat function.
-tom-
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/10/2007 09:10:51
|
BuildSmart
Joined: 07/10/2007 07:27:15
Messages: 23
Offline
|
hmmm, got an integer now instead of an exponential now but there is still an issue.
Code:
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="3493104135">
still gives me
Code:
Error message: Unable to convert String 3493104135 to number!
Error type: database
File: /Applications/APPLECF/wwwroot/ip2Location.cfm
Row: 69
Column: 20
Program code
67 <cfset ipnumber = #NumberFormat((16777216 * a) + (65536 * b) + (256 * c) + d, "_")#>
68 <!--- do the query --->
69 <cfquery name="getUserInfo" datasource="ip2location">SELECT * FROM ipcitylatlong WHERE ipFrom <= <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="3493104135"> ORDER BY ipFrom DESC LIMIT 1</cfquery>
70
71 <!--- time B --->
I thought that perhaps it was an issue with the exponential value but running a test in BlueDragon and hard-coding with an exponential value doesn't yield an error so I'd have to conclude that something else is wrong with the engines compatability and my environment.
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/10/2007 09:42:51
|
BuildSmart
Joined: 07/10/2007 07:27:15
Messages: 23
Offline
|
Maybe I should provide the full dump, this is using the distribution of the engine as deliverd by the smith project and nothing added but the mysql driver.
I hard coded the number, tied with and without dbl-quotes, made no difference, always get the same error.
Code:
EXCEPTION INFO
Exception overview
Error message:
Unable to convert String 3493104135 to number!
Error type:
database
File:
/Applications/APPLECF/wwwroot/ip2Location.cfm
Row:
69
Column:
20
Program code
67
<cfset ipnumber = #NumberFormat((16777216 * a) + (65536 * b) + (256 * c) + d, "_")#>
68
<!--- do the query --->
69
<cfquery name="getUserInfo" datasource="ip2location">SELECT * FROM ipcitylatlong WHERE ipFrom <= <cfqueryparam cfsqltype="CF_SQL_INTEGER" value=3493104135> ORDER BY ipFrom DESC LIMIT 1</cfquery>
70
71
<!--- time B --->
Stack trace
[Error message: Unable to convert String 3493104135 to number!]
com.youngculture.smith.engine.db.SmithQuery.setInParams(SmithQuery.java:543)
com.youngculture.smith.engine.db.SmithQuery.execute(SmithQuery.java:187)
com.youngculture.smith.engine.tagimpl.QueryTagImpl.doTag(QueryTagImpl.java:130)
com.youngculture.smith.engine.tagimpl.AbstractTagImpl.execute(AbstractTagImpl.java:64)
__smithdynamic._Applications._APPLECF_wwwroot._ip2Location.execute(_ip2Location.java:554)
com.youngculture.smith.engine.pages.CfPage.run(CfPage.java:42)
com.youngculture.smith.engine.pages.PageUtil.runPage(PageUtil.java:290)
com.youngculture.smith.engine.util.PageDispatcher.includePage(PageDispatcher.java:92)
com.youngculture.smith.engine.util.PageDispatcher.includePage(PageDispatcher.java:116)
com.youngculture.smith.engine.servlets.SmithServlet.serviceRequest(SmithServlet.java:167)
com.youngculture.smith.engine.servlets.SmithServlet.service(SmithServlet.java:112)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:447)
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:356)
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:226)
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:621)
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:123)
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
org.mortbay.jetty.Server.handle(Server.java:269)
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:430)
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:692)
org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:617)
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:199)
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:339)
org.mortbay.jetty.nio.HttpChannelEndPoint.run(HttpChannelEndPoint.java:270)
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)
[Error message: For input string: "3493104135"]
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:480)
java.lang.Integer.parseInt(Integer.java:518)
com.youngculture.smith.engine.db.SmithQuery.setInParams(SmithQuery.java:540)
com.youngculture.smith.engine.db.SmithQuery.execute(SmithQuery.java:187)
com.youngculture.smith.engine.tagimpl.QueryTagImpl.doTag(QueryTagImpl.java:130)
com.youngculture.smith.engine.tagimpl.AbstractTagImpl.execute(AbstractTagImpl.java:64)
__smithdynamic._Applications._APPLECF_wwwroot._ip2Location.execute(_ip2Location.java:554)
com.youngculture.smith.engine.pages.CfPage.run(CfPage.java:42)
com.youngculture.smith.engine.pages.PageUtil.runPage(PageUtil.java:290)
com.youngculture.smith.engine.util.PageDispatcher.includePage(PageDispatcher.java:92)
com.youngculture.smith.engine.util.PageDispatcher.includePage(PageDispatcher.java:116)
com.youngculture.smith.engine.servlets.SmithServlet.serviceRequest(SmithServlet.java:167)
com.youngculture.smith.engine.servlets.SmithServlet.service(SmithServlet.java:112)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:447)
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:356)
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:226)
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:621)
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:123)
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
org.mortbay.jetty.Server.handle(Server.java:269)
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:430)
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:692)
org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:617)
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:199)
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:339)
org.mortbay.jetty.nio.HttpChannelEndPoint.run(HttpChannelEndPoint.java:270)
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/10/2007 10:02:16
|
BuildSmart
Joined: 07/10/2007 07:27:15
Messages: 23
Offline
|
Further details, it appears to be value related, I guess a bug needs to be filed on this and I thought it was me or something wrong in my environment, go figure.
0 to 2147483647 is ok 2147483648+ fails.
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 18/10/2007 16:09:59
|
tomdonovan
Joined: 11/06/2007 20:20:23
Messages: 38
Offline
|
FYI - Adobe CF8 won't accept this number either:
Code:
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="3493104135">
The CF8 error is: Invalid data 3493104135 for CFSQLTYPE CF_SQL_INTEGER.
The CFML definition of Integer is ColdFusion supports integers between -2,147,483,648 and 2,147,483,647 (32-bit signed integers).
.
If the datatype in your database is not really Integer, but some other Numeric or Decimal datatype
- you could try using CF_SQL_DECIMAL or CF_SQL_NUMBER instead of CF_SQL_INTEGER.
-tom-
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 21/10/2007 10:28:26
|
BuildSmart
Joined: 07/10/2007 07:27:15
Messages: 23
Offline
|
It appears that the smithcf engine doesn't provide int results in a math calculation is the cause of the problem.
In both BlueDragon and Adobe CF the IP is converted to an int(32) which provides a negative number for the value yet the smithcf engine doesn't, it calulcates the IP with the math routine and the value is never an int(32), always a positive number.
That has to be a bug.
|
|
|
 |
![[Post New]](/forum/templates/default/images/icon_minipost_new.gif) 21/10/2007 23:45:11
|
tomdonovan
Joined: 11/06/2007 20:20:23
Messages: 38
Offline
|
Using this code to access a MySQL database with a large value as CF_SQL_INTEGER:
Code:
<cfset a = 192>
<cfset b = 168>
<cfset c = 1>
<cfset d = 1>
<cfset ipnumber = Int((16777216 * a) + (65536 * b) + (256 * c) + d)>
<cfoutput>
ipnumber #ipnumber#<br>
formatted #NumberFormat(ipnumber,"_")#<br>
type #ipnumber.getClass().toString()#<br>
</cfoutput>
<cfquery name="q1" datasource="mysqlTest">
SELECT * from tbl01 WHERE id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ipnumber#">
</cfquery>
The results for several servers are:
Code:
Server Internal Type Default Format Formatted Query
------------- ----------------- -------------- ----------- ------------------------------------------------------
Smith 1.3b java.lang.Double 3.232235777E9 3232235777 Unable to convert String 3.232235777E9 to number!
BlueDragon 7 java.lang.String 3232235777 3232235777 successful
CF8 java.lang.Double 3232235777 3232235777 Invalid data 3.232235777E9 for CFSQLTYPE CF_SQL_INTEGER.
CF7.0.2 java.lang.Double 3232235777 3232235777 Invalid data 3.232235777E9 for CFSQLTYPE CF_SQL_INTEGER.
It appears to be a unique behavior of BlueDragon that it allows CF_SQL_INTEGER values larger than the integer maximum as a queryparam.
When no formatting function is used, Smith formats calculated numeric values differently from CF and BD by default.
There may be a formatting bug here, although fixing it won't make values > 2,147,483,647 work with <cfqueryparam>:
Smith uses the standard Java algorithm to format calculated numeric values - so any value 10,000,000 or greater will be in scientific notation. Unlike Java, Smith will trim off a trailing ".0" fractional portion for numbers smaller than 10,000,000.
Both CF and BD seem to use 10^12 instead of 10^7 as the cutoff for using scientific notation for large values.
CF and BD differ in the cutoff for small values (near zero).
I cannot find any mention in the CF docs that specifies exactly when scientific notation is expected.
-tom-
|
|
|
 |
|
|