Solved

How To Create a Coldfusion Struct Using a Query

Posted on 2012-03-28
6
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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