limit(inQry, arg1, arg2)
Last updated February 13, 2009
Version: 2 | Requires: ColdFusion MX | Library: DatabaseLib
Description:
To be used on a recordset like a QoQ. Mimics MySQL's Limit function i.e.
SELECT * FROM myTable LIMIT 0, 10
The above code will display the first 10 results from your table
SELECT * FROM myTable LIMIT 5, 5
Starting from the 5th record this will bring back rows 5, 6, 7, 8, and 9.
This functions aims to mimic this.
Return Values:
Returns a query.
Example:
<!--- Return rows 5-10 --->
<cfset newQuery = limit(qry, 5,5) />
Parameters:
| Name | Description | Required |
|---|---|---|
| inQry | Query to modify. | Yes |
| arg1 | Row to begin the limit. | Yes |
| arg2 | Number of rows to limit the result to. | Yes |
Full UDF Source:
<!---
Mimics MySQL limit's function.
v2 mods by Raymond Camden and Steven Van Gemert
@param inQry Query to modify. (Required)
@param arg1 Row to begin the limit. (Required)
@param arg2 Number of rows to limit the result to. (Required)
@return Returns a query.
@author Andy Jarrett (mail@andyjarrett.co.uk)
@version 2, February 13, 2009
--->
<cffunction name="limit" returntype="query" description="WORKS LIKE MYSQL LIMIT(N,N)" output="false">
<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;
if(arg1 GT 1){
outQry.RemoveRows(JavaCast( "int", 0 ), JavaCast( "int", a1 ));
}
outQry.RemoveRows(JavaCast( "int", arg2 ),JavaCast( "int", outQry.recordcount-arg2));
return outQry;
</cfscript>
</cffunction>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
4 day(s) ago
Will Belden added
longTime
9 day(s) ago
James Sleeman added
quickSort
19 day(s) ago
Ben Forta added
GetHostAddress
22 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)