@param string $logic
@param $sql
@param array $params

@return $this
321726
public function addWhere(string $logic, $sql, array $params = [])
    {
        $this->wConditions()->addCondition($logic, $sql, $params);

        return $this;
    }
134366
public function setSQL($sql, array $args=[]) {
		$this->sql = $sql;
		$this->args = $args;

		$this->message = $this->getMessage();

		if(strlen($sql) > 2048)
			return $this;
		$msg = '<br/>'."\n".'SQL: '.$sql;
		if(count($args) > 0) {
			$msg .= ' ('.implode(', ', $args).')';
			if(strlen($msg) > 2048)
				return $this;
		}
		$this->message .= $msg;

		return $this;
	}
394322
public function query($sql, $bindings = array())
    {
        list($this->pdoStatement) = $this->statement($sql, $bindings);

        return $this;
    }
1106311
public function andWhere($sql=null, $params=array())
    {
        if(!isset($this->_where))
            $this->_where = new Criteria();

        $this->_where->and(new Criteria($sql, $params));

        return $this;
    }
810069
public function query($sql=null, array $params=[]) {
		if($sql === null) {
			$sql = $this->buildSQL();
			$params = $this->getParameters();
		}

		$this->replaceArrayParams($sql, $params);

		return $this->query = $this->db->query($sql, $params);
	}
1288454
public function query(string $sql, array $params = [])
    {
        $prepared = $this->prepare($sql, $params);
        $this->execute($prepared);
        return new ResultSet($prepared['statement']);
    }
1277492
public function execute($sql, array $params=array())
	{
		if ($params) {
			$stmt = $this->prepare($sql);
			if (!$stmt) { return false; }

			$flag = $stmt->execute($params);
			if (!$flag) { return false; }
		} else {
			$stmt = $this->query($sql);
			if (!$stmt) { return false; }
		}

		return $stmt->rowCount();
	}
226221
public function query(string $sql, array $params = []) {
        X::logger()->trace("$sql with params " . $this->serializeArray($params));
        try {
            $st = $this->pdo->prepare($sql);
            if ($st === false) {
                $e = $this->pdo->errorInfo();
                throw new DataBaseException($e[2], $e[1]);
            }
            if ($st->execute($params)) {
                $this->_affectedRows = $st->rowCount();
                $this->_lastInsertId = $this->pdo->lastInsertId();
                return $st->fetchAll(PDO::FETCH_ASSOC);
            }

            $e = $st->errorInfo();
            throw new DataBaseException($e[2], $e[1]);
        } catch (PDOException $ex) {
            X::logger()->trace($ex);
            throw new DataBaseException($ex->getMessage(), $ex->getCode());
        }
    }
870538
public function where(string $sql, array $params = []) : self
    {
        $this->qiterator = null;
        $this->where[] = [ $sql, $params ];
        return $this;
    }
325531
public function query($sql, $params = [], $options = [])
    {
        $conn = $this->getConn(!empty($options['forceMaster']) ? true : false);

        $stmt = $this->prepare($conn, $sql, $params);

        $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        if ($rows === false) {
            $this->throwException();
        }
        if (!empty($options['getRow'])) {
            $rows = isset($rows[0]) ? $rows[0] : null;
        }
        return $rows;
    }
946470
public function orderByRaw(string $sql, string ...$params)
    {
        $this->addOrderBy($this->dialect()->quote($sql), null, $params);

        return $this;
    }
1131488
public function orHavingRaw(string $sql, string ...$params)
    {
        $this->hConditions()->orRaw($sql, ...$params);

        return $this;
    }
805201
public function getPost($sql, $params)
    {
        $post = $this->findWhere("$sql", $params);
        return $post->setupPost($post);
    }
143445
public function sql(string $sql, array $params = []) {
        $r = $this->model->db->query($sql, $params);
        if (!is_array($r) || 0 === count($r)) {
            return [];
        }
        return $this->model->setup($r);
    }
85018
public function sql(string $sql, array $params = [], bool $autoexec = false)
    {
        // Store Sql / definition and parameter
        $this->sql = $sql;
        $this->params = $params;
        
        return $this->query($autoexec);
    }
268341
private function prepare(string $sql, array $params = []): \PDOStatement
    {
        return $this->pdo()->connectionProcess(function (Pdo $pdo) use ($sql, $params) {
            $stmt = $pdo->prepare($sql);

            if ($params) {
                $k = 1;

                foreach ($params as $key => $value) {
                    $stmt->bindValue(is_int($key) ? $k++ : $key, $value);
                }
            }

            $this->fire($sql, $params);

            $stmt->execute();

            $pdo->checkError();

            return $stmt;
        });
    }
1084094
private function addColumn($sql, $alias = null, array $params = [])
    {
        $this->columns[] = [
            'sql'    => $sql,
            'alias'  => $alias,
            'params' => $params,
        ];

        return $this;
    }