• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Jun 21, 2008 Jun 21, 2008

Copy link to clipboard

Copied

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 .
TOPICS
Advanced techniques

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2008 Jun 21, 2008

Copy link to clipboard

Copied

It is working fine for some date range and and getting above mentioned error in sone situation .

The return object qry is perhaps undefined for certain date ranges. If so, then a possible workaround is to include the following line within the cfscript block at the top:

var qry = queryNew(colNames);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2008 Jun 21, 2008

Copy link to clipboard

Copied

I think your problem is this line.
ORDER BY #colSort# ASC

because you didn't scope your variable.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2008 Jun 21, 2008

Copy link to clipboard

Copied

> ORDER BY #colSort# ASC

Are there any nulls in this column? Nulls and ORDER BY in QoQ don't play
nice, sometimes.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 22, 2008 Jun 22, 2008

Copy link to clipboard

Copied

Thanks for reply ...

No NULL value i got when i have taken cfdump of tempqry . I am taking sort order on Timestamp values .

Hoping for reply asap .


Rajesh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

Can you just verify that the null pointer error is definitely referencing
the line(s) of code where the QoQ is, and not a different part of the
function?

make sure you VAR all your variables in the function. Most aren't.

It's not relevant to this, but you will make your code an awful lot clearer
and easier to follow if you scope all your variables (eg:
arguments.colSort, not simply colSort).

What happens if you take the ORDER BY out?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied


Thank Adam for your reply ...

No effect i am getting after removing order by clause ......

Same issue ....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

> No effect after removing order by clause ......

So, as per my question... what line of code is it pointing to?

And did you do the other things I mentioned?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2008 Jun 21, 2008

Copy link to clipboard

Copied

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.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

cfdump your query and cfabort right before the Q of Q. Look for hints.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

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.



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

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



Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

> 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.

You mean colArray, yeah?

It's not a 2-D array, it looks like it's an array of structs (which we did
kind of ask about, by way of clarification).


> 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 .

What version of CF are you running?

Since... umm... CFMX7 (someone will correct me if need be) one has been
able to specify the column types, which are then respected.

If you're not specifying the column types, you can javaCast until you're
blue in the face: CF still simply guesses the type.


> javacast() is not properly working in this case .

What makes you say that?

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

>>>You mean colArray, yeah?

---- yes

>>>What version of CF are you running?

ColdFusion MX 6.0.


Rajesh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

Hi All ,

Thank you for your support ,

Finally i have fix the issue using some changes in my function in cfc .

<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>
//Declare variable collection used in function as local --->
var tmpqry = Querynew(arguments.colNames,"CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_DATE,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR,CF_SQL_VARCHAR");
var qRow = QueryAddRow(tmpqry, Arraylen(arguments.colArray));
</cfscript>

<cfloop from="1" to="#Arraylen(arguments.colArray)#" index="qRowIndex">
<cfscript>
// Populate the query table

QuerySetCell(tmpqry, 'SENSOR', colArray[qRowIndex]["SENSOR"], qRowIndex);
QuerySetCell(tmpqry, 'TYPE',arguments.colArray[qRowIndex]["TYPE"], qRowIndex);
QuerySetCell(tmpqry, 'TIMESTAMP2', LSParseDateTime(arguments.colArray[qRowIndex]["TIMESTAMP2"]), qRowIndex);
QuerySetCell(tmpqry, 'ORDER_BY_PARAM',arguments.colArray[qRowIndex]["ORDER_BY_PARAM"], qRowIndex);
QuerySetCell(tmpqry, 'READING_CODE', colArray[qRowIndex]["READING_CODE"] , qRowIndex);
QuerySetCell(tmpqry, 'READING',arguments.colArray[qRowIndex]["READING"], qRowIndex);
QuerySetCell(tmpqry, 'PK_READING',arguments.colArray[qRowIndex]["PK_READING"], qRowIndex);
QuerySetCell(tmpqry, 'ALARM_STATUS',arguments.colArray[qRowIndex]["ALARM_STATUS"], qRowIndex);
QuerySetCell(tmpqry, 'DURATION', arguments.colArray[qRowIndex]["DURATION"], qRowIndex);
QuerySetCell(tmpqry, 'DESCRIPTION',arguments.colArray[qRowIndex]["DESCRIPTION"], qRowIndex);

</cfscript>
</cfloop>

<cfquery name="qry" dbtype="query" >

SELECT *
FROM tmpqry
ORDER BY #arguments.colSort# ASC

</cfquery>

<cfreturn qry >

</cffunction>

Rajesh
SCMS
India

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 25, 2008 Jun 25, 2008

Copy link to clipboard

Copied

Note, you're still not VARing this:


> index="qRowIndex">

Or:

This:

> <cfquery name="qry"

Otherwise, good work.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2008 Jun 25, 2008

Copy link to clipboard

Copied

Hi all ,

I am facing another problem in the date formatting .

I want to make the date formated in dd/mm/yy . I used LSDateFormat() ,DateFormat() Functionasof Cold Fusion to Format the timestamp values from qry using different mask .

but i am not getting proper result when we format the dates of April . Instead of giving result in dd/mm/yy it gives in mm/dd/yy inrespective of mask given in the function .


Is there any way to handle this situation ,

Rajesh

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2008 Jun 25, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2008 Jun 25, 2008

Copy link to clipboard

Copied

LATEST
> ...i am not getting proper result when we format the dates

What is your locale? Run

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation