Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How To Create a Coldfusion Struct Using a Query

Posted on 2012-03-28
6
Medium Priority
?
352 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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 800 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 1200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Screencast - Getting to Know the Pipeline
Suggested Courses

773 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