• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Query.ColumnList

Explorer ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

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

this statement from SQL then i got retun in order: categoryid, categoryname. But in coldusion when i
cfdump query i got it reverved : categoryname, categoyid. Is there the way to display it in oder like categoryid, categoryname?

Thanks
TOPICS
Advanced techniques

Views

3.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

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>
<tr>
<cfloop list="#colHeaderNames#" index="col" delimiters=",">
<th><cfoutput>#col#</cfoutput></th>
</cfloop>
</tr>
</table>

Phil

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

paross1 wrote:
> 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 ..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

> 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.


> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

Adam Cameron wrote:
> 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.

> 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 ;-)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

> Not the getMetaData() function _of_ a query object

*method* _of_ a query object

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 19, 2008 Aug 19, 2008

Copy link to clipboard

Copied

LATEST
> 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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation