Monday, September 22, 2014

Monday, December 13, 2010

ColdFusion Remove rows from QueryNew

Last week, i was working with a temp. query manipulation which is created by QueryNew function.

When i planned to delete multiple rows based on the condition, i filtered ColdFusion Live Docs for the function. Luckily got java function from Bennadel blog on remove rows.
While doing unit test, found some fileds are not deleting.
Tried with reverse engineering (reverse loop). Hey! its working.
Problem is with the ColdFusion-Java indexes Compatibility.
Thanks Ben! I inspired!!

Created sample code for re-use:

<CFSET qryFiles = QUERYNEW("FileID,FileName") />
<CFLOOP from="1" to="10" index="idx">
<CFSET QueryAddRow(qryFiles) />
<CFSET QuerySetCell(qryFiles,"FileID","#idx#")>
<CFSET QuerySetCell(qryFiles,"FileName","item#idx#")>
<CFDUMP var="#qryFiles#" label="Base table --- Before delete:Raghuram">
<CFSET fileNameList= "item1,item10,item4" />
<CFSET fileArr = ListToArray(fileNameList) />
<CFDUMP var="#fileArr#" label="Values array wish to delete :Raghuram">

<CFLOOP from ="#qryFiles.recordCount#" to="1" step="-1" index="rowIdx">
<CFLOOP from = 1 to = #arraylen(fileArr)# index="fileIDx">
<CFIF (qryFiles.FileName[rowIdx] EQ fileArr[fileIDx])>
<CFSET qryFiles.RemoveRows(JavaCast( "int", (rowIdx - 1) ), JavaCast( "int", 1 ) ) />

<CFDUMP var="#qryFiles#" label="Base table --- After delete :Raghuram" />

Raghuram Reddy Gottimukkula
Adobe Certified ColdFusion Developer
Hyderabad, India

Tuesday, November 30, 2010

For knowing application settings:
<cfdump var="#application.getApplicationSettings()#" label="App.Settings-Raghuram" />