/** * @throws DBQueryException * @param ISqlQUery $query * @param boolean $isAsync * @return resource */ protected function performQuery(ISqlQuery $query, $isAsync) { Assert::isBoolean($isAsync); $parameters = $query->getPlaceholderValues($this->getDialect()); $queryAsString = $query->toDialectString($this->getDialect()); if ($isAsync) { LoggerPool::log(parent::LOG_VERBOSE, 'sending an async query: %s', $queryAsString); } else { LoggerPool::log(parent::LOG_VERBOSE, 'sending query: %s', $queryAsString); } LoggerPool::log(parent::LOG_QUERY, $queryAsString); $executeResult = pg_send_query($this->link, $queryAsString); if (!$isAsync || !$executeResult) { $result = pg_get_result($this->link); $resultStatus = pg_result_status($result, PGSQL_STATUS_LONG); if (in_array($resultStatus, array(PGSQL_EMPTY_QUERY, PGSQL_BAD_RESPONSE, PGSQL_NONFATAL_ERROR, PGSQL_FATAL_ERROR))) { $errorCode = pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); $errorMessage = pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY); if (PgSqlError::UNIQUE_VIOLATION == $errorCode) { LoggerPool::log(parent::LOG_VERBOSE, 'query caused a unique violation: %s', $errorMessage); throw new UniqueViolationException($query, $errorMessage); } else { LoggerPool::log(parent::LOG_VERBOSE, 'query caused an error #%s: %s', $errorCode, $errorMessage); throw new PgSqlQueryException($query, $errorMessage, $errorCode); } } } return $result; }
/** * @throws DBQueryException * @param ISqlQUery $query * @param boolean $isAsync * @return resource */ protected function performQuery(ISqlQuery $query, $isAsync) { $queryAsString = $query->toDialectString($this->getDialect()); LoggerPool::log(parent::LOG_VERBOSE, 'sending query: %s', $queryAsString); LoggerPool::log(parent::LOG_QUERY, $queryAsString); $result = mysql_query($queryAsString, $this->link); if (!$result) { $code = mysql_errno($this->link); $error = mysql_error($this->link); if ($code == 1062) { LoggerPool::log(parent::LOG_VERBOSE, 'query caused a unique violation #%s: %s', $code, $error); throw new UniqueViolationException($query, $error); } else { LoggerPool::log(parent::LOG_VERBOSE, 'query caused an error #%s: %s', $code, $error); throw new DBQueryException($query, $error, $code); } } Assert::isTrue(is_resource($result) || $result === true); return $result; }