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.
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>
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() )>
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 reading “Tip : Show hide columns in cfdump” »
Take it with you!
- Instant Method Finder : My first Coldfusion Builder extension!
- Create coldfusion builder snippets from cflib repository
- Tip:Difference between resistive and capacitive touch screen.
- Why QR code is cool and easy with smartphones !!!!!
- Tip : Getting unsorted query columns in coldfusion
- Coldfusion Builder
- Project Management
- Tips and Tricks
- composeDateTime May 3, 2013Creates a date time from optional date parts […]
- convertQueryStringToStruct April 6, 2013Converts a URL query string to a struct […]
- arrayDiff April 5, 2013Compares two arrays and returns the difference between the two. […]
- ArrayOfStructsSort April 4, 2013Sorts an array of structures based on a key in the structures. […]
- directoryCopy March 21, 2013Copies a directory. […]
- invokeRemoteMethodByJSON March 10, 2013Invoke a remote method using cfhttp and JSON proxy […]
- SmallCaps March 10, 2013Formats a string to simulate the small-caps style without using the css font-variant attribute. […]
- ArrayCartesianProduct March 10, 2013Returns a cartesian product (a join) of arbitrary number of arrays. […]
- listReFilterNoCase March 10, 2013Filters a target list, given a list of regex filters. […]