Not of type Numeric when it damn well is...

I have a problem, and it's ColdFusion... We're working on some complex object interaction, and moving data in and out of our objects. Part of the "moving in" part involves building out a structure of arguments based on query columns, and then passing them all in via the ArgumentCollection. Unfortunately, ColdFusion doesn't love us here at lynda.com... It's pitching a fit and saying that our IDs aren't of type numeric, when I know damn well that they are (grumble grumble)... To demonstrate my point I've come up with the following code example. This fails every time for me:

That generates the following error: The argument ID passed to function init() is not of type numeric. Has anyone else come across this same error? Is there some hotfix that fixes this? It's completely stymied our development... The only way around it is to set our arguments to accept type="any", which honestly is unacceptable...
Posted by Daniel Short on Jan 4, 2007 at 12:00 AM | Categories: Rambling - ColdFusion - Dreamweaver -

14 Comments

charlie griefer

charlie griefer wrote on 01/04/07 2:24 PM

add the [1] inside the loop where you're converting the query to a struct. otherwise, do some dumps on the rs[col] values. output the value of isSimpleValue(rs[col]) for each loop iteration. they're not simple values. i'm not sure what they are...i thought omitting the [1] would default to the first row...but something more is going on. in any event, specifying the record position in the query seems to resolve it. hope that helps.
Daniel Short

Daniel Short wrote on 01/04/07 2:24 PM

Yup
Danilo

Danilo wrote on 01/04/07 3:27 PM

Hey man, hope all is well! My first thought was that the query cell value that is returned is actually some Java data type, not the integer you're telling it to be. So I tried dumping: IsNumeric(TestStruct["ID"]) and it output NO so CF wasn't seeing it as numeric. So I thought instead of using the default for pulling the query row value: rs[col] trying rs[col][1] to indicate pulling the first row and then IsNumeric(TestStruct["ID"]) did return YES. As I don't have access to your CFC...or do I? :-) you'll have to try it to see how it'll work for your situation. Let me know. PS: Not that I post here so much, but how about making the textarea a little wider and taller?
Daniel Short

Daniel Short wrote on 01/04/07 3:27 PM

Nail, meet hammer :)
Adrian J. Moreno

Adrian J. Moreno wrote on 01/05/07 1:34 PM

I'd say the problem is that ArgumentCollection is an attribute of cfinvoke and (without seeing the code for test.cfc) not an argument of the init() method. I imagine that init() has two arguments: {cfargument name="ID" type="numeric" required="true" /} {cfargument name="FirstName" type="string" required="true" /} Since you're passing in a named argument called ArgumentCollection and no named argument called ID, the error is thrown as expected. If you instead use {cfset MyObject = CreateObject("component", "test").init(ID = TestStruct.ID, FirstName = TestStruct.FirstName) /} the object will be created correctly. HTH
Daniel Short

Daniel Short wrote on 01/05/07 1:35 PM

Actually the argumentcollection allows you to pass in an entire struct of arguments without having to name them all :). It came down to me not referencing the proper row of the recordset.
TAmi

TAmi wrote on 01/06/07 3:08 PM

Hi Dan... I have had the same issue before, but I am surprised you are able to CFDUMP an CFC object. I can never get my CFMX to play nice. I usually have to then My CFMX is persnickety about trying to evaluate complex structures that involve CFC calls.... Just a thought... Tami
Daniel Short

Daniel Short wrote on 01/06/07 3:08 PM

Interesting issue... not sure what would be going on there...
DAD

DAD wrote on 01/06/07 3:27 PM

I think that if you turn your = sign over, then take a backward < sign and turn it around to make a >, then take and flip your [ right side up, then leave all the comma's where they are, it ought to work perfectly. Hope this helps, Dad
Daniel Short

Daniel Short wrote on 01/06/07 3:27 PM

Thanks dad, that worked perfectly :).
Paul

Paul wrote on 01/08/07 11:45 AM

You are using cfmx6 correct? If so this is a known bug and you may be able to get around it by using the javaCast function when setting the id. In general when you create or edit a query in cfmx6 you may have problems when checking the type of the data.
Daniel Short

Daniel Short wrote on 01/08/07 11:46 AM

Actually it turned out to be me not referencing the column correctly. I needed this: <cfset TestStruct[col] = rs[col][1] />
Bryan Ashcraft

Bryan Ashcraft wrote on 01/15/07 2:38 PM

Total shot in the dark here, but could be the way you are addressing the value? For instance: arguments.testStruct.id vs arguments.testStruct[1]
Daniel Short

Daniel Short wrote on 01/15/07 2:38 PM

Yep, you got it Bryan...