/** * Executes a prepared statement * * Execute the prepared statement. If the prepared statement included parameter markers, you must either: * * call PDOStatement::bindParam() to bind PHP variables to the parameter markers: bound variables pass * their value as input and receive the output value, if any, of their associated parameter markers * or pass an array of input-only parameter values * * * @param array|null $inputParameters - An array of values with as many elements as there are bound parameters * in the SQL statement being executed. All values are treated * as PDO::PARAM_STR. (not yet implemented because of a bug in vitess) * * You cannot bind multiple values to a single parameter; for example, * you cannot bind two values to a single named parameter in an IN() clause. * * You cannot bind more values than specified; if more keys exist * in input_parameters than in the SQL specified in the PDO::prepare(), * then the statement will fail and an error is emitted. * @return bool * @throws PDOException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(array $inputParameters = null) { $this->reset(); if ($inputParameters) { if (array_key_exists(0, $inputParameters)) { $inputParameters = $this->repairUnnamedParamsArray($inputParameters); } foreach ($inputParameters as $key => $value) { $this->bindValue($key, $value); // default type is string } } $vitessMethod = 'executeRead'; $query = $this->queryAnalyzer->parseQuery($this->query); if ($query->isWritable()) { $vitessMethod = 'executeWrite'; } try { /* @var $result ResultInterface */ $result = $this->executor->{$vitessMethod}($query, $this->params); $this->setResult($result); if (!$result->isSuccess()) { return false; } $this->cursor = new Cursor($result->getCursor(), $this->fetcherFactory); } catch (CoreException $e) { $this->setResult(new PDO\Vitess\Result(null, $e)); if ($e instanceof PDOException && $this->attributes->isErrorModeException()) { throw $e; } return false; } return true; }
/** * @param VitessException $exception * * @throws PDOException */ private function handleException(VitessException $exception) { switch (true) { case $this->attributes->isErrorModeSilent(): break; case $this->attributes->isErrorModeWarning(): trigger_error($exception->getMessage(), E_WARNING); break; case $this->attributes->isErrorModeException(): throw new PDOException("Vitess exception (check previous exception stack): " . $exception->getMessage(), 0, $exception); break; } }
/** * Executes an SQL statement, returning a result set as a PDOStatement object * * public PDOStatement PDO::query ( string $statement ) * public PDOStatement PDO::query ( string $statement, int $PDO::FETCH_COLUMN, int $colno ) * public PDOStatement PDO::query ( string $statement, int $PDO::FETCH_CLASS, string $classname, array $ctorargs ) * public PDOStatement PDO::query ( string $statement, int $PDO::FETCH_INTO, object $object ) * * PDO::query() executes an SQL statement in a single function call, returning the result set (if any) returned * by the statement as a PDOStatement object. * * For a query that you need to issue multiple times, you will realize better performance if you prepare * a PDOStatement object using PDO::prepare() and issue the statement with multiple calls * to PDOStatement::execute(). * * If you do not fetch all of the data in a result set before issuing your next call to PDO::query(), your call * may fail. Call PDOStatement::closeCursor() to release the database resources associated with the PDOStatement * object before issuing your next call to PDO::query(). * * Note: * Although this function is only documented as having a single parameter, you may pass additional arguments * to this function. They will be treated as though you called PDOStatement::setFetchMode() * on the resultant statement object. * * @param string $statement - The SQL statement to prepare and execute. * Data inside the query should be properly escaped. * @param int $fetchStyle * @param mixed $fetchArgument * @param array|null $ctorArgs * * @return PDOStatement|false - PDO::query() returns a PDOStatement object, or FALSE on failure. * @throws PDOException * @throws Exception */ public function query($statement, $fetchStyle = CorePdo::FETCH_BOTH, $fetchArgument = null, array $ctorArgs = []) { $pdoStatement = $this->prepare($statement); try { $pdoStatement->execute(); $pdoStatement->fetchAll($fetchStyle, $fetchArgument, $ctorArgs); } catch (Exception $e) { if ($this->attributes->isErrorModeException()) { throw $e; } return false; } return $pdoStatement; }