-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/pgsql: adding pg_set_error_context_visibility. #11395
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 1 commit
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 |
---|---|---|
|
@@ -2833,6 +2833,36 @@ PHP_FUNCTION(pg_set_error_verbosity) | |
} | ||
/* }}} */ | ||
|
||
PHP_FUNCTION(pg_set_error_context_visibility) | ||
{ | ||
zval *pgsql_link = NULL; | ||
zend_long visibility; | ||
PGconn *pgsql; | ||
pgsql_link_handle *link; | ||
|
||
if (ZEND_NUM_ARGS() == 1) { | ||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &visibility) == FAILURE) { | ||
RETURN_THROWS(); | ||
} | ||
link = FETCH_DEFAULT_LINK(); | ||
CHECK_DEFAULT_LINK(link); | ||
} else { | ||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &pgsql_link, pgsql_link_ce, &visibility) == FAILURE) { | ||
RETURN_THROWS(); | ||
} | ||
link = Z_PGSQL_LINK_P(pgsql_link); | ||
CHECK_PGSQL_LINK(link); | ||
} | ||
|
||
pgsql = link->conn; | ||
|
||
if (visibility & (PQSHOW_CONTEXT_NEVER|PQSHOW_CONTEXT_ERRORS|PQSHOW_CONTEXT_ALWAYS)) { | ||
RETURN_LONG(PQsetErrorContextVisibility(pgsql, visibility)); | ||
} else { | ||
RETURN_FALSE; | ||
} | ||
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. Make this a ValueError in case of a wrong value? |
||
} | ||
|
||
/* {{{ Set client encoding */ | ||
PHP_FUNCTION(pg_set_client_encoding) | ||
{ | ||
|
@@ -3331,7 +3361,7 @@ PHP_FUNCTION(pg_result_error) | |
RETURN_FALSE; | ||
} | ||
|
||
err = (char *)PQresultErrorMessage(pgsql_result); | ||
err = PQresultErrorMessage(pgsql_result); | ||
RETURN_STRING(err); | ||
} | ||
/* }}} */ | ||
|
@@ -3365,7 +3395,7 @@ PHP_FUNCTION(pg_result_error_field) | |
#endif | ||
|PG_DIAG_CONTEXT|PG_DIAG_SOURCE_FILE|PG_DIAG_SOURCE_LINE | ||
|PG_DIAG_SOURCE_FUNCTION)) { | ||
field = (char *)PQresultErrorField(pgsql_result, (int)fieldcode); | ||
field = PQresultErrorField(pgsql_result, (int)fieldcode); | ||
if (field == NULL) { | ||
RETURN_NULL(); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -462,6 +462,25 @@ | |||||||
*/ | ||||||||
const PGSQL_PIPELINE_ABORTED = UNKNOWN; | ||||||||
#endif | ||||||||
|
||||||||
/* For pg_set_error_context_visibility() */ | ||||||||
|
||||||||
/** | ||||||||
* @var int | ||||||||
* @cvalue PQSHOW_CONTEXT_NEVER | ||||||||
*/ | ||||||||
const PGSQL_SHOW_CONTEXT_NEVER = UNKNOWN; | ||||||||
/** | ||||||||
* @var int | ||||||||
* @cvalue PQSHOW_CONTEXT_ERRORS | ||||||||
*/ | ||||||||
const PGSQL_SHOW_CONTEXT_ERRORS = UNKNOWN; | ||||||||
/** | ||||||||
* @var int | ||||||||
* @cvalue PQSHOW_CONTEXT_ALWAYS | ||||||||
*/ | ||||||||
const PGSQL_SHOW_CONTEXT_ALWAYS = UNKNOWN; | ||||||||
|
||||||||
|
||||||||
function pg_connect(string $connection_string, int $flags = 0): PgSql\Connection|false {} | ||||||||
|
||||||||
|
@@ -951,6 +970,9 @@ function pg_exit_pipeline_mode(PgSql\Connection $connection): bool {} | |||||||
function pg_pipeline_sync(PgSql\Connection $connection): bool {} | ||||||||
function pg_pipeline_status(PgSql\Connection $connection): int {} | ||||||||
#endif | ||||||||
|
||||||||
/** @param PgSql\Connection|int $connection */ | ||||||||
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. This comment is not needed any more now. |
||||||||
function pg_set_error_context_visibility($connection, int $visibility = UNKNOWN): int|false {} | ||||||||
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. Since the visibility is not optional anymore and it doesn't return false on failure.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
namespace PgSql { | ||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,11 @@ if (function_exists('pg_set_error_verbosity')) { | |
pg_set_error_verbosity($db, PGSQL_ERRORS_VERBOSE); | ||
pg_set_error_verbosity($db, PGSQL_ERRORS_SQLSTATE); | ||
} | ||
if (function_exists('pg_set_error_context_visibility')) { | ||
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_NEVER); | ||
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ERRORS); | ||
pg_set_error_context_visibility($db, PGSQL_SHOW_CONTEXT_ALWAYS); | ||
} | ||
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. It looks like it's always defined? |
||
echo "OK"; | ||
?> | ||
--EXPECT-- | ||
|
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.
Considering we have deprecated the fetching of the default link I would rather not introduce a new function with this functionality. Would also make the stubs correct.
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.
oky doky