Solved

How To Create a Coldfusion Struct Using a Query

Posted on 2012-03-28
6
324 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Airline check in kiosk 4 90
Build PDF in coldfusion 2 57
cfchart display 12 91
Coldfusion Datefield problem 2 85
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…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

18 Experts available now in Live!

Get 1:1 Help Now