-
Notifications
You must be signed in to change notification settings - Fork 34
classes_essentials_model_resultset.class
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
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
INTERNAL Closes the inner statements cursor if present
Returns the number of affected rows.
Definition: public function Count()
Returns: int
Number of affected rows
IMPLEMENTS Iterator::current
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
Returns the error info
Definition: public function ErrorInfo()
Returns: array
ErrorInfo
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
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
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.
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
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
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
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
Gets the arguments
Definition: public function GetArgs()
Returns: array
SQL arguments
Gets the merged query used (inline arguments)
Definition: public function GetMergedSql()
Returns: string
SQL query
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
Gets the query used
Definition: public function GetSql()
Returns: string
SQL query
Returns if there was an error
Definition: public function HadError()
Returns: bool
true if there was an error
IMPLEMENTS Iterator::key
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
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:
-
DataSource $ds
DataSource used to escape the arguments (DataSource::EscapeArgument) -
string $sql
SQL statement -
array $arguments
Array of arguments
IMPLEMENTS Iterator::next
IMPLEMENTS ArrayAccess::offsetExists
IMPLEMENTS ArrayAccess::offsetGet
IMPLEMENTS ArrayAccess::offsetSet
IMPLEMENTS ArrayAccess::offsetUnset
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
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
SHORTCUT ResultSet::fetchAll.
IMPLEMENTS Iterator::rewind
OVERRIDE Make sure that SqLite returns something on SELECT statements too
Savely serializes this object This is mainly needed for query caching
Definition: public function serialize()
Returns: string
serialized data string
Savely unserializes this object This is mainly needed for query caching.
Definition: public function unserialize($data)
Returns: void
Parameters:
-
string $data
Serialized data, see result of ResultSet::serialize
IMPLEMENTS Iterator::valid
INTERNAL Extends PDOStatement so that we can easily capture calling DataSource
Extends: PDOStatement