PHP RedBeanPHP\QueryWriter AQueryWriter::setSQLFilters - 2 examples found. These are the top rated real world PHP examples of RedBeanPHP\QueryWriter\AQueryWriter::setSQLFilters extracted from open source projects. You can rate examples to help us improve the quality of examples.
This is a lowlevel method to set the SQL filter array.
The format of this array is:
array(
'' => array(
'' => array(
'' => ''
)
)
)
Example:
array(
QueryWriter::C_SQLFILTER_READ => array(
'book' => array(
'title' => ' LOWER(book.title) '
)
)
Note that you can use constants instead of magical chars
as keys for the uppermost array.
This is a lowlevel method. For a more friendly method
please take a look at the facade: R::bindFunc().
/**
* Binds an SQL function to a column.
* This method can be used to setup a decode/encode scheme or
* perform UUID insertion. This method is especially useful for handling
* MySQL spatial columns, because they need to be processed first using
* the asText/GeomFromText functions.
*
* @param string $mode mode to set function for, i.e. read or write
* @param string $field field (table.column) to bind SQL function to
* @param string $function SQL function to bind to field
*
* @return void
*/
public function bindFunc($mode, $field, $function)
{
list($type, $property) = explode('.', $field);
$mode = $mode === 'write' ? QueryWriter::C_SQLFILTER_WRITE : QueryWriter::C_SQLFILTER_READ;
if (!isset(self::$sqlFilters[$mode])) {
self::$sqlFilters[$mode] = array();
}
if (!isset(self::$sqlFilters[$mode][$type])) {
self::$sqlFilters[$mode][$type] = array();
}
if (is_null($function)) {
unset(self::$sqlFilters[$mode][$type][$property]);
} else {
if ($mode === QueryWriter::C_SQLFILTER_WRITE) {
self::$sqlFilters[$mode][$type][$property] = $function . '(?)';
} else {
self::$sqlFilters[$mode][$type][$property] = $function . "({$field})";
}
}
AQueryWriter::setSQLFilters(self::$sqlFilters, !$this->isFrozen);
}