/** * 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; } }
/** * Retrieve a database connection attribute * * This function returns the value of a database connection attribute. To retrieve PDOStatement attributes, * refer to PDOStatement::getAttribute(). * Note that some database/driver combinations may not support all of the database connection attributes. * * @param int $attribute - One of the PDO::ATTR_* constants. The constants that apply to database * connections are as follows: * PDO::ATTR_AUTOCOMMIT * PDO::ATTR_CASE * PDO::ATTR_CLIENT_VERSION * PDO::ATTR_CONNECTION_STATUS * PDO::ATTR_DRIVER_NAME * PDO::ATTR_ERRMODE * PDO::ATTR_ORACLE_NULLS * PDO::ATTR_PERSISTENT * PDO::ATTR_PREFETCH * PDO::ATTR_SERVER_INFO * PDO::ATTR_SERVER_VERSION * PDO::ATTR_TIMEOUT * * @return mixed - A successful call returns the value of the requested PDO attribute. * An unsuccessful call returns null. */ public function getAttribute($attribute) { return $this->attributes->get($attribute); }