Latest Articles:
Committee Members:
Alert Email
Get a short email alert whenever a new entry is published.
Confidential, secure it's piece of cake to keep uptodate.
New QueryRun() + QueryOfQueryRun() functions
Of all the things you most want to do buried deep within a CFSCRIPT block is manipulate databases. Invoking a tag while in script mode is impossible, unless you build your own CFC wrapper, which is clunky and horrendously inefficient.
OpenBlueDragon has just released the first couple of native functions that let you get in and around the power of queries but from a script.
These operate just like CFQUERY but at a script level. So let us look at how you can use them. In the basic form, you can simply pass in a datasource and a SQL statement and it will return a standard query object.
<cfscript>
if ( QueryRun(ds,"select 1 from table where x=2").recordcount eq 0 ){
//do something
}
</cfscript>
Okay, all fairly straightforward thus far, but what about doing something that requires a little bit more control over the variables to which you build up the string. In other words how do you CFQUERYPARAM your statement?
That is easy. You mark in your SQL statement where you wish your variable to be placed, using the ? character. Then you pass in an array of structs that describe each of the variables you wish to use.
Assume for sake of example, you wish to query between two dates, the code to do that would be:
<cfscript> var sql = "select * from table1 where date1 > ? and date1 < ?"; var params = ArrayNew(); params[1] = StructNew(); params[1].value = CreateDate( 2007, 1, 1 ); params[1].cfsqltype = "CF_SQL_DATE"; params[2] = StructNew(); params[2].value = CreateDate( 2010, 1, 1 ); params[2].cfsqltype = "CF_SQL_DATE"; var qry = QueryRun( ds, sql, params ); </cfscript>
You can use all of the attributes available to CFQUERYPARAM to describe your variables, and you must have at least one structure in the array per ? in your SQL statement.
It is that simple. Performing the same thing with QueryOfQuery's, is used with the sister function, QueryOfQueryRun(), which is the same, minus the datasource parameter at the start.
This, long overdue, addition to the core language, will enable much tighter and faster CFC's to be written including removing all the hacks away that framework developers have had to do to provide database connectivity.
Available from today in the nightly build.
CFHTMLBODY + CFHTMLHEAD added
From an excellent discussion with Peter/Matt, we've made some improvements to CFHTMLHEAD and added a new tag, CFHTMLBODY to the OpenBD stable:
Not only can you now decide if you want the content to be at the start or end of the HEAD/BODY section, you can also use closing tags to express content now instead of using an external variable. <cfhtmlhead position="prepend"> <title>My Title</title> </cfhtmlhead>
The same power can also be applied to the BODY tag of the HTML page you are building. A common technique is to push Javascript calls down at the bottom of the page. This is also an opportunity for you to add in custom footer information.
<cfhtmlbody> <script src="somejavascript.js"></script> </cfhtmlbody>
And for the CFSCRIPT junkies, we have also added these tag enhancements as CFML functions.
Part of the nightly build.
Suite of new Array/List Functions added
You talk. We listen.
This weekend has seen a whole slew of new functions added to OpenBD core base, thanks largely to the suggestions by Peter Farrell.
- ArrayValueCount
- ArrayIndexExists
- ArrayValueCountNoCase
- ArrayConcat
- ArrayReverse
- ArrayRest
- ArraySlice
- ListSwap
- ListIndexExists
- htmlBody
- htmlHead
- REMatch
- REMatchNoCase
Remember you can get access to all our core functions/tags through the online support documentation site.
Official CFML Documentation site released
We are proud to release the official OpenBD CFML Documentation reference site released.
This site lists all the functions and tags available within OpenBD in an interface not dissimilar to the popular JavaDoc's site enjoyed by Java Developers.
http://www.openbluedragon.org/docs/
The key feature here is that the documentation is coming from the engine itself, not any 3rd party resource, external files or special website. Like JavaDoc, the information is taken from the actual runtime of OpenBD. This makes it the only resource that is truly representative of what the engine is doing. Never again will documentation be out of date.
You can visit here for a bit of background on how this evolved from Alan Williamson's blog



