Executes an SQL query on the storage engine. Should be used for SELECT
only.

@access public
@author Jerome Bogaerts, <jerome@taotesting.com>
@param  string statement
@param  array params
@return PDOStatement
1935
public function query($statement, $params = array())
    {
        $returnValue = null;

        
//         $trace=debug_backtrace();
//         $caller=array_shift($trace);
//         $caller=array_shift($trace);
//         common_Logger::d('trace : '. $caller['function'] .$caller['class'] );
//         common_Logger::d($statement . implode('|', $params));
       	$sth = $this->persistence->query($statement,$params);
		
        if (!empty($sth)){
        	$returnValue = $sth;
        }

        $this->incrementNrOfQueries();
        return $returnValue;
    }
247037
private function executeWrite($statement, array $parameters)
    {
        if ($this->transactionCount == 0) {
            $connection = $this->pool->selectWriteConnection();
        } else {
            $connection = $this->transactionConnection;
        }

        try {
            return $connection->execute(
                $this->expandPlaceholders($statement, $parameters),
                $parameters
            );
        } catch (ConnectionException $e) {
            $this->pool->disableWriteConnection($connection);
            if ($this->pool->getWriteConnectionCount() == 0) {
                throw $e;
            }

            return $this->executeWrite($statement, $parameters);
        }
    }
457332
public function statement($sql, $bindings = array())
    {
        $start = microtime(true);
        $pdoStatement = $this->pdo->prepare($sql);
        foreach ($bindings as $key => $value) {
            $pdoStatement->bindValue(
                is_int($key) ? $key + 1 : $key,
                $value,
                is_int($value) || is_bool($value) ? PDO::PARAM_INT : PDO::PARAM_STR
            );
        }
        $pdoStatement->execute();
        return array($pdoStatement, microtime(true) - $start);
    }
343396
public function bindParameters(\PDOStatement $statement)
    {
        foreach (array_keys($this->params) as $key)
        {
            $type = $this->param_types[$key];
            $statement->bindParam($key, $this->params[$key], $type);
        }
        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);
	}
1254347
public function queryAssoc($statement, $params = array()) {
        $start = microtime(true);
        $query = $this->prepare($statement);
        try {
            $query->execute($params);
        } catch (\PDOException $e){
            $this->error($e->getMessage(), array(
                'File' => __FILE__,
                'Line' => __LINE__ - 4,
                'Query' => $statement .'',
                'Params' => $params,
                'Trace' => $e->getTraceAsString()
            ));
            return null;
        }
        $r = $query->fetchAll(\PDO::FETCH_ASSOC);
        $this->debug($statement . '', array(
            'params' => $params,
            'intoArray' => 'assoc',
            'rows' => count($r),
            'time' => microtime(true) - $start,
            'dns' => $this->dns
        ));
        return $r;
    }
162804
public function _execute(array $params = null)
    {
        try {
            if ($params !== null) {
                return $this->_stmt->execute($params);
            } else {
                return $this->_stmt->execute();
            }
        } catch (PDOException $e) {
            // require_once 'Zend/Db/Statement/Exception.php';
            throw new Zend_Db_Statement_Exception($e->getMessage(), (int) $e->getCode(), $e);
        }
    }
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;
        });
    }
341873
public function exec($statement) {
		try {
			return $this->pdo->exec($statement);
		} catch (PDOException $e) {
			throw $this->exceptionAdapter->adapt($e, $statement);
		}
	}
1302544
public function queryClass($statement, $classname, $params = array(), $ctorargs = array()) {
        $start = microtime(true);
        $q = $statement . '';
        if (is_a($statement, ModelCondition::className())){
            foreach ($statement->getJoinParams() as $k=>$v){
                $params[$k] = $v;
            }
        }
        $statement = $this->prepare($q);
        try {
            $statement->execute($params);
        } catch (\PDOException $e){
            $this->error($e->getMessage(), array(
                'File' => __FILE__,
                'Line' => __LINE__ - 4,
                'Query' => $q,
                'Params' => $params,
                'Trace' => $e->getTraceAsString()
            ));
            return null;
        }
        $objects = array();
        while ($ob = $statement->fetchObject($classname, $ctorargs)) {
            $objects[] = $ob;
        }
        $this->debug($q, array(
            'params' => $params,
            'intoClass' => $classname,
            'controllerArguments' => $ctorargs,
            'rows' => count($objects),
            'time' => microtime(true) - $start,
            'dns' => $this->dns
        ));
        return $objects;
    }
