-
Notifications
You must be signed in to change notification settings - Fork 7.9k
pgsqlSetNoticeCallback #6764
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
Closed
Closed
pgsqlSetNoticeCallback #6764
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dc0c27f
pgsqlSetNoticeCallback
outtersg 9cf61dc
pgsqlSetNoticeCallback: test case
outtersg dae9585
pgsqlSetNoticeCallback: test case for closure callback
outtersg 0ba336c
pgsqlSetNoticeCallback: tests: ensure where are "multiple calls"-proof
outtersg ae3d817
pgsqlSetNoticeCallback: test case for method callback
outtersg cac65e8
pgsqlSetNoticeCallback: tests: set client_min_messages
outtersg c757d02
pgsqlSetNoticeCallback: clean call to libpq
outtersg 5b12816
pgsqlSetNoticeCallback: more tests
outtersg 3d4d448
pgsqlSetNoticeCallback: standard ZPP and FCC
outtersg b0df768
pgsqlSetNoticeCallback: cleanup
outtersg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; | ||
require_once dirname(__FILE__) . '/config.inc'; | ||
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt'); | ||
|
||
attach($db); | ||
|
||
$db->beginTransaction(); | ||
$db->exec("set client_min_messages to notice"); | ||
$db->exec("create temporary table t (a varchar(3))"); | ||
$db->exec("create function hey() returns trigger as \$\$ begin new.a := 'oh'; raise notice 'I tampered your data, did you know?'; return new; end; \$\$ language plpgsql"); | ||
$db->exec("create trigger hop before insert on t for each row execute procedure hey()"); | ||
$db->exec("insert into t values ('ah')"); | ||
attach($db, 'Re'); | ||
$db->exec("delete from t"); | ||
$db->exec("insert into t values ('ah')"); | ||
$db->pgsqlSetNoticeCallback(null); | ||
$db->exec("delete from t"); | ||
$db->exec("insert into t values ('ah')"); | ||
var_dump($db->query("select * from t")->fetchAll(PDO::FETCH_ASSOC)); | ||
echo "Done\n"; | ||
$db->rollback(); | ||
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
pgsqlSetNoticeCallback catches Postgres "raise notice". | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); | ||
require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; | ||
require_once dirname(__FILE__) . '/config.inc'; | ||
PDOTest::skip(); | ||
?> | ||
--FILE-- | ||
<?php | ||
function disp($message) { echo trim($message)."\n"; } | ||
function dispRe($message) { echo "Re".trim($message)."\n"; } | ||
function attach($db, $prefix = '') | ||
{ | ||
$db->pgsqlSetNoticeCallback('disp'.$prefix); | ||
} | ||
require dirname(__FILE__) . '/issue78621.inc'; | ||
?> | ||
--EXPECT-- | ||
NOTICE: I tampered your data, did you know? | ||
ReNOTICE: I tampered your data, did you know? | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["a"]=> | ||
string(2) "oh" | ||
} | ||
} | ||
Done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--TEST-- | ||
pgsqlSetNoticeCallback catches Postgres "raise notice". | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); | ||
require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; | ||
require_once dirname(__FILE__) . '/config.inc'; | ||
PDOTest::skip(); | ||
?> | ||
--FILE-- | ||
<?php | ||
function disp($message) { echo trim($message)."\n"; } | ||
function attach($db, $prefix = '') | ||
{ | ||
global $flavor; | ||
switch($flavor) | ||
{ | ||
case 0: | ||
$db->pgsqlSetNoticeCallback(function($message) use($prefix) { echo $prefix.trim($message)."\n"; }); | ||
// https://github.com/php/php-src/pull/4823#pullrequestreview-335623806 | ||
$eraseCallbackMemoryHere = (object)[1]; | ||
break; | ||
case 1: | ||
$closure = function($message) use($prefix) { echo $prefix.'('.get_class($this).')'.trim($message)."\n"; }; | ||
$db->pgsqlSetNoticeCallback($closure->bindTo(new \stdClass)); | ||
break; | ||
} | ||
} | ||
echo "Testing with a simple inline closure:\n"; | ||
$flavor = 0; | ||
require dirname(__FILE__) . '/issue78621.inc'; | ||
echo "Testing with a postbound closure object:\n"; | ||
++$flavor; | ||
require dirname(__FILE__) . '/issue78621.inc'; | ||
?> | ||
--EXPECT-- | ||
Testing with a simple inline closure: | ||
NOTICE: I tampered your data, did you know? | ||
ReNOTICE: I tampered your data, did you know? | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["a"]=> | ||
string(2) "oh" | ||
} | ||
} | ||
Done | ||
Testing with a postbound closure object: | ||
(stdClass)NOTICE: I tampered your data, did you know? | ||
Re(stdClass)NOTICE: I tampered your data, did you know? | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["a"]=> | ||
string(2) "oh" | ||
} | ||
} | ||
Done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--TEST-- | ||
pgsqlSetNoticeCallback catches Postgres "raise notice". | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded'); | ||
require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc'; | ||
require_once dirname(__FILE__) . '/config.inc'; | ||
PDOTest::skip(); | ||
?> | ||
--FILE-- | ||
<?php | ||
class Logger | ||
{ | ||
public function disp($message) { echo trim($message)."\n"; } | ||
public function dispRe($message) { echo "Re".trim($message)."\n"; } | ||
public function __call(string $method, array $args) | ||
{ | ||
$realMethod = strtr($method, [ 'whatever' => 'disp' ]); | ||
echo "$method trampoline for $realMethod\n"; | ||
return call_user_func_array([ $this, $realMethod ], $args); | ||
} | ||
} | ||
$logger = new Logger(); | ||
function attach($db, $prefix = '') | ||
{ | ||
global $logger; | ||
global $flavor; | ||
switch($flavor) | ||
{ | ||
case 0: $db->pgsqlSetNoticeCallback([ $logger, 'disp'.$prefix ]); break; | ||
case 1: $db->pgsqlSetNoticeCallback([ $logger, 'whatever'.$prefix ]); break; | ||
} | ||
} | ||
echo "Testing with method explicitely plugged:\n"; | ||
$flavor = 0; | ||
require dirname(__FILE__) . '/issue78621.inc'; | ||
echo "Testing with a bit of magic:\n"; | ||
++$flavor; | ||
require dirname(__FILE__) . '/issue78621.inc'; | ||
?> | ||
--EXPECT-- | ||
Testing with method explicitely plugged: | ||
NOTICE: I tampered your data, did you know? | ||
ReNOTICE: I tampered your data, did you know? | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["a"]=> | ||
string(2) "oh" | ||
} | ||
} | ||
Done | ||
Testing with a bit of magic: | ||
whatever trampoline for disp | ||
NOTICE: I tampered your data, did you know? | ||
whateverRe trampoline for dispRe | ||
ReNOTICE: I tampered your data, did you know? | ||
array(1) { | ||
[0]=> | ||
array(1) { | ||
["a"]=> | ||
string(2) "oh" | ||
} | ||
} | ||
Done |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.