Solved

CFQuery column names case sensitive

Posted on 2014-10-31
5
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
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 …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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