Solved

CFQuery column names case sensitive

Posted on 2014-10-31
5
205 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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