can't cast String [] to a value of type [numeric]

Railo Error Message
invalid call of the function getJerseyColor (), first Argument (Color) is of invalid type, can't cast String [] to a value of type [numeric]

Using a UDF (User Defined Function) created to convert a numeric value to a string within a returned query. We have an integer stored in the database table which represents a color value. It is much easier for the user to actually read the color name instead of mentally trying to convert the number to a the color value each time. We are actually looking at Jersey colors and Jersey numbers, so coaches and evaluators can quickly and easily identify each player.

Here's the UDF:

view plain print about
1<cffunction name="getJerseyColor">
2    <cfargument name="Color" type="numeric" required="true" />
3    <cfset var JerseyColor = "" />
4    <cfswitch expression="#arguments.Color#">
5        <cfcase value="1">
6            <cfset JerseyColor = "Yellow" />
7        </cfcase>
8        <cfcase value="2">
9            <cfset JerseyColor = "Blue" />
10        </cfcase>
11        <cfcase value="3">
12            <cfset JerseyColor = "Purple" />
13        </cfcase>
14        <cfcase value="4">
15            <cfset JerseyColor = "Yellow/Blue" />
16        </cfcase>
17        <cfcase value="5">
18            <cfset JerseyColor = "Green/Blue" />
19        </cfcase>
20    </cfswitch>
21    <cfreturn JerseyColor />

Here's how the UDF is called:

view plain print about
1<cfset filterPlayer.Color = getJerseyColor(filterPlayer.Color) />

Here it is utilized replacing the returned query value for "Color":

view plain print about
1<cfquery name="filterPlayer" datasource="#application.datasource#">
2    SELECT     playerid    AS "ID",
3        rate1        AS "Color",
4        rate2        AS "Num"
5    FROM     tblplayerinfo
7<!--- make jersey color human readable --->
8<cfloop query="filterPlayer">
9    <cfset filterPlayer.Color = getJerseyColor(filterPlayer.Color) />

Now about the error....

Testing on development produced no error, while Production generated the error. Both columns in each MySQL database were numeric, of type smallint(6) and defaulted to Null. In this case, we are talking about "rate1" column aliased as "Color". The only difference between the two database columns was that the development MySQL database had actual numeric values in each row. Production had Null values in every "rate1" column row.

Doing a little reasearch, mainly Googling "can't cast string to a number value" turned up some issues about Railo and null values while casting strings to numbers. Some pondering led to realization that the column needed non Null numeric values to allow the UDF to run.

The solution was to replace the Null values in the numeric int() column to actual numeric values. Setting to 0 (zero) worked. Now the UDF runs perfectly.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.7. Contact Blog Owner