Author: timbo
Date: Thu Dec 16 04:18:51 2004
New Revision: 630
Modified:
dbi/trunk/Changes
dbi/trunk/lib/DBD/ExampleP.pm
dbi/trunk/lib/DBD/NullP.pm
dbi/trunk/lib/DBD/Proxy.pm
dbi/trunk/lib/DBD/Sponge.pm
dbi/trunk/lib/DBI/DBD.pm
Log:
Updated handle/attribute docs for DBD authors thanks to Steffen Goeldner.
Removed unused $err from drivers thanks to Steffen Goeldner.
Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes (original)
+++ dbi/trunk/Changes Thu Dec 16 04:18:51 2004
@@ -25,6 +25,7 @@
Updated docs for NULL Value placeholders thanks to Brian Campbell.
Updated docs for primary_key_info and primary_keys.
Updated err/errstr/state docs for DBD authors thanks to Steffen Goeldner.
+ Updated handle/attribute docs for DBD authors thanks to Steffen Goeldner.
Corrected and updated LongReadLen docs thanks to Bart Lateur.
=head2 Changes in DBI 1.46 (svn rev 584), 16th November 2004
Modified: dbi/trunk/lib/DBD/ExampleP.pm
==============================================================================
--- dbi/trunk/lib/DBD/ExampleP.pm (original)
+++ dbi/trunk/lib/DBD/ExampleP.pm Thu Dec 16 04:18:51 2004
@@ -32,7 +32,6 @@
die unless @statprec == @stattypes;
$drh = undef; # holds driver handle once initialised
- $err = 0; # The $DBI::err value
#$gensym = "SYM000"; # used by st::execute() for filehandles
sub driver{
Modified: dbi/trunk/lib/DBD/NullP.pm
==============================================================================
--- dbi/trunk/lib/DBD/NullP.pm (original)
+++ dbi/trunk/lib/DBD/NullP.pm Thu Dec 16 04:18:51 2004
@@ -14,7 +14,6 @@
# License or the Artistic License, as specified in the Perl README file.
$drh = undef; # holds driver handle once initialised
- $err = 0; # The $DBI::err value
sub driver{
return $drh if $drh;
Modified: dbi/trunk/lib/DBD/Proxy.pm
==============================================================================
--- dbi/trunk/lib/DBD/Proxy.pm (original)
+++ dbi/trunk/lib/DBD/Proxy.pm Thu Dec 16 04:18:51 2004
@@ -31,7 +31,7 @@
package DBD::Proxy;
-use vars qw($VERSION $err $errstr $drh %ATTR);
+use vars qw($VERSION $drh %ATTR);
$VERSION = "0.2004";
Modified: dbi/trunk/lib/DBD/Sponge.pm
==============================================================================
--- dbi/trunk/lib/DBD/Sponge.pm (original)
+++ dbi/trunk/lib/DBD/Sponge.pm Thu Dec 16 04:18:51 2004
@@ -15,7 +15,6 @@
# License or the Artistic License, as specified in the Perl README file.
$drh = undef; # holds driver handle once initialised
- $err = 0; # The $DBI::err value
my $methods_already_installed;
sub driver{
Modified: dbi/trunk/lib/DBI/DBD.pm
==============================================================================
--- dbi/trunk/lib/DBI/DBD.pm (original)
+++ dbi/trunk/lib/DBI/DBD.pm Thu Dec 16 04:18:51 2004
@@ -696,21 +696,18 @@
# environment variables to be set; this could be where you
# validate that they are set, or default them if they are not set.
+ # Assume you can attach to your database via drv_connect:
+ my $connection = drv_connect($dbname, $user, $auth);
+ return $drh->set_err(1,'Connection refused') unless $connection;
+
# create a 'blank' dbh (call superclass constructor)
- my $dbh = DBI::_new_dbh($drh, {
- 'Name' => $dbname,
- })
- or return undef;
-
- # Process attributes from the DSN; we assume ODBC syntax
- # here, that is, the DSN looks like var1=val1;...;varN=valN
- foreach my $var (split(/;/, $dbname)) {
- if ($var =~ m/(.*?)=(,*)/) {
- # Not !!! $dbh->{$var} = $val;
- $dbh->STORE($var, $val);
- }
- }
- $dbh;
+ my ($outer, $dbh) = DBI::_new_dbh($drh, { Name => $dbname });
+
+ $dbh->STORE('Active', 1 );
+
+ $dbh->{drv_connection} = $connection;
+
+ return $outer;
}
The Name attribute is a standard DBI attribute.
@@ -721,11 +718,13 @@
The constructor _new_dbh is called, returning a database handle.
The constructor's prototype is:
- $dbh = DBI::_new_dbh($drh, $public_attr, $private_attr);
+ ($outer, $inner) = DBI::_new_dbh($drh, $public_attr, $private_attr);
with similar arguments to those in the I<driver handle constructor>,
except that the C<$class> is replaced by C<$drh>.
+In scalar context, only the outer handle is returned.
+
Note the use of the I<STORE> method for setting the dbh attributes.
That's because within the driver code, the handle object you have is
the 'inner' handle of a tied hash, not the outer handle that the
@@ -807,19 +806,18 @@
my ($dbh, $statement, @attribs) = @_;
# create a 'blank' sth
- my $sth = DBI::_new_sth($dbh, {
- 'Statement' => $statement,
- });
+ my ($outer, $sth) = DBI::_new_sth($dbh, { Statement => $statement });
- # Setup module specific data
- $sth->STORE('drv_params', []);
$sth->STORE('NUM_OF_PARAMS', ($statement =~ tr/?//));
- $sth;
+ $sth->{drv_params} = [];
+
+ return $outer;
}
This is still the same: check the arguments and call the super class
constructor I<DBI::_new_sth>.
+Again, in scalar context, only the outer handle is returned.
The C<Statement> attribute should be cached as shown.
Note the prefix I<drv_> in the attribute names: it is required that
your private attributes are lowercased and use such a prefix.