/** * Performs the given query. * * Performs the $query, checks for errors and throws an exception in case. * Returns the generated statement object on success. If the $transaction * parameter is set to true, the query is excuted transaction save. * * @param ezcQuery $q * @param bool $transaction * @return PDOStatement * * @access private */ public function performQuery(ezcQuery $q, $transaction = false) { if ($transaction) { $this->database->beginTransaction(); } try { $stmt = $q->prepare(); $stmt->execute(); if (($errCode = $stmt->errorCode()) != 0) { if ($transaction) { $this->database->rollback(); } throw new ezcPersistentQueryException("The query returned error code {$errCode}.", $q); } if ($transaction) { $this->database->commit(); } return $stmt; } catch (PDOException $e) { if ($transaction) { $this->database->rollback(); } throw new ezcPersistentQueryException($e->getMessage(), $q); } }