Best Practice: Looping over a query in cfscript?

2008-11-20 Thread Andy Matthews
So yesterday I was working in cfscript and needed to loop over a query. I
reviewed my options and decided for elegance sake that a for / in loop was
choice. Only problem is that for / in loops in cfscript can't be used with
query objects. After trying a few things, I fell back and punted with the
following code:

 

qGetTheme = siteGW.GetSiteThemeValuesByThemeID(ARGUMENTS.themeID);

colList = qGetTheme.columnlist;

for ( item=1;item = ListLen(colList);item++ ) {

SiteInfo.theme[ListGetAt(colList,item)] =
qGetTheme[ListGetAt(colList,item)][1];

}

 

I know this works, and is perfectly legit, but I'd love to see if there's a
better way of doing this in cfscript. Anyone?

 

 

 

Andy 




~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315675
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: Best Practice: Looping over a query in cfscript?

2008-11-20 Thread Dominic Watson
Hm, I'd think I'd do that loop the same way with cfloop - there is no
cfloop shortcut for looping over the query columns. What you have
there is fine though I would personally use an array instead of a list
in the loop as it is generally more efficient and easier to read in my
opinion:

qGetTheme = siteGW.GetSiteThemeValuesByThemeID(ARGUMENTS.themeID);

cols = ListToArray( qGetTheme.columnlist );
nCols = ArrayLen(cols);

for ( item=1;item = nCols; item++ ) {
SiteInfo.theme[ cols[item] ] = qGetTheme[ cols[item] ][1];
}

Looping over the rows of the query would be slightly different
however. Here is a neat but undocumented way to loop a query in
cfscript:

cfscript
foo = QueryNew('');
bar = [1,2,3,4];
QueryAddColumn(foo,'bar','integer',bar);

while(foo.next()){
writeoutput(foo.bar[foo.getCurrentRow()]);
}
/cfscript

Output would be: 1234

HTH

Dominic


2008/11/20 Andy Matthews [EMAIL PROTECTED]:
 So yesterday I was working in cfscript and needed to loop over a query. I
 reviewed my options and decided for elegance sake that a for / in loop was
 choice. Only problem is that for / in loops in cfscript can't be used with
 query objects. After trying a few things, I fell back and punted with the
 following code:



 qGetTheme = siteGW.GetSiteThemeValuesByThemeID(ARGUMENTS.themeID);

 colList = qGetTheme.columnlist;

 for ( item=1;item = ListLen(colList);item++ ) {

SiteInfo.theme[ListGetAt(colList,item)] =
 qGetTheme[ListGetAt(colList,item)][1];

 }



 I know this works, and is perfectly legit, but I'd love to see if there's a
 better way of doing this in cfscript. Anyone?







 Andy




 

~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315681
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


Re: Best Practice: Looping over a query in cfscript?

2008-11-20 Thread Jason Fisher
This isn't looping over the query, though, right?  It's looping over the 
columns in the first row only. Looks like the SiteInfo.theme struct is simply a 
mirror of the first row of the query when all is said and done.  Is that what 
you're going for?


~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315680
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


RE: Best Practice: Looping over a query in cfscript?

2008-11-20 Thread Andy Matthews
You're right...with cfscript though, you can't easily loop over the query,
at least not in what I'd consider an elegant way.

