Skip to content

Commit 89fe486

Browse files
committed
Changes for DBI-1.40
git-svn-id: https://svn.perl.org/modules/dbi/trunk@46 50811bd7-b8ce-0310-adc1-d9db26280581
1 parent 8c365bc commit 89fe486

14 files changed

+452
-267
lines changed

Changes

+16-10
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ DBI::Changes - List of significant changes to the DBI
44

55
=cut
66

7-
Need to add docs for DbTypeSubclass (ala DBIx::AnyDBD)
8-
Move TIEHASH etc to XS (and pureperl)
7+
=head1 CHANGES
98

10-
$dbh->{Statement} can be wrong because fetch doesn't update value
11-
maybe imp_dbh holds imp_sth (or inner handle) of last sth method
12-
called (if not DESTROY) and sth outer DESTROY clears it (to reduce ref count)
13-
Then $dbh->{LastSth} would work (returning outer handle if valid).
14-
Then $dbh->{Statement} would be the same as $dbh->{LastSth}->{Statement}
15-
Also $dbh->{ParamValues} would be the same as $dbh->{LastSth}->{ParamValues}.
16-
Add more macro hooks to Driver.xst: ping, quote etc.
9+
=head2 Changes in DBI 1.40, 7th January 2004
1710

18-
=head1 CHANGES
11+
Fixed handling of CachedKids when DESTROYing threaded handles.
12+
Fixed sql_user_name() in DBI::DBD::Metadata (used by write_getinfo_pm)
13+
to use $dbh->{Username}. Driver authors please update your code.
14+
15+
Changed connect_cached() when running under Apache::DBI
16+
to route calls to Apache::DBI::connect().
17+
18+
Added CLONE() to DBD::Sponge and DBD::ExampleP.
19+
Added warning when starting a new thread about any loaded driver
20+
which does not have a CLONE() function.
21+
Added new prepare_cache($sql, \%attr, 3) option to manage Active handles.
22+
Added SCALE and NULLABLE support to DBD::Sponge.
23+
Added missing execute() in fetchall_hashref docs thanks to Iain Truskett.
24+
Added a CONTRIBUTING section to the docs with notes on creating patches.
1925

2026
=head2 Changes in DBI 1.39, 27th November 2003
2127

DBI.pm

+126-70
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# $Id: DBI.pm,v 11.40 2003/11/27 23:29:06 timbo Exp $
1+
# $Id: DBI.pm,v 11.42 2004/01/08 14:03:46 timbo Exp $
22
# vim: ts=8:sw=4
33
#
4-
# Copyright (c) 1994-2003 Tim Bunce Ireland
4+
# Copyright (c) 1994-2004 Tim Bunce Ireland
55
#
66
# See COPYRIGHT section in pod text below for usage and distribution rights.
77
#
88

99
require 5.006_00;
1010

1111
BEGIN {
12-
$DBI::VERSION = "1.39"; # ==> ALSO update the version in the pod text below!
12+
$DBI::VERSION = "1.40"; # ==> ALSO update the version in the pod text below!
1313
}
1414

