Skip to content

Conversation

@sartor
Copy link

@sartor sartor commented Mar 20, 2020

All PgSQL queries didn't show full SQL ext of failed query.
This PR add functionality to show failed query text instead of "Current query was 0"

* @throws QueryError
*/
private function createResult($result)
private function createResult($result, &$sql)
Copy link
Member

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 making this a reference?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just want to save memory by preventing large SQL string copy.

foreach (self::DIAGNOSTIC_CODES as $fieldCode => $desciption) {
$diagnostics[$desciption] = \pg_result_error_field($result, $fieldCode);
}
$diagnostics['sql'] = $sql;
Copy link
Member

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?

Copy link
Author

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

public function __construct(string $message, array $diagnostics, \Throwable $previous = null)
{
parent::__construct($message, 0, $previous);
parent::__construct($message, $diagnostics['sql'], $previous);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A string should not be used for the code.

Copy link
Author

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it does, I didn't realize QueryError had a custom constructor taking the SQL query. Not providing it to QueryExecutionError was certainly an oversight before.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should I do?

{
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$name is not the query SQL.

Copy link
Author

Choose a reason for hiding this comment

The 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

@trowski trowski closed this in 13ac10a Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants