@param array|string $sql

@return int
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);
    }
1195013
protected function executeWithPaging($sql)
    {
        $count = 0;
        do {
            $stmt = $this->entityManager->getConnection()->executeQuery($sql);
            $stmt->execute();
            $lastCount = $stmt->rowCount();
            $count += $lastCount;
        } while ($lastCount > 0);

        return $count;
    }
189079
public function fetch_assoc($sql)
    {

        if (empty($sql)) return false;

        $res    = $this->query($sql);
        $result = @mysql_fetch_assoc($res);
        $this->free($res);

        return $result;
    }
586252
public function query($sql, $data = [])
     {
         $this->_init();

         try {
             $q = $this->db->prepare($sql);
         } catch (PDOException $e) {
             throw new Exception($e->getMessage());
         }

         foreach ($data as $k => $v) {
             $$k = $v;
             $q->bindParam(':' . $k, $$k); # bindParam( ... , PDO::PARAM_INT ...);
         }

         $result = $q->execute();

         if (strpos(trim(strtoupper($sql)), 'SELECT') === 0) {
             $rows = [];
             while($row = $q->fetch()) {
                 $rows[] = $row;
             }
             return $rows;
         }

         return $result;
     }
64857
protected function queryID(string $sql, array $params = [], array $options = []) {
        $options += [Db::OPTION_FETCH_MODE => 0];
        $this->query($sql, $params, $options);
        $r = $this->getPDO()->lastInsertId();

        return is_numeric($r) ? (int)$r : $r;
    }
1184535
public function execSql(string $sql): int
    {
        $result = $this->pdo->exec($sql);
        if ($result === false) {
            $err = $this->errorInfo();
            throw new \Exception('['.$err[0].']'.$err[2]);
        }
        return $result;
    }
197689
public function count(array $query = [], string $column = null): int
    {
        return $this->getSelector()->where($query)->count();
    }
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;
	}
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);
	}
927940
public function fetch_objects($sql)
    {
        $arr = $this->fetch_arrays($sql);
        if (!empty($arr)) {
            foreach ($arr as $k => $v) {
                $arr[$k] = (object) $v;
            }
        }

        $GLOBALS['__$DB_QUERY_COUNT']++;
        return $arr;
    }
1199238
public static function count($where = null): int
    {
        $select = static::select();

        if ($where !== null) {
            if ($where instanceof Where) {
                $select->field('COUNT(*)', 'total');
                $select->where(clone $where);

            } else if (is_array($where)) {
                $select->field('COUNT(*)', 'total');
                foreach ($where as $field => $value) {
                    $select->where($field, $value);
                }

            } else if (!is_array(static::$primaryKey) && (is_numeric($where) || is_string($where))) {
                $select->field('COUNT(' . static::$primaryKey . ')', 'total');
                $select->where(static::$primaryKey, $where);

            }
        } else {
            $pk = is_string(static::$primaryKey) ? static::$primaryKey : '*';
            $select->field('COUNT(' . $pk . ')', 'total');
        }

        $results = $select->fetchAll();

        if (isset($results[0])) {
            $r = $results[0];
            if (array_key_exists('total', $r)) {
                return (int)$r['total'];
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
879414
public static function countAll () : int
	{
        $dbObject  	= Database::getInstance();
		$sqlQuery 	= "SELECT COUNT(*) FROM ".static::$tableName;
		$resultSet 	= $dbObject->query($sqlQuery);
		$row 		= Database::fetchAssoc($resultSet);
		return (int) array_shift($row);
	}
581791
protected function query($sql) {
		$this->sqlCnt++;
		$res = $this->db->query($sql);
		if (!$res) {
			$this->dbError = $this->db->error;
		}
		return $res;
	}
261596
public static function simpleQuery($sql)
        {
            self::$sql_hits++;
            try {
                $res = self::getDBLink()->query($sql);
            } catch (PDOException $e) {
                throw new Exception($e->getMessage());
            }
            return $res;
        }
166783
public function fetch_array($sql)
    {
        $rs   = $this->query($sql);
        $data = $rs->fetchArray(SQLITE3_ASSOC);
        $GLOBALS['__$DB_QUERY_COUNT']++;

        $rs->finalize();
        return $data;
    }
122149
public function update(array $data): int
    {
        $this->builder->setUpdateData($data);
        $sql = $this->builder->buildSql();
        $this->builder = new QueryBuilder($this->pdo);
        return $this->execSql($sql);
    }
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;
    }