806553
public function queryHandle(Statement $statement): \PDOStatement
    {
        // 记录开始时间
        $begin = timeLog();

        // 获取要执行的语句的Prepare和Params
        $prepare = $statement->getPrepare();
        $params = $statement->getParams();

        // 先记日志,以免错误导致无日志
        FileLog::instance()->sqlBefore('queryHandle', $statement->getSql());

        // 从读服务器进行
        $connect = $this->connectRead();

        // 禁止缓存
        $connect->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

        // 如果绑定参数为空,直接执行就好.
        if (empty($params)) {
            $result = $connect->query($prepare);
        } else {
            $stmt = $connect->prepare($prepare);
            $stmt->execute($params);
            $result = $stmt;
        }

        // 查询完成,再次打开缓存
        $connect->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);

        // 计算耗时
        $interval = timeLog($begin);

        // 记录耗时
        FileLog::instance()->sqlAfter('afterQueryHandle', $statement->getSql(), $result, $interval, $statement->getOperation());

        Debug::setSql('QueryHandle', $prepare, $interval * 1000, $params, $statement->getSql());
        return $result;
    }
1273079
public function execute($sql, $params = null)
    {
        $stmt = $this->_pdo->prepare($sql);

        if (is_array($params)) {
            foreach ($params as $token => $value) {
                $stmt->bindValue($token, $value);
            }
        }

        try {
            $stmt->execute();
        } catch (PDOException $exception) {
            $this->_database->error('execute', $exception);
        }

        return $stmt;
    }
1142935
public int[] executeBatchPreparedStatement(String statement, Collection inParamsBatch) throws SQLException {
		return executeBatchPreparedStatement(statement, inParamsBatch, true);
	}
1101848
public function query($statement, $mode=null, $p1=null, $p2=null)
    {
        // TODO: use mode and parameters
        $stmt = null;
        try {
            $stmt = new Statement($this, $statement);
            $stmt->execute();
            $this->setError();
            return $stmt;
        } catch (\Exception $e) {
            throw new \PDOException($e->getMessage());
        }
        return $stmt;
    }
138225
public function statement( $query, $params = array() )
	{
		// we alway prepare the query even if we dont have parameters
		$sth = $this->driver()->connection()->prepare( $query );
		
		// because we set pdo the throw exception on db errors
		// we catch them here to throw our own exception.
		try 
		{
			$sth->execute( $params );
		}
		catch ( \PDOException $e ) 
		{
			throw new Exception( "DB\\Handler - PDOException: {$e->getMessage()} \n Query: {$query}" );
		}
		
		// In development we alway log the query into an array.
		if ( \ClanCats::in_development() ) 
		{	
			$keys = array();
			
			foreach ( $params as $key => $value ) 
			{
				if ( is_string( $key ) ) 
				{
					$keys[] = '/:'.$key.'/';
				} else {
					$keys[] = '/[?]/';
				}
			}
			
			static::$_query_log[] = preg_replace( $keys, $params, $query, 1 );
		}
		
		return $sth;
	}
80191
public static boolean execute(PreparedStatement ps, Object... params) throws SQLException {
		StatementUtil.fillParams(ps, params);
		return ps.execute();
	}
219754
protected function fetchCol($statement, array $params = array(), array $types = array()): array
    {
        $result = array();

        $rows = $this->getDb()->fetchAll($statement, $params, $types);

        foreach ($rows as $row) {
            $result[] = current($row);
        }

        return $result;
    }