-
-
Notifications
You must be signed in to change notification settings - Fork 21
PgSql now shows text of failed query in Exception #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,13 +241,14 @@ private function send(callable $function, ...$args): \Generator | |
|
|
||
| /** | ||
| * @param resource $result PostgreSQL result resource. | ||
| * @param string $sql SQL query text or statement id for error message | ||
| * | ||
| * @return \Amp\Sql\CommandResult|ResultSet | ||
| * | ||
| * @throws FailureException | ||
| * @throws QueryError | ||
| */ | ||
| private function createResult($result) | ||
| private function createResult($result, $sql) | ||
| { | ||
| switch (\pg_result_status($result, \PGSQL_STATUS_LONG)) { | ||
| case \PGSQL_EMPTY_QUERY: | ||
|
|
@@ -265,6 +266,7 @@ private function createResult($result) | |
| foreach (self::DIAGNOSTIC_CODES as $fieldCode => $desciption) { | ||
| $diagnostics[$desciption] = \pg_result_error_field($result, $fieldCode); | ||
| } | ||
| $diagnostics['sql'] = $sql; | ||
| throw new QueryExecutionError(\pg_result_error($result), $diagnostics); | ||
|
|
||
| case \PGSQL_BAD_RESPONSE: | ||
|
|
@@ -286,7 +288,7 @@ private function createResult($result) | |
| public function statementExecute(string $name, array $params): Promise | ||
| { | ||
| return call(function () use ($name, $params) { | ||
| return $this->createResult(yield from $this->send("pg_send_execute", $name, $params)); | ||
| return $this->createResult(yield from $this->send("pg_send_execute", $name, $params), $name); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought name of statement may be more usefull than nothing. I can remove it |
||
| }); | ||
| } | ||
|
|
||
|
|
@@ -326,7 +328,7 @@ public function query(string $sql): Promise | |
| } | ||
|
|
||
| return call(function () use ($sql) { | ||
| return $this->createResult(yield from $this->send("pg_send_query", $sql)); | ||
| return $this->createResult(yield from $this->send("pg_send_query", $sql), $sql); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -343,7 +345,7 @@ public function execute(string $sql, array $params = []): Promise | |
| $params = Internal\replaceNamedParams($params, $names); | ||
|
|
||
| return call(function () use ($sql, $params) { | ||
| return $this->createResult(yield from $this->send("pg_send_query_params", $sql, $params)); | ||
| return $this->createResult(yield from $this->send("pg_send_query_params", $sql, $params), $sql); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -396,6 +398,7 @@ public function prepare(string $sql): Promise | |
| foreach (self::DIAGNOSTIC_CODES as $fieldCode => $description) { | ||
| $diagnostics[$description] = \pg_result_error_field($result, $fieldCode); | ||
| } | ||
| $diagnostics['sql'] = $modifiedSql; | ||
| throw new QueryExecutionError(\pg_result_error($result), $diagnostics); | ||
|
|
||
| case \PGSQL_BAD_RESPONSE: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ class QueryExecutionError extends QueryError | |
|
|
||
| public function __construct(string $message, array $diagnostics, \Throwable $previous = null) | ||
| { | ||
| parent::__construct($message, 0, $previous); | ||
| parent::__construct($message, $diagnostics['sql'], $previous); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A string should not be used for the code.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? parent constructor have exactly string parameter at this place? Any ideas how to pass this without string?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it does, I didn't realize
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should I do? |
||
| $this->diagnostics = $diagnostics; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for adding this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$diagnostics will be used in QueryExecutionError for error message. 'sql' key will contain failed query