I faced with some problem recently which could not solve by googling. The problem was looking simple: how to get actual database name by coldfusion datasource name? OK in CF 8 Scorpio there is new <cfdbinfo> tag which I thought would work but it does something strange: when tried to query <cfdbinfo datasource="#REQUEST.ds#" type="dbnames" name="res"> it alphabetically lists all the databases connected to any of datasources instead of retrieving the only database name of the parameter datasource "#REQUEST.ds#". So I had no choice and setup my own solution: <CFFUNCTION name="GetDBbyDS" access="remote" returntype="string"> <cfargument name="ds" type="string" required="Yes"> <cfset res=""> <CFIF fileexists("#SERVER.Coldfusion.rootdir#lib eo-datasource.xml")> <CFFILE action="read" file="#SERVER.Coldfusion.rootdir#lib eo-datasource.xml" variable="wds"> <CFWDDX action="wddx2cfml" input="#wds#" output="resds"> <CFLOOP collection="#resds[1]#" item="c"> <cfif c is ARGUMENTS.ds> <CFSET curdts=structfind(resds[1],c)> <CFSET keystostruct=structkeyarray(curdts)> <CFLOOP from="1" to="#ArrayLen(keysToStruct)#" index="i"> <cfif isstruct(curdts[keysToStruct[i]])> <cfset res=curdts[keysToStruct[i]]["database"]> <cfreturn res> </cfif> </CFLOOP> </cfif> </CFLOOP> </cfif> <cfreturn res> </CFFUNCTION> This works ok for me and not in CF Scorpio only. Hope this may help someone. - cheers, |
| |
| BRIEF DESCRIPTION: how to get database name from coldfusion datasource |
|
|
| |
Add your review to this item: |
|
|
|