Data Types of Fields

When I run a query using the CFQUERY tag is there anyway to find out the datatypes of the fields returned by the CFQUERY ?

I would be grateful for all help offered regarding this.

Thanks in advance

John Clarke
johnclarkeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BrigidCommented:
I've never heard of this being done. Usually you know what datatypes you're dealing with, I guess!
I looked up the CFQUERY tag in the CMFL Language Reference in Studio. There aren't any parameters to deal with that, and none of the four variables returned (RecordCount, CurrentRow, ColumnList, and ExecutionTime) do what you're asking.
You might be able to find a custom tag that deals with ColumnList to search out the datatypes.
A good place to start is under the Developer|Developer's Exchange|Custom Tags|Search Custom Tags area of the Allaire site: http://www.allaire.com

Good luck, and let me know if you find what you're looking for. I'd like to know how it's done!
0
dapperryCommented:
Well if you have the MS Jet installed on your server machine, you could use DAO and CFOBJECT to return the field types.  Here's an example:

<CFSET SQLString="SELECT * FROM MyTable">
<CFOBJECT Action="create" name="DBEngine" Class="DAO.DBEngine.35">

'Use this cfset if going to a server odbc source          
<CFSET db=DBEngine.OpenDatabase("",1,0,"#ODBCConnectString#")>

'If going to a file based odbc source use this cfset (eg Access)
'DSNFile being the path and filename
<CFSET db=DBEngine.OpenDatabase("#DSNFile#",0)>
 
<CFSET qdf=db.CreateQueryDef("","#SQLString#")>
<CFSET fields=qdf.fields>
<CFLOOP COLLECTION="#fields#" ITEM=fld>
      <CFOUTPUT>
      #fld.Type#
       </CFOUTPUT>
</CFLOOP>

Now I haven't tested this code directly, so it might need an adjustment or two, but thats the idea.  Let me know if this works for you.

:) dapperry
0
rod_nolanCommented:
Just to add to the thread, I just ran across an article in the Allaire Support Forums called "Finding column types dynamically?". Hope it helps lead you to the solution.

(http://forums.allaire.com/DevConf/Index.cfm?Message_ID=376678)
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

dapperryCommented:
johnclarke,
       How are you doing on this problem?

:) dapperry
0
beregothCommented:
If there is no direct CF Method to get the information directly from a returned recordset from a CFQUERY, I would recommend a stored procedure (depending on the data platform) that will accept the table.field combination and search the data dictionary for the information then return back what you need.

Or, and this is a little overkill, join in that data in the query itself.  It means a lot of extra data but it would work pretty simply.
0
Nathan Stanford SrSenior ProgrammerCommented:
Are you still reading this John Drake?

What is the goal of your question?
0
Nathan Stanford SrSenior ProgrammerCommented:
He is not reading this.
0
dapperryCommented:
Apparently so Nathans.  I thought I gave a workable solution too.

:) dapperry
0
beregothCommented:
Ooo, I like dapperry's answer too...thanks.  I feel like such a cheat.
0
OttaCommented:
Somebody should post an "answer" to this question, so that (eventually!) the "auto-grader" software will "accept" the answer, and award the answer-points.
0
dapperryCommented:
Ok I will.  JohnClarke, if you decide you don't like my answer by all means reject it.  Hope it all worked out for you.

:) dapperry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.