CFX lucee.runtime.cfx.QueryWrap.getData broken

Description

We are working with CFX Extensions to address external services.

A query is passed to the function and is then handled in JAVA:

Query query = request.getQuery();
int rows = query.getRowCount(); // 1 row!
for (int row = 1; row <= rows; row++)
{
LogHelper.logIt("GET_QUERY: ROW: " + row); // Log it to make sure
String data = (query.getData(row, 1)); // this is row 1
}

--> Lucee throws error:
java.lang.IndexOutOfBoundsException: invalid row index to retrieve Data from query, valid index goes from 1 to 1.

Stacktrace:

java.lang.IndexOutOfBoundsException: invalid row index to retrieve Data from query, valid index goes from 1 to 1
at lucee.runtime.type.QueryImpl.getData(QueryImpl.java:1585)
at lucee.runtime.cfx.QueryWrap.getData(QueryWrap.java:123)

Environment

None

Activity

Pothys - MitrahSoft 18 July 2017 at 07:27

Closing this as per the reporter's comment.

Oliver Neumann 29 June 2017 at 09:45


was corrected with Lucee version 5.2.1.9 --> NULL Support was changed. Can be closed

Oliver Neumann 3 May 2017 at 11:12
Edited

Complete Sample:

QueryDispatcher.java
/*

  • To change this license header, choose License Headers in Project Properties.

  • To change this template file, choose Tools | Templates

  • and open the template in the editor.
    */
    package querytest;

import com.allaire.cfx.CustomTag;
import com.allaire.cfx.Query;
import com.allaire.cfx.Request;
import com.allaire.cfx.Response;
import com.allaire.cfx.DebugRequest;
import com.allaire.cfx.DebugResponse;

public class QueryTestDispatcher implements CustomTag {

public QueryTestDispatcher()
{
//epic!
}

@Override
public void processRequest(Request request, Response response) throws Exception
{

Query q = request.getQuery();

if (q == null)
{
response.write("No Query specified");
}
else
{

String[] queryHeaders = q.getColumnNamesAsString();
for (int row = 1; row <= q.getRowCount(); row++)
{

for (int col = 0; col < queryHeaders.length; col++)
{

String data = (q.getData(row, col + 1));
response.write(data);

}

}
}

}
}

Compile and Install CFX with Lucee Administrator

ColdFusion Template which uses Template:

<cfscript>
doc_items = QueryNew("one,two,three");
QueryAddRow(doc_items, 1);

for (fldname in doc_items.Columnlist) {

doc_items[fldname][1] = "";
}
</cfscript>
ONE
<cfx_testquery query="doc_items">
First works!
<cfscript> 
doc_items = QueryNew("one,two,three");
QueryAddRow(doc_items, 1);
</cfscript>

TWO
<cfx_testquery query="doc_items">
You wont see this!

Please let me know if you need and further instructions.

Pothys - MitrahSoft 2 May 2017 at 14:50

Hi ,

Yes , I've analyzed this ticket a lot & I couldn't able to reproduce the issue. I've tried with all above code working fine for me. It doesn't throw any error. Please attached some more details of the error. It helps me lot to find the issue.

Oliver Neumann 2 May 2017 at 11:45

Maybe I did not describe this error good enough.
At the moment Line 123 of Class: lucee.runtime.cfx.QueryWrap in function getData leads to an Exception, when a query is send to a CFX:

CF:

<cfset q = QueryNew("mycolumn1,mycolumn2")>
<cfset QueryAddrow(q, 1)>
<cfset QuerySetCell(q, "mycolumn1", "myvalue", 1)>

<cfx_myQueryClass myvar="#q#">

CFX:

myQueryClass handles q:

(...)

Query query = request.getQuery();
String[] queryHeaders = query.getColumnNamesAsString();

for (int row = 1; row <= query.getRowCount(); row++)
{
for (int col = 0; col < queryHeaders.length; col++)
{
String data = (query.getData(row, col + 1));
}
}

This will crash in Line:
if(o==NullSupportHelper.NULL()), because row 1 of column "mycolumn2" was not initialized.

Workaround is:
<cfset q = QueryNew("mycolumn1,mycolumn2")>
<cfset QueryAddrow(q, 1)>

<cfloop list="#q.ColumnList#" index="fname">
<cfset QuerySetCell(q, fname, "", 1)>
</cfloop>

<cfset QuerySetCell(q, "mycolumn1", "myvalue", 1)>

<cfx_myQueryClass myvar="#q#">

Do you need a complete example?

Duplicate

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 21 April 2017 at 09:42
Updated 18 July 2017 at 07:27
Resolved 18 July 2017 at 07:27