new function I would like to see in openBD / Coldfusion

One of the things that I like about openBD, is that if the tag or function is not there. I just write it, and be done with it.

However unlike openBD, I can't do this for Coldfusion though. Except go through the process of asking for it, and cross my fingers. One of the things that I have wanted in Coldfusion for a few years now, is the ability to do something like this.

<cffunction name="someMethod">
<cfargument name="queryRow">
</cffunction>

There have been times when all I wanted was the row data, and then process that. Let us say for example I am using an ORM, and with refactoring considerations. I would like to do something like this.

<cffunction name="someMethod">
<cfargument name="queryRow">

<cfset saveData(queryRow) />
</cffunction>

The above is just an example, but you get the general idea. But there is no way to just get the one row, unless you want to do a QoQ.

Well now that openBD is here, I have now created the following new function.

<cfset stVariable = queryGetRow(qry, Row) />

Now I really thought about this for a minute or 30:-) And wanted to know what would be better, to return a struct or an actual one row query. Now since referencing the data from either is done via the dot notation, I thought it would actually be better to return a struct instead.

Anyway I have asked to see if I can submit the code change, if anyone has any suggestions or improvements on the implmentation I would like to hear from you.

Here is the code if you want to add it to your openBD. I also didn't add any bounds checking, as I thought I would let openBD take care of that.

package com.naryx.tagfusion.expression.function.ext;

import java.util.List;

import com.naryx.tagfusion.cfm.engine.cfData;
import com.naryx.tagfusion.cfm.engine.cfQueryResultData;
import com.naryx.tagfusion.cfm.engine.cfSession;
import com.naryx.tagfusion.cfm.engine.cfStructData;
import com.naryx.tagfusion.cfm.engine.cfmRunTimeException;
import com.naryx.tagfusion.expression.function.functionBase;

public class queryGetRow extends functionBase {
private static final long serialVersionUID = 1L;

public queryGetRow() { min = max = 2; }

public cfData execute( cfSession _session, List<cfData> parameters ) throws cfmRunTimeException {
   cfQueryResultData query = (cfQueryResultData)parameters.get(1);
int rowNo = parameters.get(0).getInt();

cfStructData struct = new cfStructData();
String[] columnList = query.getColumnNames();

for ( int i = 0; i < columnList.length; i ++ ) {
   struct.put(columnList[i], query.getCell(rowNo, i+1));
}
return struct;
}

}


  • todd sharp's Gravatar You can create this function in CF, that's the beauty of UDF's.

    In fact, someone already has:

    http://cflib.org/udf.cfm?ID=358

    This is one thing that really concerns me about open source - when folks litter their version of the code base with custom functions such as this and possibly distribute that application or have another developer come along after them and have no idea where superCool() came from.

    I hope I'm not sounding harsh, but it's a fine line you have to walk with things like this. If you get it committed to the project then cool, congrats. But I'd be careful using your own BIF like this.
    # Posted By todd sharp | 5/15/08 7:50 AM
  • Andrew Scott's Gravatar @Todd: That is very true, however, one has to look at execution time as well.
    # Posted By Andrew Scott | 5/15/08 7:59 AM
  • Hem Talreja's Gravatar Todd,

    You can declare custom tags that use a cfnewtag instead of a cf_newtag syntax, not sure if you can declare a function in the same way in ColdFusion MX7.

    Just add your newtag.cfm file to
    C:\CFusionMX7\wwwroot\WEB-INF\cftags

    and you can reference it as <cfnewtag var1="one" var2="two" />

    I would still recommend you using regular custom tags and or components as adding "CFTAGS" is not a practice followed by the industry and very few programmers are aware or able to recall details of the same...
    # Posted By Hem Talreja | 5/16/08 9:12 AM
  • Hem Talreja's Gravatar Andrew,

    You can declare custom tags that use a cfnewtag instead of a cf_newtag syntax, not sure if you can declare a function in the same way in ColdFusion MX7.

    Just add your newtag.cfm file to
    C:\CFusionMX7\wwwroot\WEB-INF\cftags

    and you can reference it as <cfnewtag var1="one" var2="two" />

    I would still recommend you using regular custom tags and or components as adding "CFTAGS" is not a practice followed by the industry and very few programmers are aware or able to recall details of the same...
    # Posted By Hem Talreja | 5/16/08 9:13 AM
  • Andrew Scott's Gravatar Hem, I am aware of that. However when we upgrade or are using a shared hosting server that is not possible. Upgrading is, but it is a pain to set everything up again.

    Appreciate the comment though, others may not be aware of it. But there is a heap of functions and tags that I would love to see in Coldfusion, with openBD I have the oppurtunity to get them to talk natively to the rest of the CFML engine.

    I doubt this is possible with the method you prescribed, to keep code to a minium and being able to reuse code.
    # Posted By Andrew Scott | 5/16/08 10:21 AM
  • Russ Johnson's Gravatar This is great! This is the kind of thing that will help the OBD community and userbase grow! Keep submitting functionality! Sooner or later it will catch up with ColdFusion!
    # Posted By Russ Johnson | 5/16/08 2:48 PM
  • Adam Haskell's Gravatar hope you don't mind I used the (updated) code in my example of how to extend OpenBD via the plugin architecture. http://cfrant.blogspot.com/2008/05/open-bd-plugin-...
    # Posted By Adam Haskell | 5/17/08 7:34 PM
  • Andrew Scott's Gravatar Adam, no I don't mind at all.
    # Posted By Andrew Scott | 5/17/08 8:56 PM