The amazing adventures of Doug Hughes

Archive for August, 2008

Alagad Needs a Good Contractor

I actually posted this job yesterday, but for some reason it didn’t make it out over the blog aggregators so I’m reposting it today.

Right now Alagad has a need for a talented ColdFusion developer. We’re currently working on two projects for two different clients. Both of these clients need more resources to finish their respective projects.

The first project is for a major corporation with a recognizable name. We’re helping them rebuild their entire product management system. We’re making heavy use of Model-Glue, ColdSpring, MXUnit, Validat and other frameworks. This system is absolutely mission critical to our client. The client recently had one of their team members leave for another job in their company and has asked Alagad to provide a replacement from our team. This project is slated to last through the end of December, or possibly mid January. We need someone who can put in at least 40 hours per week on this project.

The other project makes use of Model-Glue, ColdSpring and Transfer. This project has about four weeks of work left on it. We’re simply trying to finish up the last few details to get this completed. We might not actually put you on this project, but if we do, we’d like you to provide up to an additional 20 hours per week.

So, ultimately, we’re looking for a guru who’s between gigs and wants to put in 50 to 60 hours a week to help Alagad wrap up the rest of the year.

Beyond that, there’s a chance of full time employment with Alagad at the end of this contract, depending on our workload.

Please send an email to Doug Hughes at dhughes@alagad.com to let me know if you’re interested.

QueryConvertForGrid()…Its Not Just For cfgrid Anymore

A few weeks ago, I was working on a small application for my wife that will allow her to keep track of the books that my kids have read. It put it together quickly using Transfer and Model-Glue utilizing Model-Glue’s scaffolding for most of the lists and forms. Everything was running smoothly and my wife was happy

However, last week, she came to me and asked if there was a way to make it so the book list could be paginated (OK, she did not use those words, but that is what she was essentially asking for). So, I started tweaking the application to stop using generic database messages in Model-Glue and adding a true service layer that interacted with Transfer to return a query object of books. I started to code the tedious (in my mind) task of handling pagination when I realized there is an easier way, queryConvertForGrid(). I figured if it works for doing pagination with cfgrid, why not use it elsewhere? I already had the page number and page size, so instead of doing the normal query of queries, and using startRow and maxRow in cfoutput, I simply used queryConvertForGrid().

For those who may not know what queryConvertForGrid() is, it is a function in ColdFusion 8 that takes 3 arguments (a query object, a page number and the page size) and returns a structure that is in a format that is used to populate a cfgrid. The structure contains 2 keys: ‘TotalRowCount’ which is the number of items in the original query and ‘Query’ which is a query object that contains ‘page’ of the query that matches the page number and page size arguments

Here is some sample code:

<cfset names = queryNew("") />
<cfset firstNames = ["Al", "Rudi", "Summer", "Dirk", "James", "Loren", "Hiram"] />
<cfset lastNames = ["Giordino", "Gunn", "Moran", "Pitt", "Sandecker", "Smith", "Yeager"] />
<cfset queryAddColumn(names,"firstName","varchar",firstNames) />
<cfset queryAddColumn(names,"lastName","varchar",lastNames) />

<cfset pagedQuery = queryConvertForGrid(names,1,5) />

<cfdump var="#pagedQuery#">

In this example, we are asking queryConvertForGrid() for page 1 with 5 items per page.

Running this code will give you the following output.

queryCOnvert Image 1

You can now use this query to display ‘paged’ items on your page.

I noticed a rather odd issue when viewing the last page set and there were less than a full page of data. I had expected that the items under the list would appear closer to he bottom of the list than they actually did. The cause of this issue is that queryConvertForGrid()will always return a query with the same number of rows as specified in the pageSize argument. This means that if your page only has 2 items, but the page size is set at 5, then you will still get a query with 5 rows, only 3 of them will have empty strings for every column.

This code, for example, asks for page 2 with 5 items per page from a recordset that has only 7 items,

<cfset names = queryNew("") />
<cfset firstNames = ["Al", "Rudi", "Summer", "Dirk", "James", "Loren", "Hiram"] />
<cfset lastNames = ["Giordino", "Gunn", "Moran", "Pitt", "Sandecker", "Smith", "Yeager"] />
<cfset queryAddColumn(names,"firstName","varchar",firstNames) />
<cfset queryAddColumn(names,"lastName","varchar",lastNames) />

<cfset pagedQuery = queryConvertForGrid(names,1,5) />

<cfdump var="#pagedQuery#">

Runnign this code will give you the following result,

queryConvert Image 2

Not really what I expected, but I guess I can live with that. I added a quick cfif to my output to check for an empty string and my display was exactly how I wanted it.

Then I started wondering, what would happen if there was only enough data for 2 pages but I asked for page 4? Here is code that does just that:

<cfset names = queryNew("") />
<cfset firstNames = ["Al", "Rudi", "Summer", "Dirk", "James", "Loren", "Hiram"] />
<cfset lastNames = ["Giordino", "Gunn", "Moran", "Pitt", "Sandecker", "Smith", "Yeager"] />
<cfset queryAddColumn(names,"firstName","varchar",firstNames) />
<cfset queryAddColumn(names,"lastName","varchar",lastNames) />

<cfset pagedQuery = queryConvertForGrid(names,1,5) />

<cfdump var="#pagedQuery#">

And here is the result of runnign this code:

queryConvert Image 3

You will see that a query with 5 rows is still returned, but every column in every row is an empty string.

This is nothing that cannot be worked around, but if you want to use queryConvertForGrid() without using cfgrid its something you need to keep in mind.

Also keep in mind that some databases, like MySQL, make it easy to paginate data right inside your query by using the LIMIT clause. However, it is a bit more difficult in SQL Server, which is where I was storing the data for my book application.

Tag Cloud