Query of a Query functionality was introduced in ColdFusion 5 and it gives the developer the ability to re-query a returned recordset. While it does implement the core set of SQL SELECT commands the one bit of functionality I miss is MySQL's Limit function (I miss this in ANY relational database thats not MySQL as it makes paginiation a doddle).
Limit in MySQL works as such:
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
SELECT * FROM myTable LIMIT 0, 10
1SELECT * FROM myTable LIMIT 0, 10
The above code will display the first 10 results from your your (table is 0 indexed)
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
SELECT * FROM myTable LIMIT 5, 5
1SELECT * FROM myTable LIMIT 5, 5
Starting from the 5th record this will bring back rows 6, 7, 8, 9, and 10
The idea behind the my <cffunction> is to mimic Limit with a passed in query. Of course this function can be used on any returned recordset but a lot of DB's have there own way of handling this which you might want to investigate first.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<cffunction name="limit" returntype="query" description="WORKS LIKE MYSQL LIMIT(N,N)">
<cfargument name="inQry" type="query" hint="I am the query" />
<cfargument name="arg1" type="numeric" />
<cfargument name="arg2" type="numeric" />
<cfscript>
var outQry = arguments.inQry;
var a1 = arguments.arg1-1;
var a2 = arguments.arg2-1;
if(arg1 GT 1){
outQry.RemoveRows(JavaCast( "int", 0 ), JavaCast( "int", arg1 ));
}
outQry.RemoveRows(JavaCast( "int", arg2 ),JavaCast( "int", outQry.recordcount-arg2));
return outQry;
</cfscript>
</cffunction>
1<cffunction name="limit" returntype="query" description="WORKS LIKE MYSQL LIMIT(N,N)">
2 <cfargument name="inQry" type="query" hint="I am the query" />
3 <cfargument name="arg1" type="numeric" />
4 <cfargument name="arg2" type="numeric" />
5
6 <cfscript>
7 var outQry = arguments.inQry;
8 var a1 = arguments.arg1-1;
9 var a2 = arguments.arg2-1;
10
11 if(arg1 GT 1){
12 outQry.RemoveRows(JavaCast( "int", 0 ), JavaCast( "int", arg1 ));
13 }
14
15 outQry.RemoveRows(JavaCast( "int", arg2 ),JavaCast( "int", outQry.recordcount-arg2));
16
17 return outQry;
18 </cfscript>
19</cffunction>
[More]