1515
=head1 NAME
@@ -84,10 +84,9 @@ I<The synopsis above only lists the major methods and parameters.>
8484
8585
=head2 GETTING HELP
8686
87-
If you have questions about DBI, you can get help from
88-
the I<[email protected]> mailing list.
89-
You can get help on subscribing and using the list by emailing
90-
87+
If you have questions about DBI, or DBD driver modules, you can get
88+
help from the I<[email protected]> mailing list. You can get help
89+
on subscribing and using the list by emailing I<[email protected]>.
9190
9291
(To help you make the best use of the dbi-users mailing list,
9392
and any other lists or forums you may use, I I<strongly>
@@ -119,8 +118,8 @@ Tim he's very likely to just forward it to the mailing list.
119118
120119
=head2 NOTES
121120
122-
This is the DBI specification that corresponds to the DBI version 1.39
123-
(C<$Date: 2003/11/27 23:29:06 $>).
121+
This is the DBI specification that corresponds to the DBI version 1.40
122+
(C<$Date: 2004/01/08 14:03:46 $>).
124123
125124
The DBI is evolving at a steady pace, so it's good to check that
126125
you have the latest copy.
@@ -151,7 +150,7 @@ L<"http://search.cpan.org/search?query=DBI&mode=all">.
151150

152151
package DBI;
153152

154-
my $Revision = substr(q$Revision: 11.40 $, 10);
153+
my $Revision = substr(q$Revision: 11.42 $, 10);
155154

156155
use Carp();
157156
use DynaLoader ();
@@ -394,7 +393,7 @@ my @Common_IF = ( # Interface functions common to all DBI classes
394393
last_insert_id => { U =>[3,4,'$table_name, $field_name [, \%attr ]'], O=>0x0100 },
395394
preparse => { }, # XXX
396395
prepare => { U =>[2,3,'$statement [, \%attr]'], O=>0x0200 },
397-
prepare_cached => { U =>[2,4,'$statement [, \%attr [, $allow_active ] ]'] },
396+
prepare_cached => { U =>[2,4,'$statement [, \%attr [, $if_active ] ]'] },
398397
selectrow_array => { U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
399398
selectrow_arrayref=>{U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
400399
selectrow_hashref=>{ U =>[2,0,'$statement [, \%attr [, @bind_params ] ]'] },
@@ -479,18 +478,26 @@ END {
479478
sub CLONE {
480479
my $olddbis = $DBI::_dbistate;
481480
_clone_dbis() unless $DBI::PurePerl; # clone the DBIS structure
482-
%DBI::installed_drh = (); # clear loaded drivers so they have a chance to reinitialize
483481
DBI->trace_msg(sprintf "CLONE DBI for new thread %s\n",
484482
$DBI::PurePerl ? "" : sprintf("(dbis %x -> %x)",$olddbis, $DBI::_dbistate));
483+
while ( my ($driver, $drh) = each %DBI::installed_drh) {
484+
no strict 'refs';
485+
next if defined &{"DBD::${driver}::CLONE"};
486+
warn("$driver has no driver CLONE() function so is unsafe threaded\n");
487+
}
488+
%DBI::installed_drh = (); # clear loaded drivers so they have a chance to reinitialize
485489
}
486490

487491

488492
# --- The DBI->connect Front Door methods
489493

490494
sub connect_cached {
491-
# XXX we expect Apache::DBI users to still call connect()
495+
# For library code using connect_cached() with mod_perl
496+
# we redirect those calls to Apache::DBI::connect() as well
492497
my ($class, $dsn, $user, $pass, $attr) = @_;
493-
($attr ||= {})->{dbi_connect_method} = 'connect_cached';
498+
($attr ||= {})->{dbi_connect_method} =
499+
($DBI::connect_via eq "Apache::DBI::connect")
500+
? 'Apache::DBI::connect' : 'connect_cached';
494501
return $class->connect($dsn, $user, $pass, $attr);
495502
}
496503

@@ -1234,16 +1241,8 @@ sub _new_sth { # called by DBD::<drivername>::db::prepare)
12341241

12351242
sub default_user {
12361243
my ($drh, $user, $pass, $attr) = @_;
1237-
unless (defined $user) {
1238-
$user = $ENV{DBI_USER};
1239-
Carp::carp("DBI connect: user not defined and DBI_USER env var not set")
1240-
if 0 && !defined $user && $drh->{Warn}; # XXX enable later
1241-
}
1242-
unless (defined $pass) {
1243-
$pass = $ENV{DBI_PASS};
1244-
Carp::carp("DBI connect: password not defined and DBI_PASS env var not set")
1245-
if 0 && !defined $pass && $drh->{Warn}; # XXX enable later
1246-
}
1244+
$user = $ENV{DBI_USER} unless defined $user;
1245+
$pass = $ENV{DBI_PASS} unless defined $pass;
12471246
return ($user, $pass);
12481247
}
12491248

@@ -1452,7 +1451,7 @@ sub _new_sth { # called by DBD::<drivername>::db::prepare)
14521451
}
14531452

14541453
sub prepare_cached {
1455-
my ($dbh, $statement, $attr, $allow_active) = @_;
1454+
my ($dbh, $statement, $attr, $if_active) = @_;
14561455
# Needs support at dbh level to clear cache before complaining about
14571456
# active children. The XS template code does this. Drivers not using
14581457
# the template must handle clearing the cache themselves.
@@ -1462,12 +1461,11 @@ sub _new_sth { # called by DBD::<drivername>::db::prepare)
14621461
my $key = ($attr) ? join("~~", $statement, @attr_keys, @{$attr}{@attr_keys}) : $statement;
14631462
my $sth = $cache->{$key};
14641463
if ($sth) {
1465-
if ($sth->FETCH('Active') && ($allow_active||0) != 2) {
1466-
Carp::carp("prepare_cached($statement) statement handle $sth was still active")
1467-
if !$allow_active;
1468-
$sth->finish;
1469-
}
1470-
return $sth;
1464+
return $sth unless $sth->FETCH('Active');
1465+
Carp::carp("prepare_cached($statement) statement handle $sth still active")
1466+
unless ($if_active ||= 0);
1467+
$sth->finish if $if_active <= 1;
1468+
return $sth if $if_active <= 2;
14711469
}
14721470
$sth = $dbh->prepare($statement, $attr);
14731471
$cache->{$key} = $sth if $sth;
@@ -2286,8 +2284,7 @@ variables if no C<$data_source> is specified.)
22862284
The C<AutoCommit> and C<PrintError> attributes for each connection default to
22872285
"on". (See L</AutoCommit> and L</PrintError> for more information.)
22882286
However, it is strongly recommended that you explicitly define C<AutoCommit>
2289-
rather than rely on the default. Future versions of
2290-
the DBI may issue a warning if C<AutoCommit> is not explicitly defined.
2287+
rather than rely on the default.
22912288
22922289
The C<\%attr> parameter can be used to alter the default settings of
22932290
C<PrintError>, C<RaiseError>, C<AutoCommit>, and other attributes. For example:
@@ -3434,14 +3431,36 @@ be used with the DBI.
34343431
34353432
$sth = $dbh->prepare_cached($statement)
34363433
$sth = $dbh->prepare_cached($statement, \%attr)
3437-
$sth = $dbh->prepare_cached($statement, \%attr, $allow_active)
3434+
$sth = $dbh->prepare_cached($statement, \%attr, $if_active)
34383435
34393436
Like L</prepare> except that the statement handle returned will be
34403437
stored in a hash associated with the C<$dbh>. If another call is made to
34413438
C<prepare_cached> with the same C<$statement> and C<%attr> values, then the
34423439
corresponding cached C<$sth> will be returned without contacting the
34433440
database server.
34443441
3442+
The C<$if_active> parameter lets you adjust the behaviour if an
3443+
already cached statement handle is still Active. There are several
3444+
alternatives:
3445+
3446+
=over 4
3447+
3448+
B<0>: A warning will be generated, and finish() will be called on
3449+
the statement handle before it is returned. This is the default
3450+
behaviour if $if_active is not passed.
3451+
3452+
B<1>: finish() will be called on the statement handle, but the
3453+
warning is suppressed.
3454+
3455+
B<2>: Disables any checking.
3456+
3457+
B<3>: The existing active statement handle will be removed from the
3458+
cache and a new statement handle prepared and cached in its place.
3459+
This is the safest option because it doesn't affect the state of the
3460+
old handle, it just removes it from the cache. [Added in DBI 1.40]
3461+
3462+
=back
3463+
34453464
Here are some examples of C<prepare_cached>:
34463465
34473466
sub insert_hash {
@@ -3469,10 +3488,12 @@ but it can also cause problems and should be used with care. Here
34693488
is a contrived case where caching would cause a significant problem:
34703489
34713490
my $sth = $dbh->prepare_cached('SELECT * FROM foo WHERE bar=?');
3472-
$sth->execute($bar);
3491+
$sth->execute(...);
34733492
while (my $data = $sth->fetchrow_hashref) {
3493+
3494+
# later, in some other code called within the loop...
34743495
my $sth2 = $dbh->prepare_cached('SELECT * FROM foo WHERE bar=?');
3475-
$sth2->execute($data->{bar});
3496+
$sth2->execute(...);
34763497
while (my $data2 = $sth2->fetchrow_arrayref) {
34773498
do_stuff(...);
34783499
}
@@ -3485,30 +3506,14 @@ Typically the the inner fetch loop will work normally, fetching all
34853506
the records and terminating when there are no more, but now $sth
34863507
is the same as $sth2 the outer fetch loop will also terminate.
34873508
3488-
The C<$allow_active> parameter lets you adjust DBI's behaviour when
3489-
prepare_cached is returning a statement handle that is still active.
3490-
There are three settings:
3491-
3492-
=over 4
3493-
3494-
B<0>: A warning will be generated, and C<finish> will be called on
3495-
the statement handle before it is returned. This is the default
3496-
behaviour if C<$allow_active> is not passed.
3497-
3498-
B<1>: C<finish> will be called on the statement handle, but the
3499-
warning is suppressed.
3500-
3501-
B<2>: DBI will not touch the statement handle before returning it.
3502-
You will need to check C<$sth-E<gt>{Active}> on the returned
3503-
statement handle and deal with it in your own code.
3504-
3505-
=back
3509+
You'll know if you run into this problem because prepare_cached()
3510+
will generate a warning by default (when $if_active is false).
35063511
3507-
Because the cache used by prepare_cached() is keyed by all the
3508-
parameters, including any attributes passed, you can also avoid
3509-
this issue by doing something like:
3512+
The cache used by prepare_cached() is keyed by both the statement
3513+
and any attributes so you can also avoid this issue by doing something
3514+
like:
35103515
3511-
my $sth = $dbh->prepare_cached("...", { dbi_dummy => __FILE__.__LINE__ });
3516+
$sth = $dbh->prepare_cached("...", { dbi_dummy => __FILE__.__LINE__ });
35123517
35133518
which will ensure that prepare_cached only returns statements cached
35143519
by that line of code in that source file.
@@ -4008,7 +4013,8 @@ See L</table_info> for a description of the parameters.
40084013
If C<$dbh-E<gt>get_info(29)> returns true (29 is SQL_IDENTIFIER_QUOTE_CHAR)
40094014
then the table names are constructed and quoted by L</quote_identifier>
40104015
to ensure they are usable even if they contain whitespace or reserved
4011-
words etc.
4016+
words etc. This means that the table names returned will include
4017+
quote characters.
40124018
40134019
=item C<type_info_all>
40144020
@@ -4998,6 +5004,7 @@ value to be used for the key for the returned hash. For example:
49985004
49995005
$dbh->{FetchHashKeyName} = 'NAME_lc';
50005006
$sth = $dbh->prepare("SELECT FOO, BAR, ID, NAME, BAZ FROM TABLE");
5007+
$sth->execute;
50015008
$hash_ref = $sth->fetchall_hashref('id');
50025009
print "Name for id 42 is $hash_ref->{42}->{name}\n";
50035010
@@ -5611,6 +5618,8 @@ can cause problems. You have been warned.
56115618
Using DBI with perl threads is not yet recommended for production
56125619
environments.
56135620
5621+
Note: There is a bug in perl 5.8.2 when configured with threads
5622+
and debugging enabled (bug #24463) which causes a DBI test to fail.
56145623
56155624
=head2 Signal Handling and Canceling Operations
56165625
@@ -5962,18 +5971,19 @@ Some of these are rather dated now but may still be useful.
59625971
http://www.altavista.com/query?q=sql+tutorial
59635972
59645973
5965-
=head2 Books and Journals
5974+
=head2 Books and Articles
59665975
5967-
Programming the Perl DBI, by Alligator Descartes and Tim Bunce.
5976+
Programming the Perl DBI, by Alligator Descartes and Tim Bunce.
5977+
L<http://books.perl.org/book/154>
59685978
5969-
Programming Perl 3rd Ed. by Larry Wall, Tom Christiansen & Jon Orwant.
5979+
Programming Perl 3rd Ed. by Larry Wall, Tom Christiansen & Jon Orwant.
5980+
L<http://books.perl.org/book/134>
59705981
5971-
Learning Perl by Randal Schwartz.
5972-
5973-
Dr Dobb's Journal, November 1996.
5974-
5975-
The Perl Journal, April 1997.
5982+
Learning Perl by Randal Schwartz.
5983+
L<http://books.perl.org/book/101>
59765984
5985+
Details of many other books related to perl can be found at L<http://books.perl.org>
5986+
59775987
=head2 Perl Modules
59785988
59795989
Index of DBI related modules available from CPAN:
@@ -6096,14 +6106,60 @@ Leffler, Jeff Urlwin, Michael Peppler, Henrik Tougaard, Edwin Pratomo,
60966106
Davide Migliavacca, Jan Pazdziora, Peter Haworth, Edmund Mergl, Steve
60976107
Williams, Thomas Lowery, and Phlip Plumlee. Without them, the DBI would
60986108
not be the practical reality it is today. I'm also especially grateful
6099-
to Alligator Descartes for starting work on the "Programming the Perl
6100-
DBI" book and letting me jump on board.
6109+
to Alligator Descartes for starting work on the first edition of the
6110+
"Programming the Perl DBI" book and letting me jump on board.
61016111
6102-
Much of the DBI and DBD::Oracle was developed while I was Technical
6112+
The DBI and DBD::Oracle were originally developed while I was Technical
61036113
Director (CTO) of the Paul Ingram Group (www.ig.co.uk). So I'd
61046114
especially like to thank Paul for his generosity and vision in
61056115
supporting this work for many years.
61066116
6117+
=head1 CONTRIBUTING
6118+
6119+
As you can see above, many people have contributed to the DBI and
6120+
drivers in many ways over many years.
6121+
6122+
If you'd like the DBI to do something new or different the best way
6123+
to make that happen is to do it yourself and send me a patch to the
6124+
source code that shows the changes.
6125+
6126+
=head2 How to create a patch
6127+
6128+
Unpack a fresh copy of the distribution:
6129+
6130+
tar xfz DBI-1.40.tar.gz
6131+
6132+
Rename the newly created top level directory:
6133+
6134+
mv DBI-1.40 DBI-1.40.your_foo
6135+
6136+
Edit the contents of DBI-1.40.your_foo/* till it does what you want.
6137+
6138+
Test your changes and then remove all temporary files:
6139+
6140+
make test && make distclean
6141+
6142+
Go back to the directory you originally unpacked the distribution:
6143+
6144+
cd ..
6145+
6146+
Unpack I<another> copy of the original distribution you started with:
6147+
6148+
tar xfz DBI-1.40.tar.gz
6149+
6150+
Then create a patch file by performing a recursive C<diff> on the two
6151+
top level directories:
6152+
6153+
diff -r -u DBI-1.40 DBI-1.40.your_foo > DBI-1.40.your_foo.patch
6154+
6155+
=head2 Speak before you patch
6156+
6157+
For anything non-trivial or possibly controversial it's a good idea
6158+
to discuss (on [email protected]) the changes you propose before
6159+
actually spending time working on them. Otherwise you run the risk
6160+
of them being rejected because they don't fit into some larger plans
6161+
you may not be aware of.
6162+
61076163
=head1 TRANSLATIONS
61086164
61096165
A German translation of this manual (possibly slightly out of date) is

0 commit comments

Comments
 (0)