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: