Solved

How To Create a Coldfusion Struct Using a Query

Posted on 2012-03-28
6
330 Views
Last Modified: 2012-03-29
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#">
0
Comment
Question by:Garbonzo_Horowitz
  • 3
  • 2
6 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 37779869
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>
0
 

Author Comment

by:Garbonzo_Horowitz
ID: 37780626
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.
0
 

Author Comment

by:Garbonzo_Horowitz
ID: 37780763
Perhaps a better solution would be to create another query object since the data will  ultimately be used in a chart.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 200 total points
ID: 37781874
> I want to create a structure to hold the initial data and the decrypted data

what is "initial data" ? is that then encrypted value from the query?

If you want to use that as your Key for the structure, it would look like this..

   <cfset decryptedVal = #functionToDecrypt#>

   <cfset myStruct[someQuery.encryptedField2] = decryptedVal>


But I would agree with agx, you may be able to skip this
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 300 total points
ID: 37782656
I'm not having an issue decrypting.

I think you may have misunderstood. What I'm saying is I don't think you need an extra structure (or query) just to create a chart. You can change the values of an existing query in code. Just loop through it and overwrite/decrypt the values. Then you can feed that same query into your chart.  Unless there's more to it, you don't need any extra objects.
0
 

Author Closing Comment

by:Garbonzo_Horowitz
ID: 37782940
Ok I see what you are saying. Just alter the value on the fly and don't bother with a differnet object. Thanks.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question