> -----Original Message-----
> From: Jared Rypka-Hauer - CMG, LLC [mailto:[EMAIL PROTECTED]
> Sent: Sunday, March 27, 2005 6:09 PM
> To: CF-Talk
> Subject: Re: Best practice question?
>
> > The odd thing is with queries should you use indexed notation you get a
> > different value.  While the value of "queryname.fieldname" is the value
> of
> > the first row the value of "queryname["fieldname"]" is actually a
> reference
> > the column - essentially a one dimensional array containing all of the
> rows
> > values.
> 
> Well, yeah, it's true... but it's actually a 2-dimensional array,
> because your column name is the first dimension. I may be being unduly
> picky, but these are issues where "getting it right" is the same as
> "getting it to work."

I think we're saying the same thing - the QUERY is a two dimensional array,
but the column is a one-dimensional array.

The result from queryname["fieldname"] is a one-dimensional array, not two.
 
> When using query["column"][rowNumber], you're effectively treating
> your entire query as a 2-dimensional array, whereas you're asserting
> that it treats the individual column as a one-dimensional array. It's
> a critical distinction, because query.column[1] should work as you've
> explained it, but it won't.

It does actually work just as I described (give it a try: query.column[1]
will give you the value from that column for the first row of the query).

Queryname["fieldname"][index] gives the exact same results as
queryname.fieldname[index].  In this case (accessing a single cell) indexed
and dot notation are equivalent and return the same values.

However queryname.fieldname returns the value of the first row of that
column while queryname["fieldname"] does not - it returns a one-dimensional
array of all the values in the column.  So in this case (accessing a column)
indexed and dot notations result in different values.

I'm sorry if I said something incorrectly - but the above is definitely what
I meant.

> > For most everything you can use this as an array.  To get the sum of a
> query
> > column, for example, you can do ArraySum(queryname["fieldname"]).
> >
> > This is a very powerful feature - but test it first.  CFMX had some
> minor
> > bugs with this related to the fact that in some cases it counted the
> array
> > from zero (as Java) and not from one (as CF).
> 
> And... something you don't see mentioned very often... this worked as
> far back as CF 4.x, it's not specifically a Java-derived feature, and

To take it further it actually worked BETTER in CF 4.5/5 since once CF went
to Java we began to see bugs in stuff like this since Java arrays are
counted from 0 natively.  It's still useful post-mx but just check out
first.

There were a lot of little annoying bugs in features like this due to
that... which reminds me that I've got to test CF 7 and see if they're still
there.  ;^)

> I've used it on SQL Server datasets that had spaces in the column
> names because this treats the first dimension of the array - the
> column name - as a string, which, being wrapped in quotes, resolves
> just fine where #spaces in this name# won't work no matter how you try
> to resolve it.

Exactly - this also applies to structs as well (naturally since internally a
query is a struct of arrays - the column name is the struct key).  You can
use indexed notation to use key or column labels that are not legal CF
variables names (contain spaces as you mention but also begin with numbers,
use odd punctuation characters or other odd things).

All told the breadth and ability of CF variables and data structures far
out-shadows any other language I've seen - but most people barely scratch
the surface.

Jim Davis




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:200167
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to