Skip to content

classes_essentials_model_resultset.class

Daniel Spors edited this page Dec 19, 2023 · 3 revisions

Classes in file essentials/model/resultset.class.php

class ResultSet

This is our own Statement class There are some difficulties with PHPs PDOStatement class as it will not allow us to override all methods (Traversable hides Iterator). So we cannot simply inherit from there, but must wrap it.

Implements: Iterator ArrayAccess

bindValue

Overrides parent to capture arguments We want to know which arguments are used, so we need to capture theme here before passing control to parents method. See PDOStatement::bindvalue

Definition: public function bindValue($parameter, $value, $data_type=null)

Returns: bool true or false

Parameters:

  • string $parameter Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter

  • mixed $value The value to bind to the parameter.

  • int $data_type Explicit data type for the parameter using the PDO::PARAM_* constants

closeCursor

INTERNAL Closes the inner statements cursor if present

Count

Returns the number of affected rows.

Definition: public function Count()

Returns: int Number of affected rows

current

IMPLEMENTS Iterator::current

Enumerate

Returns all values for a specified column Will build an array with all values for the specified column in this result sets rows.

$ids = $dataSource->ExecuteSql("SELECT * FROM my_table WHERE id<1000")->Enumerate("id");	
$tables = $dataSource->ExecuteSql("SHOW TABLES")->Enumerate(0);	

Definition: public function Enumerate($column_name, $distinct=true, $key_column_name=false)

Returns: array

Parameters:

  • int|string $column_name Column to enumerate values for. If an integer is given will see that as zero-based index.

  • bool $distinct True to array_unique, false to keep duplicates

  • string $key_column_name If given uses this column as key for an associative resulting array

ErrorInfo

Returns the error info

Definition: public function ErrorInfo()

Returns: array ErrorInfo

ErrorOutput

Returns the last statement and the error info Will combine that into a string for easy output

Definition: public function ErrorOutput()

Returns: string SQL[newline]ErrorInfo

execute

Overrides parent to capture query and arguments We want to know which query and arguments are used, so we need to capture theme here before passing control to parents method. See PDOStatement::execute

Definition: public function execute($input_parameters=null)

Returns: bool true or false

Parameters:

  • array $input_parameters An array of values with as many elements as there are bound parameters in the SQL statement being executed

ExecuteWithArguments

Executes the query representes by this ResultSet. Will autodetect if the query references named (:arg1, :arg2) or numerical (?) arguments and bind the values from $arguments accordingly.

Definition: public function ExecuteWithArguments($arguments)

Returns: mixed The query result

Parameters:

  • array $arguments Array of arguments, matching the SQL query given.

fetch

Overrides parent for buffering See PDOStatement::fetch

Definition: public function fetch(int $mode=null, int $cursorOrientation=null, int $cursorOffset=null)

Returns: mixed See php.net docs

Parameters:

  • int $mode See php.net docs

  • int $cursorOrientation See php.net docs

  • int $cursorOffset See php.net docs

fetchAll

Overrides parent for buffering See PDOStatement::fetchall

Definition: public function fetchAll($fetch_style=null, $column_index=null, $ctor_args=null)

Returns: mixed See php.net docs

Parameters:

  • int $fetch_style See php.net docs

  • int $column_index See php.net docs

  • mixed $ctor_args See php.net docs

fetchRow

Returns a row Will return the first result row as array. Useful when for example querying for min/max values like this:

list($min,$max) = $ds->ExecuteSql("SELECT min(a), max(a) FROM some_table")->fetchRow(false);	

Definition: public function fetchRow($assoc=true)

Returns: array|false The next rows values or false on error

Parameters:

  • bool $assoc If true returns an associative array, else only array values are returned

fetchScalar

Returns a scalar value Will return the first result rows $column.

Definition: public function fetchScalar($column)

Returns: mixed The value or false on error

Parameters:

  • int $column Column index

GetArgs

Gets the arguments

Definition: public function GetArgs()

Returns: array SQL arguments

GetMergedSql

Gets the merged query used (inline arguments)

Definition: public function GetMergedSql()

Returns: string SQL query

GetPagingInfo

Returns information about paging Result will be an array with these keys: 'rows_per_page', 'current_page', 'total_pages', 'total_rows', 'offset'

Definition: public function GetPagingInfo($key=false)

Returns: array Paging info

Parameters:

  • mixed $key If given returns one of the keys value only

GetSql

Gets the query used

Definition: public function GetSql()

Returns: string SQL query

HadError

Returns if there was an error

Definition: public function HadError()

Returns: bool true if there was an error

key

IMPLEMENTS Iterator::key

LogDebug

Logs this statement Sometimes you will need to debug specific statements. This method will create a logentry with the SQL query, the arguments used and try to combine it for easy copy+paste from log to your sql tool (for retry).

Definition: public function LogDebug($label)

Returns: void

Parameters:

  • string $label Optional label to use as prefix for the log entry

MergeSql

Merges arguments into an SQL statement. Note that this is meant for debug output only!

Definition: public static function MergeSql($ds, $sql, $arguments)

Returns: string Merged statement

Parameters:

next

IMPLEMENTS Iterator::next

offsetExists

IMPLEMENTS ArrayAccess::offsetExists

offsetGet

IMPLEMENTS ArrayAccess::offsetGet

offsetSet

IMPLEMENTS ArrayAccess::offsetSet

offsetUnset

IMPLEMENTS ArrayAccess::offsetUnset

Process

Calls a callback function for each result dataset. Callback function will receive each row as array and must return the (eventually changed) array. Note that this method will not clone the result, but return the object itself!

Definition: public function Process($callback)

Returns: ResultSet Returns $this

Parameters:

  • mixed $callback Anonymous callback function

restore

Creates a ResultSet from a serialized data string This is mainly needed for query caching

Definition: public static function restore($data)

Returns: ResultSet Restored ResultSet object

Parameters:

  • string $data serialized data string

results

SHORTCUT ResultSet::fetchAll.

rewind

IMPLEMENTS Iterator::rewind

rowCount

OVERRIDE Make sure that SqLite returns something on SELECT statements too

serialize

Savely serializes this object This is mainly needed for query caching

Definition: public function serialize()

Returns: string serialized data string

unserialize

Savely unserializes this object This is mainly needed for query caching.

Definition: public function unserialize($data)

Returns: void

Parameters:

valid

IMPLEMENTS Iterator::valid

class WdfPdoStatement

INTERNAL Extends PDOStatement so that we can easily capture calling DataSource

Extends: PDOStatement

Clone this wiki locally