Skip to main content
Participating Frequently
June 21, 2008
Question

The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or

  • June 21, 2008
  • 13 replies
  • 1993 views
I have taken the cfdump for tmpqry and it shows all data for the range ( No error at this step ) . But when we exceute this dbquery we get below mentioned error .

<cfquery name="qry" dbtype="query" >
SELECT *
FROM tmpqry
ORDER BY #arguments.colSort# ASC
</cfquery>

senerio:

I am using createobject to create a reference for component and call MDArraySort function in the cfc and getting this error .

'The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code.

Null pointer is undefined.... '

i am using this code in a cfc file.

<cffunction name="MDArraySort" Returntype="query" access="public" >
<cfargument name="colArray" type="array" required="true">
<cfargument name="colNames" type="string" required="true">
<cfargument name="colSort" type="string" required="true">
<cfargument name="sensorIDs" type="string" required="true">

<cfscript>
var tmpqry = Querynew(arguments.colNames);
var qRow = QueryAddRow(tmpqry, Arraylen(arguments.colArray) );
</cfscript>

<cfloop from="1" to="#Arraylen(arguments.colArray)#" index="qRowIndex">

<cfscript>

sIndexinSensorIDs = colArray[qRowIndex]["SENSOR"]&"##";
Temp_readin_code = colArray[qRowIndex]["READING_CODE"]&"##";

QuerySetCell(tmpqry, 'SENSOR', sIndexinSensorIDs, qRowIndex);
QuerySetCell(tmpqry, 'TYPE',javacast('String',colArray[qRowIndex]["TYPE"]), qRowIndex);
QuerySetCell(tmpqry, 'TIMESTAMP2', LSParseDateTime(colArray[qRowIndex]["TIMESTAMP2"]), qRowIndex);
QuerySetCell(tmpqry, 'ORDER_BY_PARAM',javacast('String',colArray[qRowIndex]["ORDER_BY_PARAM"]), qRowIndex);
QuerySetCell(tmpqry, 'READING_CODE',Temp_readin_code , qRowIndex);
QuerySetCell(tmpqry, 'READING',javacast('String',colArray[qRowIndex]["READING"]), qRowIndex);
QuerySetCell(tmpqry, 'PK_READING',javacast('String',colArray[qRowIndex]["PK_READING"]), qRowIndex);
QuerySetCell(tmpqry, 'ALARM_STATUS',javacast('String',colArray[qRowIndex]["ALARM_STATUS"]), qRowIndex);
QuerySetCell(tmpqry, 'DURATION', javacast('String',colArray[qRowIndex]["DURATION"]), qRowIndex);
QuerySetCell(tmpqry, 'DESCRIPTION',javacast('String',colArray[qRowIndex]["DESCRIPTION"]), qRowIndex);

</cfscript>
</cfloop>

<cfquery name="qry" dbtype="query" >
SELECT *
FROM tmpqry
ORDER BY #arguments.colSort# ASC
</cfquery>

<cfreturn qry >

</cffunction>

It is working fine for some date range and and getting above mentioned error in sone situation .
This topic has been closed for replies.

13 replies

BKBK
Community Expert
Community Expert
June 26, 2008
> ...i am not getting proper result when we format the dates

What is your locale? Run

<cfoutput>#getLocale()#</cfoutput>

BKBK
Community Expert
Community Expert
June 25, 2008
Lovely Raj12 wrote:
ColdFusion MX 6.0

Arguably the most unstable and most buggy Coldfusion release. You should move up to MX7.0.2 or CF8. If that is not possible, you should at least upgrade to MX6.1 and apply the MX6.1 Updater

Inspiring
June 24, 2008
> However,
> in the context of passing complex data to a function, which is the case here, a
> query or 2-D array would be more appropriate.

What's an example of a two-dimensional array being the most appropriate
data structure (keeping in mind that I will be betting a combination of
arrays and structs will almost always been a better fit for business data).
For the purposes of the exercise.

--
Adam
Participating Frequently
June 24, 2008
Current requirement was to extract all data from the database and sort the data based on the timestamp .

I am looping to get all data from database for all sensor (A, B,C, D ,1, 2 ......). To store all data at one place i am using a two dimentional array QryArray .QryArray is paased as a parameter to MDArraySort function in cfc.in this function i want to transform the 2 D array into query so we can sort this in a easier manner .

