Link to home
Start Free TrialLog in
Avatar of Garbonzo_Horowitz
Garbonzo_HorowitzFlag for United States of America

asked on

How To Create a Coldfusion Struct Using a Query

I would like to create a structure with the data from a query in coldfusion 9.
The data ultimatley needs to be put into a chart for display.
I can not get all of the needed data in my initial query because some of the fields are encrypted and so I have to decrypt them on the page to retrieve the actual values.
I want to create a structure to hold the initial data and the decrypted data and use that as a basis to fill a cfchart.
I'm having a little trouble with the syntax. I've previously have done this type of thing with an array but I'd like to use a structure.
Can you offer some advice on how to correctly create a struct from a cfquery?

This is what I have:

<cfquery name="somequery" >
    select field1, encryptedField2 from mytable
</cfquery>

<table>
<tr>
     <td>lable1</td>
     <td>lable2</td>
</tr>

<cfset MyStruct = StructNew()>
<cfset MyStruct.thing1 = "x">
<cfset Mystruct.thing2 = "y">

<cfoutput query="somequery">
    <cfset decryptedVal = #functionToDecrypt#>
    <tr>
         <td>#field1#</td>
        <td>#decryptedField2</td>
   </tr>

   <cfscript>
      StructInsert(MyStruct, "field1", field1)>
      StructInsert(Mystruct, "decryptedField2, DecryptedThing)>
   </cfscript>
</cfoutput>

</table>

<cfdump var="#MyStruct#">
Avatar of _agx_
_agx_
Flag of United States of America image

Ignoring the question of whether it's advisable to chart encrypted data in the 1st place .. a structure isn't always a good substitute for a query for two reasons. First, structures don't maintain the order of data like queries or arrays. Second, they don't allow duplicates. So it'd only work if there's unique key.

But .. I don't think you need to go through all that trouble. Just loop through the query and decrypt the values in place.  

          <cfloop query="someQuery">
                  <cfset someQuery.encryptedField2[currentRow] = decryptFunction( someQuery.encryptedField2)>
          </cfloop>
Avatar of Garbonzo_Horowitz

ASKER

I'm not having an issue decrypting.
All the data needed is being correctly displayed in an html table.
I'm just trying to stuff the results in a struct.
Perhaps a better solution would be to create another query object since the data will  ultimately be used in a chart.
SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok I see what you are saying. Just alter the value on the fly and don't bother with a differnet object. Thanks.