Tip : Getting unsorted query columns in coldfusion
This one gave me a headache for 15 min, making all the possible tricks to make my query return the unsorted columns.
Generally Coldfusion always sort the columns in the query that has been returned, irrespective of the order you have specified in the SQL statement. Most of the time its a blessing, but not always.
There is no documented way to get the unsorted columns otherthan using some thirdparty customtags and function. But there is a tweak for this case.
Tweak #1
Use getMetaData() function to get the column list which is as per the sql statement which you have written.
<!--- use GetMetadata to get the names and data types of the fields in the cfdocexamples Employees table ---> <cfquery name="getemployees" datasource="cfdocexamples"> SELECT * FROM Employees </cfquery> <cfset employeemeta=getMetaData(getemployees)> <h4>The Employees table has the following columns</h4> <cfloop index="i" from="1" to="#arrayLen(employeemeta)#"> <cfoutput> #employeemeta[i].name# </cfoutput> </cfloop>
Tweak#2
Use queryObj.getColumnNames() function to get the unsorted list of column from the query. this function is not documented in CF docs. Thanks to Richard
<cfset queryColumnlist = ArrayToList( qryObj.getColumnNames() )>Tip : Show hide columns in cfdump
Small tip for the day, In Coldfusion MX7 the CFdump was pritty much dump that it just do the variable dump and nothing more.
CF8 dump is much more capable like writing the dump out to file like i did in my last blog , plus you even can control the fields that you need to show or hide during the dump. This could pretty much save time when dumping big queries which contains long columns
Continue
Tip : Using cfdump inside CFscript
One simple tip for the day, How to use cfdump inside the cfscript block !!!
cfscript block does not support cfdump tag or indeed any tag inside it. So the trick is to create function which dumps the value using cfdump and call the function inside cfscript by passing the variable as parameter.
Continue
Coldfusion 9 : Feature improvement history
Check out the new Coldfusion 9 feature comparison with its predecessors which includes CF8 and MX7. PDF download at the bottom of content.
Continue
Tip : Saving cfdump to file in coldfusion 8
![]()
coldfusion cfdump is the most favorite tag for almost all CF developers. but there are cases where using a cfdump will not make life much easier.
when creating a web service, dumping the sessions and application variable will be a problem. this is the same case when creating components which does not have an interface. Any method you have to debug with a cfdump should have to make a code walk-through.
Continue
Connect me
Recent Posts
- Tip : Getting unsorted query columns in coldfusion
- Tip : Show hide columns in cfdump
- Tip : Using cfdump inside CFscript
- What is Augmented Reality ?
- Coldfusion 9 : Feature improvement history
Categories
Blogroll
Tags
Archives
- February 2010 (2)
- January 2010 (5)
- December 2009 (5)
CF Libs
- DeMoronize September 2, 2010Fixes text using Microsoft Latin-1 "Extentions", namely ASCII characters 128-160. […]
- readPropertiesFile September 1, 2010Load and parse a .properties file into a struct […]
- lastDayofWeek August 30, 2010Returns last day of the week, assumes Saturday is the last day. […]
- sitemapPing August 26, 2010Ping multiple search engines with your sitemap.xml file and get the server response. […]
- isURL August 5, 2010A quick way to test if a string is a URL. […]
- indentXml July 30, 2010indentXml pretty-prints XML and XML-like markup without requiring valid XML. […]
- verifyMailServer July 1, 2010Verifies a mail server connection. […]
- getFunctionHint July 1, 2010You give me a function and I return the hint. Useful for demo and documentation pages. […]
- getUrlRelativeToWebRoot June 23, 2010Pass in file path to web root and a file and it returns URL relative to site root. […]

nerdscubecom