Jay my reference using the attributes scope was a typo, it should have been
application scope... It should read:
   application.getProductDetails[Attributes.PdtID].Price
Since I declared the structure with application scope.

In order to output the all of the product details you need to know all of
the key's (all of your ProductID's) and then you can just loop through them.
In our situation, we used an Array to contain each structure.  Some
programmers prefer to use structures that contain structures, and in this
case it may be more beneficial, because we have Function StructKeyList()
that returns all of the key's to a structure.  There isn't a function in CF
4 that does this for arrays. One way around this is to create a variable
that stores the current keys of the array, when the array is created.  For
simplicity reasons you may be better off using nested structures, instead of
the array structure.  However I ran a few tests and found that Array's can
access it's members about 10 to 15% faster than a structure can (using
integers as key's on CF 4.0.1).  That's why I prefer the array/structure
model.  So when making the decision, consider that if you plan on using
array/structure and need to output the entire table, then you will either
have to carry around an application variable containing the values, or
perform a real time lookup.

One final thing to remember is that when the table is modified (INSERT,
UPDATE, or DELETE) you will also need to update your structure.


_______________________________________________
Pete Freitag
CFDEV.COM
Cold Fusion Developer Resources
http://www.cfdev.com/


-----Original Message-----
From: Jay Sudowski [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 23, 2000 12:42 AM
To: [EMAIL PROTECTED]
Subject: Fw: Query Cache Question


This is a message I sent this weekend but was bounced ..... I'm still
curious about structures :-)

----- Original Message -----
From: Jay Sudowski <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 21, 2000 1:48 PM
Subject: Re: Query Cache Question


> Hey Pete,
>
> Thanks for the structure example :-).  I have a few questions though -
> seeing as how the whole purpose of the structure is to avoid hitting the
> database, how would I go about outputting an entire list of products from
> the structure?  Or say, just a list of products in a certain category?  I
> guess I could query the db for just product ID's and then loop through the
> structure, but that pretty much defeats the purpose of a structure, huh?
>
> Also, in the <cfoutput> section of the code, why do you refer to the
> structure as attributes.getProductDetails?  Would it still work if I used
> application.getProductDetails ...?
>
> I've never used structures before, but its apparent they're lots more
> efficient than hitting that database again and again for the same info, so
> go easy on me, huh? <g>
>
> Thanks,
>
> Jay
>
> ----- Original Message -----
> From: Pete Freitag <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, April 20, 2000 2:31 AM
> Subject: RE: Query Cache Question
>
>
> > This is a good example of a query not to cache this way, let me explain
> > why...
> > Your idea with the dynamic query name shows that you have an idea why
this
> > might not work. It will cache the query in memory with the value that
you
> > first executed it with.  Keep in mind that cold fusion can only have 100
> > queries cached at once, so you don't want to use them all up in one
place.
> >
> > Here's how I would solve your situation...
> > <cfif NOT IsDefined("Application.getProductDetails")>
> > <cfquery name="getProductDetails" datasource="xyz">
> >    SELECT * FROM Product
> > </cfquery>
> > <cfset application.getProductDetails = ArrayNew(1)>
> > <cfoutput query="getProductDetails">
> > <cfset application.getProductDetails[Pdt_ID] = StructNew()>
> > <cfset application.getProductDetails[Pdt_ID].ProductName = ProductName>
> > <cfset application.getProductDetails[Pdt_ID].Price = Price>
> > <cfset application.getProductDetails[Pdt_ID].fieldname = fieldname>
> > <cfset application.getProductDetails[Pdt_ID].etc = etc>
> > <!--- include all the fieldnames for your table --->
> > </cfoutput>
> > </cfif>
> >
> > Now you can refer to a field based on your primary key, like this...
> >
> >
>
<cfoutput>#attributes.getProductDetails[Attributes.PdtID].Price#</cfoutput>
> >
> >
> > _______________________________________________
> > Pete Freitag
> > CFDEV.COM
> > Cold Fusion Developer Resources
> > http://www.cfdev.com/
> >
> > -----Original Message-----
> > From: Ken M. Mevand [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, April 20, 2000 2:01 AM
> > To: 02 cf-talk
> > Subject: Query Cache Question
> >
> >
> > lets say i have a query :
> >
> > <CFQUERY NAME="getProductDetails" DATASOURCE="xyz"
> > CACHEWITH="#CreateTimeSpan(0,1,0,0)#">
> >     SELECT * FROM Product WHERE Pdt_ID = #Attributes.PdtID#
> > </CFQUERY>
> >
> > thus, for every product request, this query will be recached since the
> query
> > statement will be different. would it be better to rename the query to
> > something like NAME="getProductDetails_#Attributes.PdtID#" instead?
> >
> > thanks
> >
> >
>

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to