Solved

CFQuery column names case sensitive

Posted on 2014-10-31
5
193 Views
Last Modified: 2014-11-01
When  doing a CFDUMP on CFQUERY, the column names are always displayed in UPPERCASE.

Is it possible to get the column names of CFQUERY is the case they were created on an SQL server ?

Example
CREATE TABLE [dbo].[LOGIN](
      [lgId] [int] IDENTITY(1,1) NOT NULL,
      [lgUserId] [nvarchar](64) NULL,
      [lgPassword] [nvarchar](128) NULL,
      [lgRole] [nvarchar](16) NULL,
.........

Is it possible for CFQUERY to return the column names as lgId, lgUserId, lgPassword etc... and not LGID, LGUSERID, LGPASSWORD?
0
Comment
Question by:Errol Farro
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 40416277
is there a specific reason for this
0
 

Author Comment

by:Errol Farro
ID: 40416312
The reason is that we have ColdFusion  program which creates an excel file. The excel file is then uploaded onto a hosted server using a proprietary tool. The proprietary tool requires the cases of the Excel column names  and the hosted table to be the same.

I know we can use qryMae.getMetaData().getColumnLabels(), but how do I get the case name of the case sensitive column in the query instead of the upper case name CFQUERY produces.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40416490
Unfortunately CF doesn't provide a simple (documented) way to access the original column names from queries. As you noted, query.columnList is always upper case - and in alphabetical order.

>> I know we can use qryMae.getMetaData().getColumnLabels(),

I know it returns an array, but doesn't that work for you? When used with a regular db query it returns the correct case and column order. To generate your list, just arrayToList().

The only other way I know of is to use the getMetaData() function. It returns an array of the name, datatype, etc...  But that seems like a longer version of what you suggested already. Am I missing something?

<cfset meta = getMetadata(q)>
<cfset colNames = "">
<cfloop array="#meta#" index="col">
	<cfset colNames = listAppend(colNames, col.name)>
</cfloop>

Open in new window

0
 

Author Comment

by:Errol Farro
ID: 40416547
Your solution will work.


Strategy is to use CFQUERY to create Excel with upper case header and then with the data obtained from getMetaData()   replace the first row of the Excel spreadsheet with case sensitive fields.

How do I update the first row of an Excel spreadsheet ?
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 40416625
Depends on how you're generating the spreadsheet.  But based on your previous question, let's assume you have a variable containing a spreadsheet object already ie "yourSheet". Use SpreadsheetAddRow to overwrite the values in the first row.  

    <!--- Important: Set the last parameter to FALSE ie overwrite instead of insert --->
    <cfset SpreadsheetAddRow(yourSheet, commaDelimitedListOfColumnNames, 1, 1, false)>

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now