Different ways to get your query data
DSQL object offers you a number of ways how you can fetch the data from the query.
Just get all or some of the data
These functions will always executes query, fetches data and returns to you. Calling getRow() multiple times will continue to give you first row of data.
$data = $q->get(); // same as getAll();
$data = $q->getAll(); // returns all data as array of hashes, array() if query produced no results.
$data = $q->getRow(); // returns only first row of data, null if query produced no results.
$data = $q->getOne(); // returns only single value, null if query produced no results or result was NULL.
Sequentially fetching data
These functions will execute query only if it wasn't executed yet. Calling them subsequently will return more results or null if no more results are returned from the Database.
while($row = $q->fetch()){
// Will loop through results fetching one row at a time. You can access your data through $row['fieldname'];
}
Iterator support
DSQL object implements Iterator, which means you can use it inside foreach() block. It will return same thing as fetch() does, but the syntax is nicer.
foreach($q as $row){
// $row is associative array.
}
Statement access
If you want to do querying directly, you can also use PDO statement. Refer to PDO documentation.
$q->execute(); // Prepares and Executes statement
$stmt = $q->stmt;
Use with Lister
Starting from 4.2, Lister class and all derived classes (CompleteLister, Grid) accept Iterate-able classes through setSource() method. Therefore you can use this syntax:
$q=$this->api->db->dsql();
$q->table('user')->field('name')->field('surname');
$grid = $this->add('Grid');
$grid->addColumn('text','name');
$grid->addColumn('text','surname');
$grid->setSource( $q ); // Associate Grid with data-source.
