tracker issue : CF-3040896

select a category, or use search below
(searches all categories and all time range)
Title:

Bug 81968:CFQUERY doesn't use the datasource passed, it uses the datasource of the final CFQUERY before the closing /CFQUERY tag

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/

Reporter/Name(from Bugbase): Barney Boisvert / Barney Boisvert (barneyb)

Created: 02/03/2010

Components: Database, CFQuery

Versions: 9.0

Failure Type: Unspecified

Found In Build/Fixed In Build: 0000 /

Priority/Frequency: Major / Unknown

Locale/System: English / Platforms All

Vote Count: 1

Problem:

CFQUERY doesn't use the datasource passed, it uses the datasource of the final CFQUERY before the closing /CFQUERY tag.  If within a CFQUERY body, you call a UDF that does it's own CFQUERY, the UDF's CFQUERY's datasource will be used for the "outer" CFQUERY.  No matter if they're the same DSN, but if they're different DSNs it's a little wonky.
Method:

Here is a test case from my blog post about the issue (which I've included in the URL field):<cffunction name="getMsg">  <cfset var get = "" />  <cfquery datasource="dsn_A" name="get">    select count(*) as c    from test  </cfquery>  <cfreturn "(#get.c# records in dsn_A)" /></cffunction><cfquery datasource="dsn_A" name="">  insert into test (s) values (    'dsn_A - record 1'  )</cfquery><cfquery datasource="dsn_B" name="">  insert into test (s) values (    'dsn_B - record 1'  )</cfquery><cfquery datasource="dsn_A" name="get">  select * from test</cfquery><!--- one record, as you'd expect ---><cfdump var="#get#" label="dsn_A" /><cfquery datasource="dsn_B" name="get">  select * from test</cfquery><!--- one record, as you'd expect ---><cfdump var="#get#" label="dsn_B" /><cfquery datasource="dsn_A" name="">  insert into test (s) values (    'dsn_A - record 2 #getMsg()#'  )</cfquery><cfquery datasource="dsn_B" name="">  insert into test (s) values (    'dsn_B - record 2 #getMsg()#'  )</cfquery><cfquery datasource="dsn_A" name="get">  select * from test</cfquery><!--- three records!! (the two for dsn_A, plus dsn_B's second record) ---><cfdump var="#get#" label="dsn_A" /><cfquery datasource="dsn_B" name="get">  select * from test</cfquery><!--- one record!! (only dsn_B's first record) ---><cfdump var="#get#" label="dsn_B" />In order to run it, you'll need to two DSNs configured ("dsn_A" and "dsn_B"), pointed at two distinct databases, each with a 'test' table containing a single varchar column named 's'.
Result:

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3040896

External Customer Info:
External Company:  
External Customer Name: Barney Boisvert
External Customer Email: 555F4E26454CCDF099201549
External Test Config: 02/03/2010

Attachments:

Comments: