querylazy

Executes a SQL query without loading the data entierly to memory. Instead it calls the given Function with every single row

querylazy() → returns void

This function requires Lucee 5.3.6 and up.  Not supported on Adobe ColdFusion, etc.

Argument Reference

sql string
Required

SQL to execute

listener function
Required

listener function that will be called with the data of every single row. if returns false, execution is stopped.

params any

Array or Struct of parameter values.
When passing an array use ? as place holders.
When passing a struct use :keyName where keyName is the name of the key in the structure corresponding to
the parameter.
The struct or array can be a struct with keys such as the following: cfsqltype, list

options struct

Struct containing query options, all cfquery tag attributes are supported except the name attribute.

Examples
Sample code invoking the querylazy function

This example demonstrates how to use the querylazy function to execute a query without loading the data entirely to memory.

records = 0
 queryLazy(
 sql="SELECT * FROM users;",
 listener=function(row){
 // Do something with a query row
 records++;
 },
 options={
 datasource:"MyDatasource"
 }
 );
 echo("Records: #records#");

Expected Result: Recrods: 10

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub