Author: timbo
Date: Mon Dec 13 02:51:11 2004
New Revision: 623
Modified:
dbi/trunk/Changes
dbi/trunk/DBI.pm
dbi/trunk/META.yml
dbi/trunk/lib/DBD/File.pm
Log:
Changed driver handle caching in DBD::File.
Updated docs for primary_key_info and primary_keys.
Corrected and updated LongReadLen docs thanks to Bart Lateur.
Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes (original)
+++ dbi/trunk/Changes Mon Dec 13 02:51:11 2004
@@ -19,9 +19,12 @@
Changed DBI::PurePerl to set autoflush on trace filehandle.
Changed DBD::Proxy to treat Username as a local attribute
so recent DBI version can be used with old DBI::ProxyServer.
+ Changed driver handle caching in DBD::File.
- Updated docs to recommend common some DSN string attributes.
+ Updated docs to recommend some common DSN string attributes.
Updated docs for NULL Value placeholders thanks to Brian Campbell.
+ Updated docs for primary_key_info and primary_keys.
+ Corrected and updated LongReadLen docs thanks to Bart Lateur.
=head2 Changes in DBI 1.46 (svn rev 584), 16th November 2004
Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm (original)
+++ dbi/trunk/DBI.pm Mon Dec 13 02:51:11 2004
@@ -3484,14 +3484,15 @@
=item C<LongReadLen> (unsigned integer, inherited)
The C<LongReadLen> attribute may be used to control the maximum
-length of 'long' fields ("blob", "memo", etc.) which the driver will
+length of 'long' type fields (LONG, BLOB, CLOB, MEMO, etc.) which the driver
will
read from the database automatically when it fetches each row of data.
The C<LongReadLen> attribute only relates to fetching and reading
long values; it is not involved in inserting or updating them.
-A value of 0 means not to automatically fetch any long data. (C<fetch>
-should return C<undef> for long fields when C<LongReadLen> is 0.)
+A value of 0 means not to automatically fetch any long data.
+Drivers may return undef or an empty string for long fields when
+C<LongReadLen> is 0.
The default is typically 0 (zero) bytes but may vary between drivers.
Applications fetching long fields should set this value to slightly
@@ -3511,17 +3512,20 @@
execute an extra select statement to determine the longest value.
For example:
- $dbh->{LongReadLen} = $dbh->selectrow_array{qq{
- SELECT MAX(long_column_name) FROM table WHERE ...
+ $dbh->{LongReadLen} = $dbh->selectrow_array(qq{
+ SELECT MAX(OCTET_LENGTH(long_column_name))
+ FROM table WHERE ...
});
$sth = $dbh->prepare(qq{
SELECT long_column_name, ... FROM table WHERE ...
});
You may need to take extra care if the table can be modified between
-the first select and the second being executed.
+the first select and the second being executed. You may also need to
+use a different function if OCTET_LENGTH() does not work for long
+types in your database. For example, for Sybase use DATALENGTH().
-See L</LongTruncOk> for more information on truncation behaviour.
+See also L</LongTruncOk> for information on truncation of long types.
=item C<LongTruncOk> (boolean, inherited)
@@ -4374,6 +4378,7 @@
The statement handle will return one row per column, ordered by
TABLE_CAT, TABLE_SCHEM, TABLE_NAME, and KEY_SEQ.
+If there is no primary key then the statement handle will fetch no rows.
Note: The support for the selection criteria, such as $catalog, is
driver specific. If the driver doesn't support catalogs and/or
@@ -4410,6 +4415,7 @@
Simple interface to the primary_key_info() method. Returns a list of
the column names that comprise the primary key of the specified table.
The list is in primary key column sequence order.
+If there is no primary key then an empty list is returned.
=item C<foreign_key_info>
Modified: dbi/trunk/META.yml
==============================================================================
--- dbi/trunk/META.yml (original)
+++ dbi/trunk/META.yml Mon Dec 13 02:51:11 2004
@@ -1,7 +1,7 @@
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: DBI
-version: 1.46
+version: 1.47
version_from: DBI.pm
installdirs: site
requires:
Modified: dbi/trunk/lib/DBD/File.pm
==============================================================================
--- dbi/trunk/lib/DBD/File.pm (original)
+++ dbi/trunk/lib/DBD/File.pm Mon Dec 13 02:51:11 2004
@@ -31,13 +31,21 @@
$VERSION = '0.32';
-$drh = undef; # holds driver handle once initialised
+$drh = undef; # holds driver handle(s) once initialised
sub driver ($;$) {
my($class, $attr) = @_;
- return $drh if $drh;
- DBI->setup_driver('DBD::File');
+ # Drivers typically use a singleton object for the $drh
+ # We use a hash here to have one singleton per subclass.
+ # (Otherwise DBD::CSV and DBD::DBM, for example, would
+ # share the same driver object which would cause problems.)
+ # An alternative would be not not cache the $drh here at all
+ # and require that subclasses do that. Subclasses should do
+ # their own caching, so caching here just provides extra safety.
+ return $drh->{$class} if $drh->{$class};
+
+ DBI->setup_driver('DBD::File'); # only needed once but harmless to repeat
$attr ||= {};
no strict qw(refs);
if (!$attr->{Attribution}) {
@@ -48,9 +56,10 @@
}
$attr->{Version} ||= ${$class . '::VERSION'};
($attr->{Name} = $class) =~ s/^DBD\:\:// unless $attr->{Name};
- $drh = DBI::_new_drh($class . "::dr", $attr);
- $drh->STORE(ShowErrorStatement => 1);
- return $drh;
+
+ $drh->{$class} = DBI::_new_drh($class . "::dr", $attr);
+ $drh->{$class}->STORE(ShowErrorStatement => 1);
+ return $drh->{$class};
}
sub CLONE {
@@ -211,7 +220,6 @@
}
sub disconnect ($) {
shift->STORE('Active',0);
- undef $DBD::File::drh; # XXX why?
1;
}
sub FETCH ($$) {