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?
 
dapperryConnect With a Mentor Commented:
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
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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
 
nathansCommented:
Are you still reading this John Drake?

What is the goal of your question?
0
 
nathansCommented:
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
All Courses

From novice to tech pro — start learning today.