Skip to main content
Participating Frequently
November 11, 2008
Question

problem with struct and cf8

  • November 11, 2008
  • 13 replies
  • 1388 views
Hello everyone

I have following cf script (see bottom) with the following problem: I' never get the two structs in the 2nd row of the query. Should be the last dump.
In cf 7 it works fine. But in cf8 i allways get with #myQuery.Advanced[2]# the second struct of the first row. why that??? It seems to be a bug?!?

thanks for your help!

__________________________________________



<cfset strPerson1 = structNew()>
<cfset strPerson1.firstName = "Jean">
<cfset strPerson1.lastName = "Dupont">
<cfset strPerson1.city = "Paris">

<cfset strPerson2 = structNew()>
<cfset strPerson2.firstName = "Pierre">
<cfset strPerson2.lastName = "Lemont">
<cfset strPerson2.city = "Provence">


<cfset strPerson = structNew()>
<cfset strPerson[1] = strPerson1>
<cfset strPerson[2] = strPerson2>





<cfset str1Person1 = structNew()>
<cfset str1Person1.firstName = "Jean1">
<cfset str1Person1.lastName = "Dupont1">
<cfset str1Person1.city = "Pari1s">

<cfset str1Person2 = structNew()>
<cfset str1Person2.firstName = "Pierre1">
<cfset str1Person2.lastName = "Lemont1">
<cfset str1Person2.city = "Provenc1e">


<cfset str1Person = structNew()>
<cfset str1Person[1] = str1Person1>
<cfset str1Person[2] = str1Person2>


<cfset myQuery = QueryNew("Name, Time, Advanced")>

<cfset newRow = QueryAddRow(MyQuery, 2)>

<!--- Set the values of the cells in the query --->
<cfset temp = QuerySetCell(myQuery, "Name", "The Wonderful World of CMFL", 1)>
<cfset temp = QuerySetCell(myQuery, "Time", "9:15 AM", 1)>
<cfset temp = QuerySetCell(myQuery, "Advanced", strPerson, 1)>
<cfset temp = QuerySetCell(myQuery, "Name", "CFCs for Enterprise Applications", 2)>
<cfset temp = QuerySetCell(myQuery, "Time", "12:15 PM", 2)>
<cfset temp = QuerySetCell(myQuery, "Advanced", str1Person, 2)>


<cfdump var="#myQuery#">

<cfoutput>structcount: #structCount(myQuery.Advanced[2])#</cfoutput>


<cfdump var="#myQuery.Advanced[2]#">
<cfabort>

This topic has been closed for replies.

13 replies

Inspiring
November 11, 2008
Yes, it does seems like a possible bug. But .. I do not recall reading any documentation about the expected behavior when storing structures in query, or if that is even recommended. While it seems valid to me (it is just an object), I have not read any guarantees about this one way or the other.

> i can't change my structure keys, this is set automaticyle while
> i fill a structure dynamic.

How are you setting the keys? They do not have to be "A","B","C". Just appending any non-numeric character should do it. ie So the key itself is not numeric. Example: "1c", "2c", "3c", ...

tbrandenAuthor
Participating Frequently
November 11, 2008
thanks for your answer.

but the problem is, i can't change my structure keys, this is set automaticyle while i fill a structure dynamic. And looping is also not solving the problem, because i need for example exacty only the second row. so it's not very performant when i always loop through the entire query.

isn't that very strange? in fact in cf7 it works with the same code!
Inspiring
November 11, 2008
Whatever the issue, it seems to be related to the usage of array notation and the fact that your structure keys are numeric. It yields the expected results using cfloop:

<cfloop query="myQuery">
<cfset obj = myQuery.Advanced>
<cfdump var="#obj#" label="CFLOOP Row #currentRow#">
</cfloop>

.. or if you change the structure keys to strings like "A" and "B" instead of 1 and 2