-Original Message-
From: Jason Fisher [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 20, 2008 9:22 AM
To: cf-talk
Subject: Re: Best Practice: Looping over a query in cfscript?

This isn't looping over the query, though, right?  It's looping over the
columns in the first row only. Looks like the SiteInfo.theme struct is
simply a mirror of the first row of the query when all is said and done.  Is
that what you're going for?




~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315693
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


RE: Best Practice: Looping over a query in cfscript?

2008-11-20 Thread Andy Matthews
NICE

That's the sort of thing I'm looking for Dominic! Thanks!

-Original Message-
From: Dominic Watson [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 20, 2008 9:24 AM
To: cf-talk
Subject: Re: Best Practice: Looping over a query in cfscript?

Hm, I'd think I'd do that loop the same way with cfloop - there is no
cfloop shortcut for looping over the query columns. What you have
there is fine though I would personally use an array instead of a list
in the loop as it is generally more efficient and easier to read in my
opinion:

qGetTheme = siteGW.GetSiteThemeValuesByThemeID(ARGUMENTS.themeID);

cols = ListToArray( qGetTheme.columnlist );
nCols = ArrayLen(cols);

for ( item=1;item = nCols; item++ ) {
SiteInfo.theme[ cols[item] ] = qGetTheme[ cols[item] ][1];
}

Looping over the rows of the query would be slightly different
however. Here is a neat but undocumented way to loop a query in
cfscript:

cfscript
foo = QueryNew('');
bar = [1,2,3,4];
QueryAddColumn(foo,'bar','integer',bar);

while(foo.next()){
writeoutput(foo.bar[foo.getCurrentRow()]);
}
/cfscript

Output would be: 1234

HTH

Dominic


2008/11/20 Andy Matthews [EMAIL PROTECTED]:
 So yesterday I was working in cfscript and needed to loop over a query. I
 reviewed my options and decided for elegance sake that a for / in loop was
 choice. Only problem is that for / in loops in cfscript can't be used with
 query objects. After trying a few things, I fell back and punted with the
 following code:



 qGetTheme = siteGW.GetSiteThemeValuesByThemeID(ARGUMENTS.themeID);

 colList = qGetTheme.columnlist;

 for ( item=1;item = ListLen(colList);item++ ) {

SiteInfo.theme[ListGetAt(colList,item)] =
 qGetTheme[ListGetAt(colList,item)][1];

 }



 I know this works, and is perfectly legit, but I'd love to see if there's
a
 better way of doing this in cfscript. Anyone?







 Andy




 



~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315694
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4


RE: Best Practice: Looping over a query in cfscript?

2008-11-20 Thread Chuck
Here is how I loop over a query in cfscript. Quick, simple and easy.

cfscript
// Create Query
myQry =
QueryNew(ColumnA,ColumnB,ColumnC,VarChar,VarChar,VarChar);
// Load Query With Data
for (i=1; i LTE 10; i=i+1){
QueryAddRow(myQry, 1);
QuerySetCell(myQry, ColumnA, RandRange(1, 2), i);
QuerySetCell(myQry, ColumnB, RandRange(1, 2), i);
QuerySetCell(myQry, ColumnC, RandRange(1, 2), i);
}
/cfscript
!--- Dump the Query to see what is in the recordset ---
cfdump var=#myQry#
cfscript
// Loop Over Query and write out the data
for (q=1; q LTE myQry.RecordCount; q=q+1){
writeoutput(myQry.ColumnA[q]   -- );
writeoutput(myQry.ColumnB[q]   -- );
writeoutput(myQry.ColumnC[q]  br /);
}
/cfscript


~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315747
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4


Re: Looping over a query with CFSCRIPT

2002-03-26 Thread Sharon DiOrio

More like:

cfscript
for (i=1; i LTE selProd.recordcount; i=i+1) {
writeOutput(selProd.PR_NAME[i]  br);
}
/cfscript

Sharon
- Original Message -
From: VAN VLIET, SCOTT E (SBCSI) [EMAIL PROTECTED]
To: CF-Talk [EMAIL PROTECTED]
Sent: Monday, March 25, 2002 6:47 PM
Subject: Looping over a query with CFSCRIPT


 Is this possible?  If so, sample code would be appreciated.

 I tried the following, and got an access error (i understand that you
can't
 modify currentrow, etc, but one can wish, right ^_^):

 cfscript
  while (selProd.CurrentRow LTE selProd.RecordCount)
  {
   writeOutput(selProd.PR_NAME);
   writeOutput(br);
   selProd.CurrentRow = selProd.CurrentRow + 1;
  }
 /cfscript

 Thanks in advance!

 --
 SCOTT VAN VLIET
 SENIOR ANALYST
 SBC SERVICES, INC
 Tel: 858.886.3878
 Fax: 858.653.6763
 Email: [EMAIL PROTECTED]
 
__
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists



Looping over a query with CFSCRIPT

2002-03-25 Thread VAN VLIET, SCOTT E (SBCSI)

Is this possible?  If so, sample code would be appreciated.

I tried the following, and got an access error (i understand that you can't
modify currentrow, etc, but one can wish, right ^_^):

cfscript
 while (selProd.CurrentRow LTE selProd.RecordCount)
 {
  writeOutput(selProd.PR_NAME);
  writeOutput(br);
  selProd.CurrentRow = selProd.CurrentRow + 1;
 }
/cfscript

Thanks in advance!

-- 
SCOTT VAN VLIET 
SENIOR ANALYST 
SBC SERVICES, INC 
Tel: 858.886.3878 
Fax: 858.653.6763 
Email: [EMAIL PROTECTED]
__
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists



Re: Looping over a query with CFSCRIPT

2002-03-25 Thread Michael Dinowitz

http://www.houseoffusion.com/docs/cfscript.htm
note 8.7

At 06:47 PM 3/25/02, you wrote:
Is this possible?  If so, sample code would be appreciated.

I tried the following, and got an access error (i understand that you can't
modify currentrow, etc, but one can wish, right ^_^):

cfscript
 while (selProd.CurrentRow LTE selProd.RecordCount)
 {
  writeOutput(selProd.PR_NAME);
  writeOutput(br);
  selProd.CurrentRow = selProd.CurrentRow + 1;
 }
/cfscript

Thanks in advance!

-- 
SCOTT VAN VLIET 
SENIOR ANALYST 
SBC SERVICES, INC 
Tel: 858.886.3878 
Fax: 858.653.6763 
Email: [EMAIL PROTECTED]

__
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists



RE: Looping over a query with CFSCRIPT

2002-03-25 Thread VAN VLIET, SCOTT E (SBCSI)

Many Thanks ^_^

-- 
SCOTT VAN VLIET 
SENIOR ANALYST 
SBC SERVICES, INC 
Tel: 858.886.3878 
Fax: 858.653.6763 
Email: [EMAIL PROTECTED]


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 25, 2002 3:56 PM
To: CF-Talk
Subject: Re: Looping over a query with CFSCRIPT


http://www.houseoffusion.com/docs/cfscript.htm
note 8.7

At 06:47 PM 3/25/02, you wrote:
Is this possible?  If so, sample code would be appreciated.

I tried the following, and got an access error (i understand that you can't
modify currentrow, etc, but one can wish, right ^_^):

cfscript
 while (selProd.CurrentRow LTE selProd.RecordCount)
 {
  writeOutput(selProd.PR_NAME);
  writeOutput(br);
  selProd.CurrentRow = selProd.CurrentRow + 1;
 }
/cfscript

Thanks in advance!

-- 
SCOTT VAN VLIET 
SENIOR ANALYST 
SBC SERVICES, INC 
Tel: 858.886.3878 
Fax: 858.653.6763 
Email: [EMAIL PROTECTED]


__
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists