@param bool|null $multi

@return string
@throws \chillerlan\Database\Query\QueryException
485013
public function sql(bool $multi = null):string{
		$this->multi = $multi ?? false;

		$sql = trim(implode(' ', $this->getSQL()));

		// this should only happen on a corrupt dialect implementation
		if(empty($sql)){
			throw new QueryException('empty sql'); // @codeCoverageIgnore
		}

		return $sql;
	}
1122825
protected function isColumnRelated($column, $multi = false)
    {
        if (!isset($column->relation) || $this->isColumnPivot($column)) {
            return false;
        }

        if (!$this->model->hasRelation($column->relation)) {
            throw new ApplicationException(Lang::get(
                'backend::lang.model.missing_relation',
                ['class'=>get_class($this->model), 'relation'=>$column->relation]
            ));
        }

        if (!$multi) {
            return true;
        }

        $relationType = $this->model->getRelationType($column->relation);

        return in_array($relationType, [
            'hasMany',
            'belongsToMany',
            'morphToMany',
            'morphedByMany',
            'morphMany',
            'attachMany',
            'hasManyThrough'
        ]);
    }
570559
public function readResponse($multiline = false)
    {
        try {
            $result = fgets($this->_socket);
        } catch (\Exception $e) {

        }

        if (!is_string($result)) {
            throw new \RuntimeException('read failed - connection closed?'.$e->getMessage());
        }

        $result = trim($result);
        if (strpos($result, ' ')) {
            list($status, $message) = explode(' ', $result, 2);
        } else {
            $status = $result;
            $message = '';
        }

        if ($status != '+OK') {
            throw new \RuntimeException($result);
        }

        if ($multiline) {
            $message = '';
            $line = fgets($this->_socket);
            while ($line && rtrim($line, "\r\n") != '.') {
                if ($line[0] == '.') {
                    $line = substr($line, 1);
                }
                $message .= $line;
                $line = fgets($this->_socket);
            };
        }

        return $message;
    }
1057145
public function getFormFields($model, $multiple = false)
    {
        $formFields[] = [
            'table' => [
                'attribute' => 'table',
                'formMethod' => 'dropDownList',
                'arguments' => [
                    'items' => call_user_func(['nineinchnick\audit\models\AuditForm', 'getAuditTables'])
                ],
            ]
        ];
        foreach (Yii::$app->controller->module->filters as $propety => $params) {
            $formFields[] = static::addFormField($model, $propety, $params);
        }
        return $formFields;
    }
609978
public final function initQueryBuilder(string $stack = null, bool $isSub = false): QueryBuilder
    {
        $stack = $stack ?? $this->getStack(); // use self stack if $stack is null
        if ($stack == null) {
            throw new DatabaseException(sprintf("Null \$stack, set it in '%s' class",
                static::class));
        }

        return new QueryBuilder($this->vendor->getDatabase()->getLink(), $stack, $isSub);
    }
995196
public function setValue(string $id, $value, bool $multi = false): self
    {
        return $this->set($id, new Definition\Value($value), $multi);
    }
989519
protected function resolveOperationName(string $operation, bool $multiple = true): string
    {
        if (! $multiple) {
            return $operation;
        } elseif (\in_array($operation, ['fill', 'add'])) {
            return 'attach';
        }

        return 'detach';
    }
996185
function getManialinkPageAnswers($multicall = false)
    {
        if ($multicall) {
            return $this->execute(ucfirst(__FUNCTION__), array(), $this->structHandler('PlayerAnswer', true));
        }
        return Structures\PlayerAnswer::fromArrayOfArray($this->execute(ucfirst(__FUNCTION__)));
    }
358607
public function addSelect($name, $label, $multi = [],  $is_mandatory = true)
    {
        $e = new \FrenchFrogs\Form\Element\Select($name, $label, $multi);
        $this->addElement($e);

        if ($is_mandatory) {
            $e->addRule('required');
        } else {
            $e->addFilter('nullable');
        }

        return $e;
    }
352159
protected function http_build_multi_query($data, $key = null)
    {
        $query = [];

        if (empty($data)) {
            return $key.'=';
        }

        $is_array_assoc = $this->is_array_assoc($data);

        foreach ($data as $k => $value) {
            if (is_string($value) || is_numeric($value)) {
                $brackets = $is_array_assoc ? '['.$k.']' : '[]';
                $query[] = urlencode(null === $key ? $k : $key.$brackets).'='.rawurlencode($value);
            } else {
                if (is_array($value)) {
                    $nested = null === $key ? $k : $key.'['.$k.']';
                    $query[] = $this->http_build_multi_query($value, $nested);
                }
            }
        }

        return implode('&', $query);
    }
556073
function getBillState($billId, $multicall = false)
    {
        if (!is_int($billId)) {
            throw new InvalidArgumentException('billId = ' . print_r($billId, true));
        }

        if ($multicall) {
            return $this->execute(ucfirst(__FUNCTION__), array($billId), $this->structHandler('Bill'));
        }
        return Structures\Bill::fromArray($this->execute(ucfirst(__FUNCTION__), array($billId)));
    }
354820
function buildQuery( $sql = NULL ) {
		if( !isset( $this->query ) OR empty( $sql ) ) {
			return FALSE;
		}

		$this->query .= $sql;

		return $this->query;
	}
961597
public static function searchMd($multi, $target)
    {
        if (empty($target) || empty($multi)) {
            return false;
        }

        $output = \is_object($multi)
            ? self::searchMdObject($multi, $target)
            : self::searchMdArray($multi, $target);

        $output = array_values(array_filter($output));

        // If output is not empty, false by default
        return !empty($output) ? $output : false;
    }
1229931
private static function searchMdObject($multi, array $target): array
    {
        return array_map(
            function($element) use ($target) {
                $exist = true;
                foreach ($target as $skey => $svalue) {
                    $exist = $exist && isset($element->$skey) && ($element->$skey === $svalue);
                }
                return $exist ? $element : null;
            },
            (array) $multi
        );
    }
1164034
private function getSearchableFields(stdClass $data, bool $multiLanguage = false)
    {
        $output = '';

        $model = $data->mainModel;

        $whereTpl = file_get_contents(__DIR__ . '/../templates/shared/where.hctpl');
        $orWhereTpl = file_get_contents(__DIR__ . '/../templates/shared/or.where.hctpl');
        $skip = array_merge($this->getAutoFill(), ['id']);


        if( $multiLanguage ) {
            if( array_key_exists('multiLanguage', $model) && ! empty($model->multiLanguage) )
                if( array_key_exists('columns', $model->multiLanguage) && ! empty($model->multiLanguage->columns) )
                    foreach ( $model->multiLanguage->columns as $index => $column ) {

                        if( in_array($column->Field, $skip) )
                            continue;

                        if( $output == '' )
                            $output .= str_replace('{key}', $column->Field, $whereTpl);
                        else
                            $output .= str_replace('{key}', $column->Field, $orWhereTpl);

                    }
        } else
            if( array_key_exists('columns', $model) && ! empty($model->columns) ) {

                foreach ( $model->columns as $index => $column ) {
                    if( in_array($column->Field, $skip) )
                        continue;

                    if( $output == '' )
                        $output .= str_replace('{key}', $column->Field, $whereTpl);
                    else
                        $output .= str_replace('{key}', $column->Field, $orWhereTpl);

                }
            }

        return $output;
    }
1337958
function getMapInfo($filename, $multicall = false)
    {
        if (!is_string($filename)) {
            throw new InvalidArgumentException('filename = ' . print_r($filename, true));
        }
        $filename = $this->secureUtf8($filename);

        if ($multicall) {
            return $this->execute(ucfirst(__FUNCTION__), array($filename), $this->structHandler('Map'));
        }
        return Structures\Map::fromArray($this->execute(ucfirst(__FUNCTION__), array($filename)));
    }
350269
protected function getQuery($param = null, $defaultValue = null)
    {
        if ($param === null) {
            return $this->getRequest()->getQuery();
        }

        return $this->getRequest()->getQuery($param, $defaultValue);
    }