Discussion:
Query.ColumnList
(too old to reply)
kt03
2008-08-19 18:10:24 UTC
Permalink
<cfquery name="qTableSelected" datasource="#request.DSN#">
select * from #variables.tableSelected#
</cfquery>
<cfset curRow = 1>
<cfloop list="#qTableSelected.ColumnList#" DELIMITERS="," index="column">
<cfif curRow eq 1>
<cfset columnID = #column# /> <!---get ID--->
<cfelse><!---get name--->
<cfset columnName = #column# />

<cfloop query="qTableSelected">
#evaluate(columnName)#
</cfloop>
</cfloop>

I have table category (CategoryId, Category)
With the code above, I am displaying the columname not the column Id.
As currenlty, it's display the id but if from category table,
I change Category to CategoryName then it displays name not id. I don't
understand why
the column is matter and it needs to have the letter "Name" at the end in
order to
dispplay the name?
-==cfSearching==-
2008-08-19 18:35:44 UTC
Permalink
The column names are in alphabetical order by default. I have not used it, but try this function at cflib.org
http://cflib.org/udf/queryColumns
Adam Cameron
2008-08-19 18:38:21 UTC
Permalink
Id' try to help, but I can make neither head nor tail of what you're on
about. Can you reword? Forget how you're trying to do it, just explain
what you need done.
--
Adam
paross1
2008-08-19 20:12:22 UTC
Permalink
Want to see them in the "original" order? Use getColumnList() and ArrayToList()
instead of looking at ColumnList directly......

<cfquery name="qTableSelected" datasource="#request.DSN#">
select * from category
</cfquery>

<cfset colHeaderNames = ArrayToList(qTableSelected.getColumnList())>

<table border="1">
<tr>
<cfloop list="#colHeaderNames#" index="col" delimiters=",">
<th align="left" nowrap><cfoutput>#col#</cfoutput></th>
</cfloop>
</tr>

Phil
-==cfSearching==-
2008-08-19 20:19:57 UTC
Permalink
Post by paross1
Use getColumnList()
Personally my preference would be the udf. If only because it uses a documented function. Though getColumnList() may well be what CF uses internally ..
Adam Cameron
2008-08-19 21:29:41 UTC
Permalink
Post by -==cfSearching==-
Personally my preference would be the udf. If only because it uses a documented function.
Since when was the getMetadata() method of a *query object* a "documented"
function? Any more than getColumnList() is, I mean?

The only reference to getMetadata() I can see in the docs is for this:
http://livedocs.adobe.com/coldfusion/8/buildingComponents_38.html

Which is a completely different function.

There's nothing else in the docs index for getMetadata() under "G":
http://livedocs.adobe.com/coldfusion/8/htmldocs/index_8.html

As far as I know all exposed methods of the the Java objects underlying the
CF data types are "tread with caution" because there's no guarantee they
will be implemented from one version of CF to the next.
Post by -==cfSearching==-
Though getColumnList() may well be what CF uses internally ..
I would say it almost certainly does. It seems unlikely they'd implement
it for no reason ;-)

I prefer Phil's way because it's tidier than the UDF at CFLib.
--
Adam
-==cfSearching==-
2008-08-19 21:44:40 UTC
Permalink
Post by Adam Cameron
Since when was the getMetadata() method of
a *query object* a "documented" function?
Not the getMetaData() function _of_ a query object, but the CF function. It
supports query objects.
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000488.htm#1105179. That is
what I use in my custom function. But you are right about the udf. I only
glanced at it quickly, and mistakenly thought they were using the CF
getMetaData function like I was.
Post by Adam Cameron
I would say it almost certainly does. It seems unlikely they'd implement
it for no reason ;-)
I prefer Phil's way because it's tidier than the UDF at CFLib.
Probably. But having stupidly written code that depended on some undocumented
functionality.. and not surprisingly getting burned .. I will stick with the CF
getMetaData() function thank you ;-)
-==cfSearching==-
2008-08-19 21:49:33 UTC
Permalink
Post by -==cfSearching==-
Not the getMetaData() function _of_ a query object
*method* _of_ a query object
Adam Cameron
2008-08-19 22:21:55 UTC
Permalink
Post by -==cfSearching==-
but the CF function. It
supports query objects.
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000488.htm#1105179.
I'm glad you pointed me back at this. I recalled something about queries,
but only got as far as reading "CFC" when I looked it up just before, so
decided I must've been getting my wires crossed with the object method.
But no, there is is: works on queries too.

Cheers for the nudge.
--
Adam
Loading...