DBI

 view release on metacpan or  search on metacpan

ChangeLog  view on Meta::CPAN

    Add perl 5.22 and 5.22-extras to travis-ci config

1.635 - 2016-04-24, Tim Bunce

    Fixed RaiseError/PrintError for UTF-8 errors/warnings. RT#102404
    Fixed cases where ShowErrorStatement might show incorrect Statement RT#97434
    Fixed DBD::Gofer for UTF-8-enabled STDIN/STDOUT
        thanks to mauke PR#32
    Fixed fetchall_arrayref({}) behavior with no columns
        thanks to Dan McGee PR#31
    Fixed tied CachedKids ref leak in attribute cache by weakening
        thanks to Michael Conrad RT#113852
    Fixed "panic: attempt to copy freed scalar" upon commit() or rollback()
        thanks to fbriere for detailed bug report RT#102791
    Ceased to ignore DESTROY of outer handle in DBI::PurePerl
    Treat undef in DBI::Profile Path as string "undef"
        thanks to fREW Schmidt RT#113298
    Fix SQL::Nano parser to ignore trailing semicolon
        thanks to H.Merijn Brand.

    Added @ary = $dbh->selectall_array(...) method

ChangeLog  view on Meta::CPAN

    Works for all transports. Overridable per handle.

  Added DBI::Util::CacheMemory for use with DBD::Gofer caching.
    It's a very fast and small strict subset of Cache::Memory.

1.59 - 2007-08-23, Tim Bunce (svn r9874)

  Fixed DBI::ProfileData to unescape headers lines read from data file.
  Fixed DBI::ProfileData to not clobber $_, thanks to Alexey Tourbin.
  Fixed DBI::SQL::Nano to not clobber $_, thanks to Alexey Tourbin.
  Fixed DBI::PurePerl to return undef for ChildHandles if weaken not available.
  Fixed DBD::Proxy disconnect error thanks to Philip Dye.
  Fixed DBD::Gofer::Transport::Base bug (typo) in timeout code.
  Fixed DBD::Proxy rows method thanks to Philip Dye.
  Fixed dbiprof compile errors, thanks to Alexey Tourbin.
  Fixed t/03handle.t to skip some tests if ChildHandles not available.

  Added check_response_sub to DBI::Gofer::Execute

1.58 - 2007-06-25, Tim Bunce (svn r9678)

ChangeLog  view on Meta::CPAN

    and DBD::Gofer+DBI::PurePerl, in addition to DBI::PurePerl.
  Added ability for trace() to support filehandle argument,
    including tracing into a string, thanks to Dean Arnold.
  Added ability for drivers to implement func() method
    so proxy drivers can proxy the func method itself.
  Added SQL_BIGINT type code (resolved to the ODBC/JDBC value (-5))
  Added $h->private_attribute_info method.

1.53 - 2006-10-31, Tim Bunce (svn r7995)

  Fixed checks for weaken to work with early 5.8.x versions
  Fixed DBD::Proxy handling of some methods, including commit and rollback.
  Fixed t/40profile.t to be more insensitive to long double precision.
  Fixed t/40profile.t to be insensitive to small negative shifts in time
    thanks to Jamie McCarthy.
  Fixed t/40profile.t to skip tests for perl < 5.8.0.
  Fixed to work with current 'bleadperl' (~5.9.5) thanks to Steve Peters.
    Users of Perl >= 5.9.5 will require DBI >= 1.53.
  Fixed to be more robust against drivers not handling multiple result
    sets properly, thanks to Gisle Aas.

ChangeLog  view on Meta::CPAN

    can refer to attributes, assorted magical values, and even code refs!
    Parsing of non-numeric DBI_PROFILE env var values has changed.
    Changed DBI::Profile docs extensively - many new features.
    See DBI::Profile docs for more information.

1.51 - 2006-06-06, Tim Bunce (svn r6475)

  Fixed $dbh->clone method 'signature' thanks to Jeffrey Klein.
  Fixed default ping() method to return false if !$dbh->{Active}.
  Fixed t/40profile.t to be insensitive to long double precision.
  Fixed for perl 5.8.0's more limited weaken() function.
  Fixed DBD::Proxy to not alter $@ in disconnect or AUTOLOADd methods.
  Fixed bind_columns() to use return set_err(...) instead of die()
    to report incorrect number of parameters, thanks to Ben Thul.
  Fixed bind_col() to ignore undef as bind location, thanks to David Wheeler.
  Fixed for perl 5.9.x for non-threaded builds thanks to Nicholas Clark.
    Users of Perl >= 5.9.x will require DBI >= 1.51.
  Fixed fetching of rows as hash refs to preserve utf8 on field names
    from $sth->{NAME} thanks to Alexey Gaidukov.
  Fixed build on Win32 (dbd_postamble) thanks to David Golden.

DBI.xs  view on Meta::CPAN

            && SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV
            && (tmp_svp = hv_fetch((HV*)SvRV(*tmp_svp), "ChildCallbacks", 14, 0))
            && SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV
            ) {
                /* XXX mirrors behaviour of dbih_set_attr_k() of Callbacks */
                (void)hv_store((HV*)SvRV(h), "Callbacks", 9, newRV_inc(SvRV(*tmp_svp)), 0);
                DBIc_set(imp, DBIcf_Callbacks, 1);
            }

            DBIc_LongReadLen(imp) = DBIc_LongReadLen(parent_imp);
#ifdef sv_rvweaken
            if (1) {
                AV *av;
                /* add weakref to new (outer) handle into parents ChildHandles array */
                tmp_svp = hv_fetch((HV*)SvRV(parent), "ChildHandles", 12, 1);
                if (!SvROK(*tmp_svp)) {
                    SV *ChildHandles_rvav = newRV_noinc((SV*)newAV());
                    sv_setsv(*tmp_svp, ChildHandles_rvav);
                    sv_free(ChildHandles_rvav);
                }
                av = (AV*)SvRV(*tmp_svp);
                av_push(av, (SV*)sv_rvweaken(newRV_inc((SV*)SvRV(orv))));
                if (av_len(av) % 120 == 0) {
                    /* time to do some housekeeping to remove dead handles */
                    I32 i = av_len(av); /* 0 = 1 element */
                    while (i-- >= 0) {
                        SV *sv = av_shift(av);
                        if (SvOK(sv))
                            av_push(av, sv);
                        else
                           sv_free(sv);         /* keep it leak-free by Doru Petrescu pdoru.dbi@from.ro */
                    }

DBI.xs  view on Meta::CPAN

{
    dTHX;
    dTHR;
    D_imp_xxh(h);
    STRLEN keylen;
    const char  *key = SvPV(keysv, keylen);
    const int    htype = DBIc_TYPE(imp_xxh);
    int    on = (SvTRUE(valuesv));
    int    internal = 1; /* DBIh_IN_PERL_DBD(imp_xxh); -- for DBD's in perl */
    int    cacheit = 0;
    int    weakenit = 0; /* eg for CachedKids ref */
    (void)dbikey;

    if (DBIc_TRACE_LEVEL(imp_xxh) >= 3)
        PerlIO_printf(DBIc_LOGPIO(imp_xxh),"    STORE %s %s => %s\n",
                neatsvpv(h,0), neatsvpv(keysv,0), neatsvpv(valuesv,0));

    if (internal && strEQ(key, "Active")) {
        if (on) {
            D_imp_sth(h);
            DBIc_ACTIVE_on(imp_xxh);

DBI.xs  view on Meta::CPAN

        DBIc_set(imp_xxh,DBIcf_TaintIn, on);
    }
    else if (strEQ(key, "TaintOut")) {
        DBIc_set(imp_xxh,DBIcf_TaintOut, on);
    }
    else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "CachedKids")
        /* only allow hash refs */
        && SvROK(valuesv) && SvTYPE(SvRV(valuesv))==SVt_PVHV
    ) {
        cacheit = 1;
        weakenit = 1;
    }
    else if (keylen==9 && strEQ(key, "Callbacks")) {
        if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) )
            croak("Can't set Callbacks to '%s'",neatsvpv(valuesv,0));
        /* see also dbih_setup_handle for ChildCallbacks handling */
        DBIc_set(imp_xxh, DBIcf_Callbacks, on);
        cacheit = 1;
    }
    else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "AutoCommit")) {
        /* driver should have intercepted this and either handled it    */

DBI.xs  view on Meta::CPAN

                PerlIO_printf(DBIc_LOGPIO(imp_xxh),"$h->{%s}=%s ignored for invalid driver-specific attribute\n",
                        neatsvpv(keysv,0), neatsvpv(valuesv,0));
            }
            return FALSE;
        }
        cacheit = 1;
    }
    if (cacheit) {
        SV *sv_for_cache = newSVsv(valuesv);
        (void)hv_store((HV*)SvRV(h), key, keylen, sv_for_cache, 0);
        if (weakenit) {
#ifdef sv_rvweaken
            sv_rvweaken(sv_for_cache);
#endif
        }
    }
    return TRUE;
}


static SV *
dbih_get_attr_k(SV *h, SV *keysv, int dbikey)
{

DBI.xs  view on Meta::CPAN


          case 'C':
            if (strEQ(key, "ChildHandles")) {
                svp = hv_fetch((HV*)SvRV(h), key, keylen, FALSE);
                /* if something has been stored then return it.
                 * otherwise return a dummy empty array if weakrefs are
                 * available, else an undef to indicate that they're not */
                if (svp) {
                    valuesv = newSVsv(*svp);
                } else {
#ifdef sv_rvweaken
                    valuesv = newRV_noinc((SV*)newAV());
#else
                    valuesv = &PL_sv_undef;
#endif
                }
            }
            else if (strEQ(key, "ChopBlanks")) {
                valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ChopBlanks));
            }
            else if (strEQ(key, "CachedKids")) {

dbipport.h  view on Meta::CPAN

sv_resetpvn|5.017005||Viu
SvRMAGICAL|5.003007||Viu
SvRMAGICAL_off|5.003007||Viu
SvRMAGICAL_on|5.003007||Viu
SvROK|5.003007|5.003007|
SvROK_off|5.003007|5.003007|
SvROK_on|5.003007|5.003007|
SvRV|5.003007|5.003007|
SvRV_const|5.010001||Viu
SvRV_set|5.009003|5.003007|p
sv_rvunweaken|5.027004|5.027004|
sv_rvweaken|5.006000|5.006000|
SvRVx|5.003007||Viu
SvRX|5.009005|5.003007|p
SvRXOK|5.009005|5.003007|p
SV_SAVED_COPY|5.009005||Viu
SvSCREAM|5.003007||Viu
SvSCREAM_off|5.003007||Viu
SvSCREAM_on|5.003007||Viu
sv_setbool|5.035004|5.035004|
sv_setbool_mg|5.035004|5.035004|
sv_setgid|5.019001||Viu

lib/DBI/Changes.pm  view on Meta::CPAN

    Add perl 5.22 and 5.22-extras to travis-ci config

=head2 Changes in DBI 1.635 - 24 Apr 2016

    Fixed RaiseError/PrintError for UTF-8 errors/warnings. RT#102404
    Fixed cases where ShowErrorStatement might show incorrect Statement RT#97434
    Fixed DBD::Gofer for UTF-8-enabled STDIN/STDOUT
        thanks to mauke PR#32
    Fixed fetchall_arrayref({}) behavior with no columns
        thanks to Dan McGee PR#31
    Fixed tied CachedKids ref leak in attribute cache by weakening
        thanks to Michael Conrad RT#113852
    Fixed "panic: attempt to copy freed scalar" upon commit() or rollback()
        thanks to fbriere for detailed bug report RT#102791
    Ceased to ignore DESTROY of outer handle in DBI::PurePerl
    Treat undef in DBI::Profile Path as string "undef"
        thanks to fREW Schmidt RT#113298
    Fix SQL::Nano parser to ignore trailing semicolon
        thanks to H.Merijn Brand.

    Added @ary = $dbh->selectall_array(...) method

lib/DBI/Changes.pm  view on Meta::CPAN

    Works for all transports. Overridable per handle.

  Added DBI::Util::CacheMemory for use with DBD::Gofer caching.
    It's a very fast and small strict subset of Cache::Memory.

=head2 Changes in DBI 1.59 (svn rev 9874) - 23 Aug 2007

  Fixed DBI::ProfileData to unescape headers lines read from data file.
  Fixed DBI::ProfileData to not clobber $_, thanks to Alexey Tourbin.
  Fixed DBI::SQL::Nano to not clobber $_, thanks to Alexey Tourbin.
  Fixed DBI::PurePerl to return undef for ChildHandles if weaken not available.
  Fixed DBD::Proxy disconnect error thanks to Philip Dye.
  Fixed DBD::Gofer::Transport::Base bug (typo) in timeout code.
  Fixed DBD::Proxy rows method thanks to Philip Dye.
  Fixed dbiprof compile errors, thanks to Alexey Tourbin.
  Fixed t/03handle.t to skip some tests if ChildHandles not available.

  Added check_response_sub to DBI::Gofer::Execute

=head2 Changes in DBI 1.58 (svn rev 9678) - 25 Jun 2007

lib/DBI/Changes.pm  view on Meta::CPAN

    and DBD::Gofer+DBI::PurePerl, in addition to DBI::PurePerl.
  Added ability for trace() to support filehandle argument,
    including tracing into a string, thanks to Dean Arnold.
  Added ability for drivers to implement func() method
    so proxy drivers can proxy the func method itself.
  Added SQL_BIGINT type code (resolved to the ODBC/JDBC value (-5))
  Added $h->private_attribute_info method.

=head2 Changes in DBI 1.53 (svn rev 7995) - 31 Oct 2006

  Fixed checks for weaken to work with early 5.8.x versions
  Fixed DBD::Proxy handling of some methods, including commit and rollback.
  Fixed t/40profile.t to be more insensitive to long double precision.
  Fixed t/40profile.t to be insensitive to small negative shifts in time
    thanks to Jamie McCarthy.
  Fixed t/40profile.t to skip tests for perl < 5.8.0.
  Fixed to work with current 'bleadperl' (~5.9.5) thanks to Steve Peters.
    Users of Perl >= 5.9.5 will require DBI >= 1.53.
  Fixed to be more robust against drivers not handling multiple result
    sets properly, thanks to Gisle Aas.

lib/DBI/Changes.pm  view on Meta::CPAN

    can refer to attributes, assorted magical values, and even code refs!
    Parsing of non-numeric DBI_PROFILE env var values has changed.
    Changed DBI::Profile docs extensively - many new features.
    See DBI::Profile docs for more information.

=head2 Changes in DBI 1.51 (svn rev 6475) - 06 Jun 2006

  Fixed $dbh->clone method 'signature' thanks to Jeffrey Klein.
  Fixed default ping() method to return false if !$dbh->{Active}.
  Fixed t/40profile.t to be insensitive to long double precision.
  Fixed for perl 5.8.0's more limited weaken() function.
  Fixed DBD::Proxy to not alter $@ in disconnect or AUTOLOADd methods.
  Fixed bind_columns() to use return set_err(...) instead of die()
    to report incorrect number of parameters, thanks to Ben Thul.
  Fixed bind_col() to ignore undef as bind location, thanks to David Wheeler.
  Fixed for perl 5.9.x for non-threaded builds thanks to Nicholas Clark.
    Users of Perl >= 5.9.x will require DBI >= 1.51.
  Fixed fetching of rows as hash refs to preserve utf8 on field names
    from $sth->{NAME} thanks to Alexey Gaidukov.
  Fixed build on Win32 (dbd_postamble) thanks to David Golden.

lib/DBI/PurePerl.pm  view on Meta::CPAN


$DBI::PurePerl = $ENV{DBI_PUREPERL} || 1;
$DBI::PurePerl::VERSION = "2.014286";

$DBI::neat_maxlen ||= 400;

$DBI::tfh = Symbol::gensym();
open $DBI::tfh, ">&STDERR" or warn "Can't dup STDERR: $!";
select( (select($DBI::tfh), $| = 1)[0] );  # autoflush

# check for weaken support, used by ChildHandles
my $HAS_WEAKEN = eval {
    require Scalar::Util;
    # this will croak() if this Scalar::Util doesn't have a working weaken().
    Scalar::Util::weaken( my $test = [] );
    1;
};

%DBI::last_method_except = map { $_=>1 } qw(DESTROY _set_fbav set_err);

use constant SQL_ALL_TYPES => 0;
use constant SQL_ARRAY => 50;
use constant SQL_ARRAY_LOCATOR => 51;
use constant SQL_BIGINT => (-5);
use constant SQL_BINARY => (-2);

lib/DBI/PurePerl.pm  view on Meta::CPAN

	}
        else {
            warn "panic: ".ref($parent); # should never happen
        }
	$h_inner->{dbi_pp_parent} = $parent;

	# add to the parent's ChildHandles
	if ($HAS_WEAKEN) {
	    my $handles = $parent->{ChildHandles} ||= [];
	    push @$handles, $h;
	    Scalar::Util::weaken($handles->[-1]);
	    # purge destroyed handles occasionally
	    if (@$handles % 120 == 0) {
		@$handles = grep { defined } @$handles;
		Scalar::Util::weaken($_) for @$handles; # re-weaken after grep
	    }
	}
    }
    else {	# setting up a driver handle
        $h_inner->{Warn}		= 1;
        $h_inner->{PrintWarn}		= 1;
        $h_inner->{AutoCommit}		= 1;
        $h_inner->{TraceLevel}		= 0;
        $h_inner->{CompatMode}		= (1==0);
	$h_inner->{FetchHashKeyName}	||= 'NAME';

lib/DBI/PurePerl.pm  view on Meta::CPAN

            my $fbav = DBD::_::st::dbih_setup_fbav($h);
            @$fbav = (undef) x $value if @$fbav != $value;
        }
	return 1;
    }
    elsif (!$is_valid_attribute{$key} && $key =~ /^[A-Z]/ && !exists $h->{$key}) {
       Carp::carp(sprintf "Can't set %s->{%s}: unrecognised attribute or invalid value %s",
	    $h,$key,$value);
    }
    $h->{$key} = $is_flag_attribute{$key} ? !!$value : $value;
    Scalar::Util::weaken($h->{$key}) if $key eq 'CachedKids';
    return 1;
}
sub DELETE {
    my ($h, $key) = @_;
    return $h->FETCH($key) unless $key =~ /^private_/;
    return delete $h->{$key};
}
sub err    { return shift->{err}    }
sub errstr { return shift->{errstr} }
sub state  { return shift->{state}  }

t/31methcache.t  view on Meta::CPAN

BEGIN { eval "use threads;" }	# Must be first
my $use_threads_err = $@;
use Config qw(%Config);
# With this test code and threads, 5.8.1 has issues with freeing freed
# scalars, while 5.8.9 doesn't; I don't know about in-between - DAPM
my $has_threads = $Config{useithreads};
die $use_threads_err if $has_threads && $use_threads_err;

use Test::More;

# weaken itself is buggy on 5.8.1 (magic killbackrefs panic
#  triggered by threads, fixed in 5.8.2, but 5.8.2 has other
#  issues that should have been fixed in 5.8.3, but 5.8.4 ..
#  5.8.6 still fail where 5.8.7 PASSes
if ($has_threads && $] < 5.008007) {
    plan skip_all => "Test will fail in threaded perl <= 5.8.6";
}
if ($] >= 5.010000 && $] < 5.012000) {
    plan skip_all => "Test will fail in perl-5.10.x";
}

t/31methcache.t  view on Meta::CPAN

SKIP: {
    skip "no threads / perl < 5.8.9", 12 unless $has_threads;
    # only enable this when handles are allowed to be shared across threads
    #{
    #    my @h = new_handle();
    #    threads->new(sub { run_tests("threads", @h) })->join; 
    #}
    threads->new(sub { run_tests("threads-h", new_handle()) })->join; 
};

# using weaken attaches magic to the CV; see whether this interferes
# with the cache magic

use Scalar::Util qw(weaken);
my $fetch_ref = \&DBI::st::fetch;
weaken $fetch_ref;
run_tests("magic", new_handle());

SKIP: {
    skip "no threads / perl < 5.8.9", 12 unless $has_threads;

    # only enable this when handles are allowed to be shared across threads
    #{
    #    my @h = new_handle();
    #    threads->new(sub { run_tests("threads", @h) })->join; 
    #}

t/72childhandles.t  view on Meta::CPAN

#
# test script for the ChildHandles attribute
#

use DBI;

use Test::More;

my $HAS_WEAKEN = eval {
    require Scalar::Util;
    # this will croak() if this Scalar::Util doesn't have a working weaken().
    Scalar::Util::weaken( my $test = [] ); # same test as in DBI.pm
    1;
};
if (!$HAS_WEAKEN) {
    chomp $@;
    print "1..0 # Skipped: Scalar::Util::weaken not available ($@)\n";
    exit 0;
}

plan tests => 16;

my $using_dbd_gofer = ($ENV{DBI_AUTOPROXY}||'') =~ /^dbi:Gofer.*transport=/i;

my $drh;

{

t/73cachedkids.t  view on Meta::CPAN

use warnings;
use strict;
use Scalar::Util qw( weaken reftype refaddr blessed );

use DBI;
use B ();
use Tie::Hash ();
use Test::More;

my (%weak_dbhs, %weak_caches);

# past this scope everything should be gone
{

### get two identical connections
  my @dbhs = map { DBI->connect('dbi:ExampleP::memory:', undef, undef, { RaiseError => 1 }) } (1,2);

### get weakrefs on both handles
  %weak_dbhs = map { refdesc($_) => $_ } @dbhs;
  weaken $_ for values %weak_dbhs;

### tie the first one's cache
  if (1) {
    ok(
      tie( my %cache, 'Tie::StdHash'),
      refdesc($dbhs[0]) . ' cache tied'
    );
    $dbhs[0]->{CachedKids} = \%cache;
  }

t/73cachedkids.t  view on Meta::CPAN

  $_->prepare_cached( 'SELECT name FROM .' )
    for @dbhs;

### get weakrefs of both caches
  %weak_caches = map {
    sprintf( 'statement cache of %s (%s)',
      refdesc($_),
      refdesc($_->{CachedKids})
    ) => $_->{CachedKids}
  } @dbhs;
  weaken $_ for values %weak_caches;

### check both caches have entries
  is (scalar keys %{$weak_caches{$_}}, 1, "One cached statement found in $_")
    for keys %weak_caches;

### check both caches have sane refcounts
  is ( refcount( $weak_caches{$_} ), 1, "Refcount of $_ correct")
    for keys %weak_caches;

### check both dbh have sane refcounts



( run in 0.298 second using v1.01-cache-2.11-cpan-65fba6d93b7 )