Skip to content

Commit

Permalink
Allow $sth NAME_* attributes to be set from perl code
Browse files Browse the repository at this point in the history
Relates to #45
  • Loading branch information
timbunce committed Aug 13, 2017
1 parent 79b2c9c commit a43696a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions DBI.xs
Expand Up @@ -2268,6 +2268,16 @@ dbih_set_attr_k(SV *h, SV *keysv, int dbikey, SV *valuesv)
) ) {
cacheit = 1;
}
/* deal with: NAME_(uc|lc), NAME_hash, NAME_(uc|lc)_hash */
else if ((keylen==7 || keylen==9 || keylen==12)
&& strnEQ(key, "NAME_", 5)
&& ( (keylen==9 && strEQ(key, "NAME_hash"))
|| ((key[5]=='u' || key[5]=='l') && key[6] == 'c'
&& (!key[7] || strnEQ(&key[7], "_hash", 5)))
)
) {
cacheit = 1;
}
else { /* XXX should really be an event ? */
if (isUPPER(*key)) {
char *msg = "Can't set %s->{%s}: unrecognised attribute name or invalid value%s";
Expand Down
10 changes: 10 additions & 0 deletions t/06attrs.t
@@ -1,6 +1,7 @@
#!perl -w

use strict;
use Storable qw(dclone);

use Test::More;

Expand Down Expand Up @@ -255,6 +256,15 @@ cmp_ok(scalar(keys(%{$nhash_uc})), '==', 2, '... checking number of keys returne
cmp_ok($nhash_uc->{CTIME}, '==', 0, '... checking values returned');
cmp_ok($nhash_uc->{NAME}, '==', 1, '... checking values returned');

unless ($using_autoproxy) {
# set ability to set sth attributes that are usually set internally
for $a (qw(NAME NAME_lc NAME_uc NAME_hash NAME_lc_hash NAME_uc_hash)) {
my $v = $sth->{$a};
ok(eval { $sth->{$a} = dclone($sth->{$a}) }, "Can set sth $a");
is_deeply($sth->{$a}, $v, "Can get set sth $a");
}
}

my $type = $sth->{TYPE};
is(ref($type), 'ARRAY', '... checking type of TYPE attribute for sth');
cmp_ok(scalar(@{$type}), '==', 2, '... checking number of elements returned');
Expand Down

0 comments on commit a43696a

Please sign in to comment.