tracker issue : CF-3126664

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

cfquery datasource attribute leak / scoping issue

| View in Tracker

Status/Resolution/Reason: Closed/Won't Fix/

Reporter/Name(from Bugbase): Jason Troy / Jason Troy (Jason Troy)

Created: 02/29/2012

Components: Database

Versions: 9.0

Failure Type: Data Corruption

Found In Build/Fixed In Build: 9.0 /

Priority/Frequency: Critical / All users will encounter

Locale/System: English / Win XP All

Vote Count: 4

Problem Description:
When you call function from a cfquery tag that executes another query, the (datasource) attribute is overwritten. This leads to unpredictable results when using multiple datasources/attributes. 

Steps to Reproduce:
- Setup two datasources (one with SELECT ONLY permission). 

<!--- MySQL Table: 
CREATE TABLE `dsn_test` (
  `id` int(10) unsigned NOT NULL,
  `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Datasources: 
      #DS_write# allows (READ/WRITE)
      #DS_read# allows (READ)
--->


<cftry>
      <cfset DS_write = 'writeable'>
      <cfset DS_read = 'readonly'>
      <!--- setup functions --->
      <cffunction name="getCount" returntype="numeric" access="public" output="no">
            <cfargument name="DSN" type="string" required="yes">
            <cfset var ret = "">
            <cfquery name="ret" datasource="#DSN#">
                  select count(*) as num from dsn_test
            </cfquery>
            <cfreturn ret.num>
      </cffunction>
      <cffunction name="getData" returntype="query" access="public" output="no">
            <cfargument name="DSN" type="string" required="yes">
            <cfset var ret = "">
            <cfquery name="ret" datasource="#DSN#">
                  select * from dsn_test
            </cfquery>
            <cfreturn ret>
      </cffunction>
      
      <!--- show me the data --->
      <cfdump var="#getData(DS_read)#" label="current data">

      <!--- insert it using DS_read on getCount() --->
      <cfquery name="logit" datasource="#DS_write#">
            INSERT INTO dsn_test 
            (id) 
            VALUES 
            (<cfqueryparam cfsqltype="cf_sql_integer" value="#getCount(DS_read)#">)
      </cfquery>

      <!--- show me the updated data --->
      <cfdump var="#getData(DS_read)#" label="updated data">

<cfcatch type="any">
      <cfdump var="#cfcatch#" label="catch info">
      <!--- insert it using DS_write on getCount() --->
      <cfquery name="logit" datasource="#DS_write#">
            INSERT INTO dsn_test 
            (id) 
            VALUES 
            (<cfqueryparam cfsqltype="cf_sql_integer" value="#getCount(DS_write)#">)
      </cfquery>
      <!--- show me the updated data --->
      <cfdump var="#getData(DS_read)#" label="updated data">
</cfcatch>
</cftry>

Actual Result:
It will not insert into the WRITE datasource because its trying to use the READ datasource

Expected Result:
It should use the WRITE datasource and not have overwritten the attribute.

Any Workarounds:
None. Must set variables prior to cfquery tag.

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

Watson Bug ID:	3126664

External Customer Info:
External Company:  
External Customer Name: Phillyun44
External Customer Email:  
External Test Config: My Hardware and Environment details: N/A



This bug has been confirmed in CF8 and CF9.

Attachments:

Comments:

I have seen this problem in production.
Vote by External U.
20472 | February 29, 2012 01:29:42 PM GMT
I've encountered this before and it can be annoying to troubleshoot if it's the first time you've ever encountered as it is not something that jumps out at you.
Vote by External U.
20473 | March 01, 2012 03:50:28 PM GMT
Confirmed - seen it in production
Vote by External U.
20474 | March 01, 2012 05:07:18 PM GMT
I have also seen this, it is a major nuisance.
Vote by External U.
20475 | March 01, 2012 05:32:22 PM GMT
This was an issue in ColdFusion 9. It has been fixed in ColdFusion 10
Comment by Akhila K.
20471 | March 02, 2012 05:46:21 AM GMT