Get sql.

@param array $sql

@return array
181682
protected function getLimitSql(array $sql): array
    {
        if (!isset($this->limit)) {
            return $sql;
        }
        if ($this->offset > 0) {
            $sql[] = sprintf('LIMIT %s OFFSET %s', (float)$this->limit, (float)$this->offset);
        } else {
            $sql[] = sprintf('LIMIT %s', (float)$this->limit);
        }

        return $sql;
    }
389583
public function query($sql)
    {
        // auto reconnect
        $this->connect();
        
        //echo $sql;
        $this->statement = null; //reset 
        //echo 'adapter:'; var_dump($sql);exit;
        if (!($this->result = $this->connection->query($sql))) {
            $this->showError();
        }
        return $this->result;
    }
354724
protected function getExplain($sql)
    {
        $pdo = $this->linkID->query("EXPLAIN " . $sql);
        $result = $pdo->fetch(PDO::FETCH_ASSOC);
        $result = array_change_key_case($result);
        return $result;
    }
666515
public function getFilters($sql)
    {
        $classes    = array();
        $filterRows = $this->db->fetchAll($sql);
        $output     = array();

        // \MUtil_Echo::track($filterRows);
        foreach ($filterRows as $key => $filter) {
            $className = $filter['gaf_class'];
            if (! isset($classes[$className])) {
                $classes[$className] = $this->newFilterObject($className);
            }
            $filterObject = clone $classes[$className];
            if ($filterObject instanceof AppointmentFilterInterface) {
                $filterObject->exchangeArray($filter);
                $output[$key] = $filterObject;
            }
        }
        // \MUtil_Echo::track(count($filterRows), count($output));

        return $output;
    }
232821
protected function query_one ( $sql )
	{
		$sql = $this->sql_printf(func_get_args()); 
		$row = $this->query_row($sql); 
		$val = array_pop($row);
		return $val;
	}
1095061
public function query($sql)
    {
        return $this->getDisconnectRetry()->run(function () use ($sql) {
            $statement = $this->prepare($sql);
            $statement->execute();

            return $statement;
        });
    }
34970
public static function read($sql, $mode = self::KEY)
    {
        $vals = [];
        $result = self::query($sql);
        while ($row = $result->fetch($mode)) {
            $vals[] = $row;
        }
        //
        return $vals;
    }
1147663
public function rawQuery(string $sql, array $params=[]): array
  {
    $rows = [];

    # Sanity check
    if (empty($sql)) {
      return $rows;
    }

    # Obtain transaction, unelss already in a transaction
    $autoCommit = $this->beginTransaction();

    # Prepare
    if ($sth = $this->prepare($sql)) {

      # Binds
      foreach ($params as $bind=>$value) {
        $sth->bindValue( ':'.\ltrim($bind,':'), $value);
      }

      # Execute statement
      if ($sth->execute()) {
        $rows = $sth->fetchAll(\PDO::FETCH_ASSOC);
      }

      # Close the cursor
      $sth->closeCursor();
    }

    # If we had a loacl transaction, commit it
    if ($autoCommit) $this->commit();

    return $rows;
  }
587033
public function getAll($sql = null)
    {
        $results = $this->builder->query($sql)->collect();

        if ($results) {

            $collection = new Collection();

            foreach ($results as $key => $row) {
                $collection->add(self::instance($row));
            }

            $this->resolveRelations($collection);

            return $collection;
        }

        return null;
    }
477613
protected function getSelectSql(array $sql): array
    {
        $sql[] = trim('SELECT ' . trim(implode(' ', [
            $this->distinct,
            $this->highPriority,
            $this->straightJoin,
            $this->resultSize,
            $this->bufferResult,
            $this->calcFoundRows,
        ])));

        return $sql;
    }
1255874
public function getAll($sql, array $args = [])
    {
        $result = $this->query($sql, $args);
        
        if (!$result) {
            return [];
        }

        $rows = $result->fetch_all(MYSQLI_ASSOC);
        
        return $rows;
    }
481564
final public static function findBySql (string $sql) : array
	{
        $dbObject 		= Database::getInstance();
		$resultSet 		= $dbObject->query($sql);
		$objectArray 	= [];
		while ($row = Database::fetchAssoc($resultSet))
		{
			$objectArray[] = static::instantiate($row);
		}
		return $objectArray;
	}
1254602
protected function getStatement($sql)
    {
        if (!isset($this->statements[$sql])) {
            $this->statements[$sql] = $this->adapter->prepare($sql);
        }
        return $this->statements[$sql];
    }
676120
public function get($sql)
    {
        $this->expireCache();
        $hash = self::_sqlHash($sql);

        // if doesn't exists, return null
        if (!array_key_exists($hash, $this->_prepared_cache)) {
            return null;
        }
        return $this->_prepared_cache[$hash]["statement"];
    }
271500
public function getList(array $data = array())
    {
        $sql = 'SELECT b.*, u.name AS user_name';

        if (!empty($data['count'])) {
            $sql = 'SELECT COUNT(b.backup_id)';
        }

        $sql .= ' FROM backup b
                  LEFT JOIN user u ON(b.user_id = u.user_id)
                  WHERE b.backup_id > 0';

        $where = array();

        if (isset($data['user_id'])) {
            $sql .= ' AND b.user_id = ?';
            $where[] = $data['user_id'];
        }

        if (isset($data['id'])) {
            $sql .= ' AND b.id = ?';
            $where[] = $data['id'];
        }

        if (isset($data['version'])) {
            $sql .= ' AND b.version = ?';
            $where[] = $data['version'];
        }

        if (isset($data['name'])) {
            $sql .= ' AND b.name LIKE ?';
            $where[] = "%{$data['name']}%";
        }

        $allowed_order = array('asc', 'desc');
        $allowed_sort = array('name', 'user_id', 'version',
            'id', 'backup_id', 'type', 'created');

        if (isset($data['sort'])
            && in_array($data['sort'], $allowed_sort)
            && isset($data['order'])
            && in_array($data['order'], $allowed_order)
        ) {
            $sql .= " ORDER BY b.{$data['sort']} {$data['order']}";
        } else {
            $sql .= ' ORDER BY b.created DESC';
        }

        if (!empty($data['limit'])) {
            $sql .= ' LIMIT ' . implode(',', array_map('intval', $data['limit']));
        }

        if (!empty($data['count'])) {
            return (int) $this->db->fetchColumn($sql, $where);
        }

        $results = $this->db->fetchAll($sql, $where, array('index' => 'backup_id'));
        $this->hook->attach('module.backup.list', $results, $this);
        return $results;
    }
968002
public function prepare($sql)
    {
        if (! array_key_exists($sql, $this->statements)) {
            $this->statements[$sql] = $this->pdo->prepare($sql);

        }
        return $this->statements[$sql];
    }
11572
protected function prepareArrayPlaceholders($sql)
    {
        if (!count($this->arrays)) {
            return $sql;
        }
        foreach ($this->arrays as $placeholder => $array) {
            if (strpos($sql, $placeholder) === false) {
                continue;
            }

            $placeholders = [];
            $cnt = count($array);
            for ($i = 0; $i < $cnt; $i++) {
                $placeholders[] = $placeholder . $i;
            }
            $sql = str_replace($placeholder, '(' . implode(', ', $placeholders) . ')', $sql);
        }

        return $sql;
    }