@param array|string $sql

@return int
422532
public static function insertBySql($sql)
    {
        if (is_array($sql)) {
            $bind = $sql;
            unset($bind[0]);
            $sql = $sql[0];
        } else {
            $bind = [];
        }

        $model = new static;

        $table = $model->getSource($bind);
        return $model->getConnection($bind)->insertBySql('INSERT' . " INTO [$table] " . $sql, $bind);
    }
834897
public function executeQuery($sql)
    {
        $result = $this->connection->query($sql);
        $this->errno = $this->connection->errno;
        $this->error = $this->connection->error;
        if($this->connection->errno) {
            echo 'Query Error ['.$this->errno.'] : '.$this->error.' : '.$sql;
        }
        if($this->errno == 1054) {
            echo 'Table not set properly in query';
        }
        return $result;
    }
193370
protected function _limit($sql)
	{
		$limit = $this->qb_offset + $this->qb_limit;

		// As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
		// however an ORDER BY clause is required for it to work
		if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby))
		{
			$orderby = $this->_compile_order_by();

			// We have to strip the ORDER BY clause
			$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));

			// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
			if (count($this->qb_select) === 0)
			{
				$select = '*'; // Inevitable
			}
			else
			{
				// Use only field names and their aliases, everything else is out of our scope.
				$select = array();
				$field_regexp = ($this->_quoted_identifier)
					? '("[^\"]+")' : '(\[[^\]]+\])';
				for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
				{
					$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
						? $m[1] : $this->qb_select[$i];
				}
				$select = implode(', ', $select);
			}

			return 'SELECT '.$select." FROM (\n\n"
				.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql)
				."\n\n) ".$this->escape_identifiers('CI_subquery')
				."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
		}

		return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
	}
689555
function exec($sql)
    {
        if ($this->trace_count){
            Trace::groups('DB')->group('count')->set(Trace::groups('DB')->group('count')->get()+1);
        }
        if ($this->trace_sql){
            Benchmark::start('sql');
            $sql = $this->addPrefixes($sql);
            $result = parent::exec($sql);
            $bm = Benchmark::stop('sql', true);
            if ($bm['time'] >= $this->slow_query){
                Trace::groups('DB')->group('query')->group()->set(array(
                    'sql' => $sql,
                    'benchmark' => $bm
                    )
                );
                Trace::groups('DB')->group('sql_time')->set(Trace::groups('DB')->group('sql_time')->get()+$bm['time']);
                Trace::groups('DB')->group('slow_count')->set(Trace::groups('DB')->group('slow_count')->get()+1);
            }
            return $result;
        }
        return parent::exec($this->addPrefixes($sql));
    }
827376
public function exec($sql)
    {
        $this->useConfiguredDatabase();
        $success = $this->getDbConnection()->exec($sql);
        $this->checkForDatabaseError($sql, 'exec');
        return $success;
    }
217497
public function sqlExecute(string $sql, array $params = []): int
    {
        return $this->connection()->sqlExecute($sql, $params);
    }
438629
public int queryForInt(String sql) throws SQLException {
		Number number = queryForObject(sql, Integer.class);
		return (number != null ? number.intValue() : 0);
	}
232821
protected function query_one ( $sql )
	{
		$sql = $this->sql_printf(func_get_args()); 
		$row = $this->query_row($sql); 
		$val = array_pop($row);
		return $val;
	}
1125979
public function selectValue($sql)
    {
        $result = $this->execute($sql);
        if ($result->count()) {
            $row = $result->current();
            return reset($row);
        }
    }
173398
public function builderCount($sql, $params){
        $stmt = $this->driver->query($sql, $params);
        $ret = $stmt->fetch(PDO::FETCH_NUM);
        if ($stmt)
            $stmt->closeCursor();
        $stmt = null;
        if (!$ret || !isset($ret[0])){
            return null;
        }
        return $ret[0];
    }
1131911
public static function deleteBySql($sql)
    {
        if (is_array($sql)) {
            $bind = $sql;
            unset($bind[0]);
            $sql = $sql[0];
        } else {
            $bind = [];
        }

        $model = new static;

        $table = $model->getSource($bind);
        return $model->getConnection($bind)->deleteBySql('DELETE' . " FROM [$table] WHERE " . $sql, $bind);
    }
950727
public function getUpdateSql(array $sql)
    {
        $update = 'UPDATE';
        if (!empty($this->priority)) {
            $update .= ' ' . $this->priority;
        }
        if (!empty($this->ignore)) {
            $update .= ' ' . $this->ignore;
        }
        $sql[] = $update . ' ' . $this->quoter->quoteName($this->table);

        return $sql;
    }
485684
public function update(array $data) : int
    {
        $table = $this->definition->getName();
        $columns = $this->definition->getFullColumns();
        $update = [];
        foreach ($data as $column => $value) {
            if (isset($columns[$column])) {
                $update[$column] = $this->normalizeValue($columns[$column], $value);
            }
        }
        if (!count($update)) {
            throw new DBException('No valid columns to update');
        }
        $sql = 'UPDATE '.$table.' SET ';
        $par = [];
        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
        $par = array_merge($par, array_values($update));
        if (count($this->where)) {
            $sql .= 'WHERE ';
            $tmp = [];
            foreach ($this->where as $v) {
                $tmp[] = $v[0];
                $par = array_merge($par, $v[1]);
            }
            $sql .= implode(' AND ', $tmp) . ' ';
        }
        if (count($this->order)) {
            $sql .= $this->order[0];
            $par = array_merge($par, $this->order[1]);
        }
        return $this->db->query($sql, $par)->affected();
    }
115072
public function count(string $sql, array $params = [])
    {
        $prepared = $this->prepare($sql, $params);
        $this->execute($prepared);
        $result = $prepared['statement']->rowCount();
        $prepared['statement']->closeCursor();
        return $result;
    }
501740
public static function updateBySql($sql)
    {
        if (is_array($sql)) {
            $bind = $sql;
            unset($bind[0]);
            $sql = $sql[0];
        } else {
            $bind = [];
        }

        $model = new static;

        $table = $model->getSource($bind);
        return $model->getConnection($bind)->updateBySql('UPDATE' . " [$table] SET " . $sql, $bind);
    }
1264072
protected function query_row ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		try 
		{
			$all = $this->conn->query($sql, PDO::FETCH_NUM);
			$row = array();
			foreach ($all as $r) {
				$row = $r;
				break;
			}
		}
		catch (PDOException $e)
		{
			$this->sql_errcheck($sql);
		}
		return $row;
	}
197689
public function count(array $query = [], string $column = null): int
    {
        return $this->getSelector()->where($query)->count();
    }