tracker issue : CF-3747685

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

addParam is not chainable

| View in Tracker

Status/Resolution/Reason: To Fix//

Reporter/Name(from Bugbase): Chris Phillips / Chris Phillips (cf_chris)

Created: 04/22/2014

Components: Database

Versions: 10.0

Failure Type: Usability Issue

Found In Build/Fixed In Build: Final /

Priority/Frequency: Minor / Some users will encounter

Locale/System: English / Win All

Vote Count: 1

Problem Description:
Being able to chain methods allows for a nice terse, elegent syntax. But, addParam has a returntype of void. So, you have to call each addParam() on the original Query object.

Steps to Reproduce:
	var vehicleQry = new Query(
				datasource="DealerPeak",
				sql="SELECT TOP(1) [Year], Car_Make, Car_Model FROM Vehicle WHERE Active = :Active AND Car_StatusID = :Car_StatusID ORDER BY CarIdentity DESC"
			)
			.addParam( name="Active", value="1", cfsqltype="cf_sql_integer" )
			.addParam( name="Car_StatusID", value="1", cfsqltype="cf_sql_integer" )
			.execute().getResult();

Actual Result:
Exception: The system has attempted to use an undefined value, which usually indicates a programming error, either in your code or some system code. 

Expected Result:
Run the query successfully.

Any Workarounds:
Type more characters than you need to.

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

Watson Bug ID:	3747685

External Customer Info:
External Company:  
External Customer Name: cf_chris
External Customer Email:  
External Test Config: My Hardware and Environment details:

Windows 7 (SP1) 64-bit

ColdFusion 10 - 10,0,12,286680

Java Version - 1.7.0_17

Attachments:

  1. April 23, 2014 00:00:00: 1_AddParamNotChainable.cfm

Comments:

If the return type for addParam in base.cfc were any or component and it just did (return this;) at the end, this would work.
Comment by External U.
12589 | April 22, 2014 07:04:10 PM GMT
+1. Support for method chaining make for more terse code.
Vote by External U.
12591 | April 22, 2014 09:39:33 PM GMT
You know you don't NEED to set them one by one, right? You can either pass a parameters argument to the Query constructor, or call setAttributes() (which still returns void, unfortunately) after the fact. And both options will take all the parameters in one fell swoop. -- Adam
Comment by External U.
12590 | April 24, 2014 02:17:00 PM GMT