Solved

How To Create a Coldfusion Struct Using a Query

Posted on 2012-03-28
6
325 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Controlling printer trays from browser 3 151
Problem in SELECT Statement 5 77
Coldfusion Mysql get data from two tables 3 78
coldfusion, javascript onclick url update 4 46
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now