DB_dsql::_render_where PHP Méthode

_render_where() public méthode

Subroutine which renders either [where] or [having].
public _render_where ( string $kind ) : array
$kind string 'where' or 'having'
Résultat array Parsed chunks of query
    public function _render_where($kind)
    {
        $ret = array();
        foreach ($this->args[$kind] as $row) {
            list($field, $cond, $value) = $row;
            if (is_object($field)) {
                // if first argument is object, condition must be explicitly
                // specified
                $field = $this->consume($field);
            } else {
                list($table, $field) = explode('.', $field, 2);
                if ($field) {
                    if ($this->mode == 'delete') {
                        $field = $this->bt($field);
                    } else {
                        $field = $this->bt($table) . '.' . $this->bt($field);
                    }
                } else {
                    $field = $this->bt($table);
                }
            }
            // no value or condition passed, so this should be SQL chunk itself
            if ($value === UNDEFINED && $cond === UNDEFINED) {
                $r = $field;
                $ret[] = $r;
                continue;
            }
            // if no condition defined - set default condition
            if ($value === UNDEFINED) {
                $value = $cond;
                if (is_array($value)) {
                    $cond = 'in';
                } elseif (is_object($value) && @$value->mode === 'select') {
                    $cond = 'in';
                } else {
                    $cond = '=';
                }
            } else {
                $cond = trim(strtolower($cond));
            }
            // special conditions if value is null
            if ($value === null) {
                if ($cond === '=') {
                    $cond = 'is';
                } elseif (in_array($cond, array('!=', '<>', 'not'))) {
                    $cond = 'is not';
                }
            }
            // value should be array for such conditions
            if (($cond === 'in' || $cond === 'not in') && is_string($value)) {
                $value = explode(',', $value);
            }
            // if value is array, then use IN or NOT IN as condition
            if (is_array($value)) {
                $v = array();
                foreach ($value as $vv) {
                    $v[] = $this->escape($vv);
                }
                $value = '(' . implode(',', $v) . ')';
                $cond = in_array($cond, array('!=', '<>', 'not', 'not in')) ? 'not in' : 'in';
                $r = $this->consume($field) . ' ' . $cond . ' ' . $value;
                $ret[] = $r;
                continue;
            }
            // if value is object, then it should be DSQL itself
            // otherwise just escape value
            if (is_object($value)) {
                $value = $this->consume($value);
            } else {
                $value = $this->escape($value);
            }
            $r = $field . ' ' . $cond . ' ' . $value;
            $ret[] = $r;
        }
        return $ret;
    }