Author: timbo
Date: Sun Feb 22 05:53:26 2004
New Revision: 121
Modified:
dbi/trunk/Changes
dbi/trunk/DBI.pm
dbi/trunk/DBI.xs
dbi/trunk/DBIXS.h
dbi/trunk/lib/DBI/PurePerl.pm
dbi/trunk/t/06attrs.t
Log:
Added $h->{ErrCount} attribute
Modified: dbi/trunk/Changes
==============================================================================
--- dbi/trunk/Changes (original)
+++ dbi/trunk/Changes Sun Feb 22 05:53:26 2004
@@ -6,6 +6,10 @@
=head1 CHANGES in DBI 1.41 (svn rev XX), 17th February 2004
+Split keep_err ima into err_keep_call err_ignore_rtn, err_chknew_rtn
+FETCH would be err_keep_in and err_chknew_rtn
+Add %attr to more methods, esp metadata
+
Fixed execute_for_array() so tuple_status parameter is optional
as per docs, thanks to Ed Avis.
Fixed execute_for_array() docs to say that it returns undef if
@@ -37,8 +41,9 @@
(e.g., to promote an error to a warning, or the reverse).
Added $h->{PrintWarn} attribute to enable printing of warnings
recorded by the driver. Defaults to same value as $^W (perl -w).
+ Added $h->{ErrCount} attribute, incremented whenever an error is
+ recorded by the driver via set_err().
Added $h->{Executed} attribute, set if do()/execute() called.
- Added details of DBI::Const::GetInfoType module to get_info() docs.
Added ref count of inner handle to "DESTROY ignored for outer" msg.
Added Win32 build config checks to DBI::DBD thanks to Andy Hassall.
Added bind_col to Driver.xst so drivers can define their own.
@@ -49,6 +54,7 @@
Corrected dbiproxy usage doc thanks to Christian Hammers.
Corrected type_info_all index hash docs thanks to Steffen Goeldner.
Corrected type_info COLUMN_SIZE to chars not bytes thanks to Dean Arnold.
+ Corrected get_info() docs to include details of DBI::Const::GetInfoType.
Clarified that $sth->{PRECISION} is OCTET_LENGTH for char types.
=head2 Changes in DBI 1.40, 7th January 2004
Modified: dbi/trunk/DBI.pm
==============================================================================
--- dbi/trunk/DBI.pm (original)
+++ dbi/trunk/DBI.pm Sun Feb 22 05:53:26 2004
@@ -2724,6 +2724,7 @@
The handle C<state> value is set to $state if $state is true and
the handle C<err> value was set (by the rules above).
+Support for warning and information states was added in DBI 1.41.
=item C<trace>
@@ -2859,6 +2860,8 @@
and so acts as a permenant record of whether the statement handle
was ever used.
+The C<Executed> attribute was added in DBI 1.41.
+
=item C<Kids> (integer, read-only)
For a driver handle, C<Kids> is the number of currently existing database
@@ -3082,12 +3085,25 @@
common and any such cases should be clearly marked in the driver
documentation and discussed on the dbi-dev mailing list.
+The C<HandleSetErr> attribute was added in DBI 1.41.
+
+=item C<ErrCount> (unsigned integer)
+
+The C<ErrCount> attribute is incremented whenever the set_err()
+method records an error. It isn't incremented by warnings or
+information states. It is not reset by the DBI at any time.
+
+The C<ErrCount> attribute was added in DBI 1.41. Older drivers may
+not have been updated to use set_err() to record errors and so this
+attribute may not be incremented when using them.
+
=item C<ShowErrorStatement> (boolean, inherited)
-The C<ShowErrorStatement> attribute can be used to cause the relevant Statement text
to be
-appended to the error messages generated by the C<RaiseError> and
-C<PrintError> attributes. Only applies to errors on statement handles
+The C<ShowErrorStatement> attribute can be used to cause the relevant
+Statement text to be appended to the error messages generated by
+the C<RaiseError>, C<PrintError>, and C<PrintWarn> attributes.
+Only applies to errors on statement handles
plus the prepare(), do(), and the various C<select*()> database handle methods.
(The exact format of the appended text is subject to change.)
Modified: dbi/trunk/DBI.xs
==============================================================================
--- dbi/trunk/DBI.xs (original)
+++ dbi/trunk/DBI.xs Sun Feb 22 05:53:26 2004
@@ -492,6 +492,8 @@
) {
sv_setsv(h_err, err);
err_changed = 1;
+ if (SvTRUE(h_err)) /* new error */
+ ++DBIc_ErrCount(imp_xxh);
}
if (err_changed) {
@@ -1359,6 +1361,9 @@
else if (strEQ(key, "ChopBlanks")) {
DBIc_set(imp_xxh, DBIcf_ChopBlanks, on);
}
+ else if (strEQ(key, "ErrCount")) {
+ DBIc_ErrCount(imp_xxh) = SvUV(valuesv);
+ }
else if (strEQ(key, "LongReadLen")) {
if (SvNV(valuesv) < 0 || SvNV(valuesv) > MAX_LongReadLen)
croak("Can't set LongReadLen < 0 or > %ld",MAX_LongReadLen);
@@ -1693,6 +1698,9 @@
if (strEQ(key, "Executed")) {
valuesv = boolSV(DBIc_is(imp_xxh, DBIcf_Executed));
}
+ else if (strEQ(key, "ErrCount")) {
+ valuesv = newSVuv(DBIc_ErrCount(imp_xxh));
+ }
break;
case 'I':
Modified: dbi/trunk/DBIXS.h
==============================================================================
--- dbi/trunk/DBIXS.h (original)
+++ dbi/trunk/DBIXS.h Sun Feb 22 05:53:26 2004
@@ -111,7 +111,7 @@
SV *State; /* Standard SQLSTATE, 5 char string */
SV *Err; /* Native engine error code */
SV *Errstr; /* Native engine error message */
- SV *spare;
+ UV ErrCount;
U32 LongReadLen; /* auto read length for long/blob types */
SV *FetchHashKeyName; /* for fetchrow_hashref */
/* (NEW FIELDS?... DON'T FORGET TO UPDATE dbih_clearcom()!) */
@@ -211,6 +211,7 @@
#define DBIc_STATE(imp) SvRV(_imp2com(imp, attr.State))
#define DBIc_ERR(imp) SvRV(_imp2com(imp, attr.Err))
#define DBIc_ERRSTR(imp) SvRV(_imp2com(imp, attr.Errstr))
+#define DBIc_ErrCount(imp) _imp2com(imp, attr.ErrCount)
#define DBIc_LongReadLen(imp) _imp2com(imp, attr.LongReadLen)
#define DBIc_LongReadLen_init 80 /* may change */
#define DBIc_FetchHashKeyName(imp) (_imp2com(imp, attr.FetchHashKeyName))
@@ -253,7 +254,6 @@
#define DBIcf_INHERITMASK /* what NOT to pass on to children */ \
(U32)( DBIcf_COMSET | DBIcf_IMPSET | DBIcf_ACTIVE | DBIcf_IADESTROY \
- /* These are for dbh only: */ \
| DBIcf_AutoCommit | DBIcf_BegunWork | DBIcf_Executed )
/* general purpose bit setting and testing macros */
Modified: dbi/trunk/lib/DBI/PurePerl.pm
==============================================================================
--- dbi/trunk/lib/DBI/PurePerl.pm (original)
+++ dbi/trunk/lib/DBI/PurePerl.pm Sun Feb 22 05:53:26 2004
@@ -132,6 +132,7 @@
Database
DebugDispatch
Driver
+ ErrCount
FetchHashKeyName
HandleError
HandleSetErr
@@ -419,7 +420,8 @@
$h_inner->{LongReadLen} ||= 80;
}
$h_inner->{"_call_depth"} = 0;
- $h_inner->{"Active"} = 1;
+ $h_inner->{ErrCount} = 0;
+ $h_inner->{Active} = 1;
}
sub constant {
warn "constant @_"; return;
@@ -668,6 +670,7 @@
or defined $errnum && length($errnum) > length($h->{err})
) {
$h->{err} = $DBI::err = $errnum;
+ ++$h->{ErrCount} if $errnum;
++$err_changed;
}
Modified: dbi/trunk/t/06attrs.t
==============================================================================
--- dbi/trunk/t/06attrs.t (original)
+++ dbi/trunk/t/06attrs.t Sun Feb 22 05:53:26 2004
@@ -4,7 +4,7 @@
use Test::More;
use DBI;
-BEGIN { plan tests => 140 }
+BEGIN { plan tests => 147 }
$|=1;
@@ -38,6 +38,7 @@
ok(!$dbh->{Executed} );
# other attr
+is( $dbh->{ErrCount}, 0 );
is( $dbh->{Kids}, 0 ) unless $DBI::PurePerl && ok(1);
is( $dbh->{ActiveKids}, 0 ) unless $DBI::PurePerl && ok(1);
ok( ! defined $dbh->{CachedKids} );
@@ -62,6 +63,7 @@
ok( $dbh->{Executed} ); # even though it failed
$dbh->{Executed} = 0; # reset(able)
ok(!$dbh->{Executed} ); # reset
+is( $dbh->{ErrCount}, 1 );
# ------ Test the driver handle attributes.
@@ -69,6 +71,8 @@
ok( UNIVERSAL::isa($drh, 'DBI::dr') );
ok( $dbh->err );
+is( $drh->{ErrCount}, 0 );
+
ok( $drh->{Warn} );
ok( $drh->{Active} );
ok( $drh->{AutoCommit} );
@@ -104,6 +108,7 @@
(ok my $sth = $dbh->prepare("select ctime, name from foo") );
ok( !$sth->{Executed} );
ok( !$dbh->{Executed} );
+is( $sth->{ErrCount}, 0 );
# Trigger an exception.
eval { $sth->execute };
@@ -117,6 +122,12 @@
ok( $sth->{Executed} ); # even though it failed
ok( $dbh->{Executed} ); # due to $sth->prepare, even though it failed
+is( $sth->{ErrCount}, 1 );
+$sth->{ErrCount} = 42;
+is( $sth->{ErrCount}, 42 );
+$sth->{ErrCount} = 0;
+is( $sth->{ErrCount}, 0 );
+
# booleans
ok( $sth->{Warn} );
ok(!$sth->{Active} );