In this function i have repeatedly used the javacast function to set datatype manually . As we know query using querynew set the datatype by checking first two or three entries . in my case there are two types of data in each column . so it create a datatype mismatch issue . i fixed it temporarily by making column value as string as javacast() is not properly working in this case .

in my MDArraySort Function ....

I have taken the cfdump of tmpqry it is giving exact result at this point no error happens but when i am going to sort using QoQ for sorting it create an exception as mentioned .

Rajesh



BKBK
Community Expert
Community Expert
June 24, 2008
I didn't want to weigh array of structs versus queries, in general. There is no point. They have their pros and cons. Hence what you say makes sense. However, in the context of passing complex data to a function, which is the case here, a query or 2-D array would be more appropriate.

Inspiring
June 23, 2008
> That's true. An array of structs is the only obvious possibility. I thought of
> it, but ruled it out immediately.

Well... let's let the OP rule that out ;-)


> a key?). Also, an array of structs is conceptually a query with given row
> numbers and column names.

A lot of people assert this. An array of structs has its first "axis"
indexed on positive integers, the second on string-based keys; a query has
a similar structure. However the implementation of arrays / srtucts is
quite different from how a query is implemented. Queries are a lot more
complex. But, yeah, superficially they present the same.

Bear in mind that each struct in an array of structs can have completely
different keys from each other, andthey don't form "columns", whereas a
query definitely has the concept of a column.


> Then one would expect a query to be passed.

Yes: in this instance, I wager the underlying data structure might lend
itself better to be stored in a query rather than how it seems to be
stored.


> Thoughts like these made me not to think too deep about the javacast
> expressions. A two-dimensional array made more sense.

I have yet to see a sensible usage of a two-dimensional array in CF. I can
think of uses (co-ordinated data, values in a matrix, etc), but usually
when people have two-dimensional arrays, I really thing they're after a
query, a struct of structs, or an array of structs.


> Lovely Raj12 should dump it and have a
> look before passing it to the blender.

Yup.

--
Adam
BKBK
Community Expert
Community Expert
June 23, 2008
BKBK wrote:
>> That is wrong. An array cannot have a string as index.

Adam Cameron wrote:
> So that's perfectly fine.

> I think colArray is a poorly-named variable. It looks like an
> array of structs to me, and it's rather odd to have something
> called COLarray to be indexed by row (qRowIndex).


That's true. An array of structs is the only obvious possibility. I thought of it, but ruled it out immediately.

Why would a function have intimate knowledge of the keys in a structure within the caller? (What if different callers use different keys? Or a caller changes a key?). Also, an array of structs is conceptually a query with given row numbers and column names. Then one would expect a query to be passed.

Thoughts like these made me not to think too deep about the javacast expressions. A two-dimensional array made more sense.

Your detective work is more patient, and goes beyond my observation. If colArray is indeed an array of structs, Lovely Raj12 should dump it and have a look before passing it to the blender.

Inspiring
June 23, 2008
> javacast('String',colArray[qRowIndex]["ORDER_BY_PARAM"])
>
> That is wrong. An array cannot have a string as index.

qRowIndex is an integer, set here:

<cfloop from="1" to="#Arraylen(colArray)#" index="qRowIndex">

So that's perfectly fine.

I think colArray is a poorly-named variable. It looks like an array of
structs to me, and it's rather odd to have something called COLarray to be
indexed by row (qRowIndex). So it's quite possibly something is afoot
here.

However rather than speculating... "lovely raj12"... what's the composition
of colArray? It doesn't seem to be an array of columns (whatever that
would be).

--
Adam
BKBK
Community Expert
Community Expert
June 23, 2008
Lovely raj12,
Your code contains many expressions like this one:

javacast('String',colArray[qRowIndex]["ORDER_BY_PARAM"])

That is wrong. An array cannot have a string as index.



Inspiring
June 23, 2008
cfdump your query and cfabort right before the Q of Q. Look for hints.
BKBK
Community Expert
Community Expert
June 21, 2008
Dan Bracuk wrote:
... you didn't scope your variable.

The arguments scope isn't compulsory.

Adam Cameron wrote:
Are there any nulls in this column?

From what I can see, colSort is user input.