Skip to content

Commit cd6755f

Browse files
committed
Changed delete $h->{$key} to work for keys with 'private_' prefix RT#83156
1 parent 3cef14e commit cd6755f

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ DBI::Changes - List of significant changes to the DBI
1414
driver_prefix is not fulfilled (RT#93204) [Jens Rehsack]
1515
Fixed redundant sprintf argument warning RT#97062 [Reini Urban]
1616

17+
Changed delete $h->{$key} to work for keys with 'private_' prefix
18+
per request in RT#83156. local $h->{$key} works as before.
19+
1720
Added security notice to DBD::Proxy and DBI::ProxyServer because they
1821
use Storable which is insecure. Thanks to [email protected] RT#90475
1922

DBI.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ my $keeperr = { O=>0x0004 };
411411
'FIRSTKEY' => $keeperr,
412412
'NEXTKEY' => $keeperr,
413413
'STORE' => { O=>0x0418 | 0x4 },
414+
'DELETE' => { O=>0x0404 },
414415
can => { O=>0x0100 }, # special case, see dispatch
415416
debug => { U =>[1,2,'[$debug_level]'], O=>0x0004 }, # old name for trace
416417
dump_handle => { U =>[1,3,'[$message [, $level]]'], O=>0x0004 },

DBI.xs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5445,6 +5445,19 @@ FETCH(h, keysv)
54455445
ST(0) = dbih_get_attr_k(h, keysv, 0);
54465446
(void)cv;
54475447

5448+
void
5449+
DELETE(h, keysv)
5450+
SV * h
5451+
SV * keysv
5452+
CODE:
5453+
/* only private_* keys can be deleted, for others DELETE acts like FETCH */
5454+
/* because the DBI internals rely on certain handle attributes existing */
5455+
if (strnEQ(SvPV_nolen(keysv),"private_",8))
5456+
ST(0) = hv_delete_ent((HV*)SvRV(h), keysv, 0, 0);
5457+
else
5458+
ST(0) = dbih_get_attr_k(h, keysv, 0);
5459+
(void)cv;
5460+
54485461

54495462
void
54505463
private_data(h)

lib/DBI/PurePerl.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,11 @@ sub STORE {
893893
$h->{$key} = $is_flag_attribute{$key} ? !!$value : $value;
894894
return 1;
895895
}
896+
sub DELETE {
897+
my ($h, $key) = @_;
898+
return $h->FETCH($key) unless $key =~ /^private_/;
899+
return delete $h->{$key};
900+
}
896901
sub err { return shift->{err} }
897902
sub errstr { return shift->{errstr} }
898903
sub state { return shift->{state} }

t/06attrs.t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ is_deeply [ $dbh->FETCH_many(qw(HandleError FetchHashKeyName LongReadLen ErrCoun
7979
[ undef, qw(NAME 80 0) ], 'should be able to FETCH_many';
8080

8181
is $dbh->{examplep_private_dbh_attrib}, 42, 'should see driver-private dbh attribute value';
82+
is delete $dbh->{examplep_private_dbh_attrib}, 42, 'delete on non-private attribute acts like fetch';
83+
is $dbh->{examplep_private_dbh_attrib}, 42, 'value unchanged after delete';
84+
85+
$dbh->{private_foo} = 42;
86+
is $dbh->{private_foo}, 42, 'should see private_foo dbh attribute value';
87+
is delete $dbh->{private_foo}, 42, 'delete should return private_foo dbh attribute value';
88+
is $dbh->{private_foo}, undef, 'value of private_foo after delete should be undef';
8289

8390
# Raise an error.
8491
eval {

0 commit comments

Comments
 (0)