<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">########################################################################
package DBI;

########################################################################
#
# Copyright (c) 2002  Tim Bunce  Ireland.
#
# See COPYRIGHT section in DBI.pm for usage and distribution rights.
#
########################################################################
#
# Please send patches and bug reports to
#
# Jeff Zucker &lt;jeff@vpservices.com&gt;  with cc to &lt;dbi-dev@perl.org&gt;
#
########################################################################

# TODO:
#	recheck code against DBI
#	support TraceLevel and other attributes

use strict;
use Carp;
require Symbol;

$DBI::PurePerl = $ENV{DBI_PUREPERL} || 1;
$DBI::PurePerl::VERSION = substr(q$Revision: 1.10 $, 10);
$DBI::neat_maxlen ||= 400;

$DBI::tfh = Symbol::gensym();
open $DBI::tfh, "&gt;&amp;STDERR" or warn "Can't dup STDERR: $!";


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

use constant SQL_ALL_TYPES =&gt; 0;
use constant SQL_ARRAY =&gt; 50;
use constant SQL_ARRAY_LOCATOR =&gt; 51;
use constant SQL_BINARY =&gt; (-2);
use constant SQL_BIT =&gt; (-7);
use constant SQL_BLOB =&gt; 30;
use constant SQL_BLOB_LOCATOR =&gt; 31;
use constant SQL_BOOLEAN =&gt; 16;
use constant SQL_CHAR =&gt; 1;
use constant SQL_CLOB =&gt; 40;
use constant SQL_CLOB_LOCATOR =&gt; 41;
use constant SQL_DATE =&gt; 9;
use constant SQL_DATETIME =&gt; 9;
use constant SQL_DECIMAL =&gt; 3;
use constant SQL_DOUBLE =&gt; 8;
use constant SQL_FLOAT =&gt; 6;
use constant SQL_GUID =&gt; (-11);
use constant SQL_INTEGER =&gt; 4;
use constant SQL_INTERVAL =&gt; 10;
use constant SQL_INTERVAL_DAY =&gt; 103;
use constant SQL_INTERVAL_DAY_TO_HOUR =&gt; 108;
use constant SQL_INTERVAL_DAY_TO_MINUTE =&gt; 109;
use constant SQL_INTERVAL_DAY_TO_SECOND =&gt; 110;
use constant SQL_INTERVAL_HOUR =&gt; 104;
use constant SQL_INTERVAL_HOUR_TO_MINUTE =&gt; 111;
use constant SQL_INTERVAL_HOUR_TO_SECOND =&gt; 112;
use constant SQL_INTERVAL_MINUTE =&gt; 105;
use constant SQL_INTERVAL_MINUTE_TO_SECOND =&gt; 113;
use constant SQL_INTERVAL_MONTH =&gt; 102;
use constant SQL_INTERVAL_SECOND =&gt; 106;
use constant SQL_INTERVAL_YEAR =&gt; 101;
use constant SQL_INTERVAL_YEAR_TO_MONTH =&gt; 107;
use constant SQL_LONGVARBINARY =&gt; (-4);
use constant SQL_LONGVARCHAR =&gt; (-1);
use constant SQL_MULTISET =&gt; 55;
use constant SQL_MULTISET_LOCATOR =&gt; 56;
use constant SQL_NUMERIC =&gt; 2;
use constant SQL_REAL =&gt; 7;
use constant SQL_REF =&gt; 20;
use constant SQL_ROW =&gt; 19;
use constant SQL_SMALLINT =&gt; 5;
use constant SQL_TIME =&gt; 10;
use constant SQL_TIMESTAMP =&gt; 11;
use constant SQL_TINYINT =&gt; (-6);
use constant SQL_TYPE_DATE =&gt; 91;
use constant SQL_TYPE_TIME =&gt; 92;
use constant SQL_TYPE_TIMESTAMP =&gt; 93;
use constant SQL_TYPE_TIMESTAMP_WITH_TIMEZONE =&gt; 95;
use constant SQL_TYPE_TIME_WITH_TIMEZONE =&gt; 94;
use constant SQL_UDT =&gt; 17;
use constant SQL_UDT_LOCATOR =&gt; 18;
use constant SQL_UNKNOWN_TYPE =&gt; 0;
use constant SQL_VARBINARY =&gt; (-3);
use constant SQL_VARCHAR =&gt; 12;
use constant SQL_WCHAR =&gt; (-8);
use constant SQL_WLONGVARCHAR =&gt; (-10);
use constant SQL_WVARCHAR =&gt; (-9);

use constant IMA_HAS_USAGE	=&gt; 0x0001; #/* check parameter usage	*/
use constant IMA_FUNC_REDIRECT	=&gt; 0x0002; #/* is $h-&gt;func(..., "method")*/
use constant IMA_KEEP_ERR	=&gt; 0x0004; #/* don't reset err &amp; errstr	*/
use constant IMA_spare		=&gt; 0x0008; #/* */
use constant IMA_NO_TAINT_IN   	=&gt; 0x0010; #/* don't check for tainted args*/
use constant IMA_NO_TAINT_OUT   =&gt; 0x0020; #/* don't taint results	*/
use constant IMA_COPY_STMT   	=&gt; 0x0040; #/* copy sth Statement to dbh */
use constant IMA_END_WORK	=&gt; 0x0080; #/* set on commit &amp; rollback	*/
use constant IMA_STUB		=&gt; 0x0100; #/* donothing eg $dbh-&gt;connected */

my %is_valid_attribute = map {$_ =&gt;1 } qw(
	Active
	ActiveKids
	Attribution
	AutoCommit
	BegunWork
	CachedKids
	ChopBlanks
	CompatMode
	Database
	DebugDispatch
	Driver
	FetchHashKeyName
	HandleError
	ImplementorClass
	InactiveDestroy
	Kids
	LongReadLen
	LongTruncOk
	MultiThread
	NAME NAME_uc NAME_lc NAME_uc_hash NAME_lc_hash
	NUM_OF_FIELDS
	NUM_OF_PARAMS
	Name
	PrintError
	Provider
	RaiseError
	RootClass
	RowCacheSize
	ShowErrorStatement
	Statement
	Taint
	TraceLevel
	Version
	Warn
);

sub valid_attribute {
    my $attr = shift;
    return 1 if $is_valid_attribute{$attr};
    return 1 if $attr =~ m/^[a-z]/; # starts with lowercase letter
    return 0
}

my $initial_setup;
sub initial_setup {
    $initial_setup = 1;
    warn __FILE__ . " version " . $DBI::PurePerl::VERSION . "\n" if $DBI::dbi_debug;
    untie $DBI::err;
    untie $DBI::errstr;
    untie $DBI::state;
    #tie $DBI::lasth,  'DBI::var', '!lasth';  # special case: return boolean
    #tie $DBI::rows,   'DBI::var', '&amp;rows';   # call &amp;rows   in last used pkg
}

sub  _install_method {
    my ( $caller, $method, $from, $param_hash ) = @_;
    initial_setup() unless $initial_setup;

    my ($class, $method_name) = $method =~ /^[^:]+::(.+)::(.+)$/;
    my $bitmask = $param_hash-&gt;{'O'} || 0;
    my @pre_call_frag;

    push @pre_call_frag, q{
	return $h-&gt;{$_[0]} if exists $h-&gt;{$_[0]};
    } if $method_name eq 'FETCH';

    push @pre_call_frag, "return;"
	if IMA_STUB &amp; $bitmask;

    push @pre_call_frag, q{
	$method_name = $imp . '::' . pop @_;
    } if IMA_FUNC_REDIRECT &amp; $bitmask;

    push @pre_call_frag, q{
	my $dbh = $h-&gt;{Database};
	warn "No Database set for $h on $method_name!" unless $dbh; # eg proxy problems
	$dbh-&gt;{Statement} = $h-&gt;{Statement} if $dbh;
    } if IMA_COPY_STMT &amp; $bitmask;

    push @pre_call_frag, q{
	$h-&gt;{err} = 0;
	$h-&gt;{errstr} = $DBI::state = '';
    } unless IMA_KEEP_ERR &amp; $bitmask;	# see above

    push @pre_call_frag, q{
        if ($DBI::dbi_debug &gt;= 2) {
	    local $^W;
	    my $args = join " ", map { DBI::neat($_) } ($h, @_);
	    printf $DBI::tfh "    &gt; $method_name in $imp ($args)\n";
	}
    } if exists $ENV{DBI_TRACE};	# note use of 'exists'

    push @pre_call_frag, q{
        $h-&gt;{'_last_method'} = $method_name;
    } unless exists $DBI::last_method_except{$method_name};


    # --- post method call code fragments ---
    my @post_call_frag;

    push @post_call_frag, q{
        if ($DBI::dbi_debug) {
	    if ($h-&gt;{err}) {
		printf $DBI::tfh "    !! ERROR: %s %s\n", $h-&gt;{err}, $h-&gt;{errstr};
	    }
	    my $ret = join " ", map { DBI::neat($_) } @ret;
	    printf $DBI::tfh "    &lt; $method_name= %s\n", $ret;
	}
    } if exists $ENV{DBI_TRACE}; # note use of exists

    push @post_call_frag, q{
	if ($h-&gt;{BegunWork}) {;
	    $h-&gt;{BegunWork}  = 0;
	    $h-&gt;{AutoCommit} = 1;
	}
    } if IMA_END_WORK &amp; $bitmask;

    push @post_call_frag, q{
        if ($h-&gt;{err} &amp;&amp; $call_depth &lt;= 1) {
            my $last = ($DBI::last_method_except{$method_name})
		? ($h-&gt;{'_last_method'}||$method_name) : $method_name;
            my $errstr = $h-&gt;{errstr} || $DBI::errstr || $DBI::err || '';
            my $msg = sprintf "%s %s failed: %s\n", $imp, $last, $errstr;
            if ($h-&gt;{'ShowErrorStatement'} &amp;&amp; $h-&gt;{'Statement'}) {
               $msg .= " for [\"".$h-&gt;{'Statement'}."\"]";
	    }
            my $do_croak = 1;
            if (my $subsub = $h-&gt;{'HandleError'}) {
		$do_croak = 0 if &amp;$subsub($msg,$h,$ret[0]);
            }
	    if ($do_croak) {
  	        carp  $msg if $h-&gt;{PrintError};
	        croak $msg if $h-&gt;{RaiseError};
	    }
	}
    } unless IMA_KEEP_ERR &amp; $bitmask;


    my $method_code = q[
      sub {
        my $h = shift;
	my $h_inner = tied(%$h);

	]
	. ($method_name eq 'DESTROY' ? "return if \$h_inner;\n" : "")
	. q[

	$h = $h_inner if $h_inner;
	# XXX this eval isn't good because it overwrites $@
        my $imp = eval { $h-&gt;{"ImplementorClass"} } or return; # probably global destruction

	] . join("\n", '', @pre_call_frag, '') . q[

	my $call_depth = $h-&gt;{'_call_depth'} + 1;
	local ($h-&gt;{'_call_depth'}) = $call_depth;

        my $sub = $imp-&gt;can($method_name) or croak "Can't find $method_name method for $h";

	my @ret;
        (wantarray) ? (@ret = &amp;$sub($h,@_)) : (@ret = scalar &amp;$sub($h,@_));

	] . join("\n", '', @post_call_frag, '') . q[

	return (wantarray) ? @ret : $ret[0];
      }
    ];
    no strict qw(refs);
    my $code_ref = eval $method_code;
    *$method = eval qq{#line 1 "$method"\n$method_code};
    die "$@\n$method_code\n" if $@;
    if (0 &amp;&amp; $method =~ 'set_err') { # debuging tool
	my $l=0; # show line-numbered code for method
	warn join("\n", map { ++$l.": $_" } split/\n/,$method_code);
    }
}

sub _setup_handle {
    my($h, $imp_class, $parent, $imp_data) = @_;
    my $h_inner = tied(%$h) || $h;
    warn "\n_setup_handle(@_)" if $DBI::dbi_debug &gt;= 4;
    if (ref($parent) =~ /^[^:]+::dr/){
        #$h_inner-&gt;{$_} ||= $parent-&gt;{$_} foreach (qw(Name Version Attribution));
        $h_inner-&gt;{Driver} = $parent;
    }
    $h_inner-&gt;{"_call_depth"} = 0;
    $h_inner-&gt;{"imp_data"} = $imp_data;
    $h_inner-&gt;{"ImplementorClass"} = $imp_class;
    $h_inner-&gt;{"Kids"} = $h_inner-&gt;{"ActiveKids"} = 0;	# XXX not maintained
    $h_inner-&gt;{"Active"} = 1;
    $h_inner-&gt;{"FetchHashKeyName"} ||= $parent-&gt;{"FetchHashKeyName"} || 'NAME';
    $h_inner-&gt;{"Taint"}= 0 unless defined $h_inner-&gt;{"Taint"};
    $h_inner-&gt;{"Warn"} = 1 unless defined $h_inner-&gt;{"Warn"};
    if (ref($parent) =~ /^[^:]+::db/){
        $h_inner-&gt;{'Database'}    = $parent;
        $h_inner-&gt;{'RaiseError'}  = $parent-&gt;{'RaiseError'};
        $h_inner-&gt;{'PrintError'}  = $parent-&gt;{'PrintError'};
        $h_inner-&gt;{'HandleError'} = $parent-&gt;{'HandleError'};
        $parent-&gt;{Statement} = $h_inner-&gt;{Statement};
	#use Data::Dumper; $Data::Dumper::Indent=1;
	#warn Dumper([ "$h_inner, $parent", $h_inner-&gt;{Database}]);
    }
}
sub constant {
    warn "constant @_"; return;
}
sub trace {
    my ($h, $level, $file) = @_;
    my $old_level = $DBI::dbi_debug;
    _set_trace_file($file);
    if (defined $level) {
	$DBI::dbi_debug = $level;
	print $DBI::tfh "    DBI $DBI::VERSION (PurePerl) "
                . "dispatch trace level set to $level\n" if $level;
        if ($level==0 and fileno($DBI::tfh)) {
	    _set_trace_file("");
        }
    }
    return $old_level;
}
sub _set_trace_file {
    my ($file) = @_;
    return unless defined $file;
    unless ($file) {
	open $DBI::tfh, "&gt;&amp;STDERR" or warn "Can't dup STDERR: $!";
	return 1;
    }
    open $DBI::tfh, "&gt;&gt;$file" or carp "Can't open $file: $!";
    select((select($DBI::tfh), $| = 1)[0]);
    return 1;
}
sub _get_imp_data {  shift-&gt;{"imp_data"}; }
sub _svdump       { }
sub dump_handle   { my $h = shift; warn join "\n", %$h; }

sub _handles {
    my $h = shift;
    my $h_inner = tied %$h;
    if ($h_inner) {	# this is okay
	return $h unless wantarray;
	return ($h, $h_inner);
    }
    # XXX this isn't okay... we have an inner handle but
    # currently have no way to get at its outer handle,
    # so we just warn and return the inner one for both...
    Carp::carp("Can't return outer handle from inner handle using DBI::PurePerl");
    return $h unless wantarray;
    return ($h,$h);
}

sub hash {
    my ($key, $type) = @_;
    my ($hash);
    if (!$type) {
        $hash = 0;
        # XXX The C version uses the "char" type, which could be either
        # signed or unsigned.  I use signed because so do the two
        # compilers on my system.
        for my $char (unpack ("c*", $key)) {
            $hash = $hash * 33 + $char;
        }
        $hash &amp;= 0x7FFFFFFF;    # limit to 31 bits
        $hash |= 0x40000000;    # set bit 31
        return -$hash;          # return negative int
    }
    elsif ($type == 1) {	# Fowler/Noll/Vo hash
        # see http://www.isthe.com/chongo/tech/comp/fnv/
        require Math::BigInt;   # feel free to reimplement w/o BigInt!
	my $version = $Math::BigInt::VERSION || 0;
	if ($version &gt;= 1.56) {
	    $hash = Math::BigInt-&gt;new(0x811c9dc5);
	    for my $uchar (unpack ("C*", $key)) {
		# multiply by the 32 bit FNV magic prime mod 2^64
		$hash = ($hash * 0x01000193) &amp; 0xffffffff;
		# xor the bottom with the current octet
		$hash ^= $uchar;
	    }
	    # cast to int
	    return unpack "i", pack "i", $hash;
	}
	croak("DBI::PurePerl doesn't support hash type 1 without Math::BigInt &gt;= 1.56 (available on CPAN)");
    }
    else {
        croak("bad hash type $type");
    }
}
sub looks_like_number {
    my @new = ();
    for my $thing(@_) {
        if (!defined $thing or $thing eq '') {
            push @new, undef;
        }
	elsif ( ($thing &amp; ~ $thing) eq "0") { # magic from Randal
            push @new, 1;
	}
        else {
	    push @new, 0;
	}
    }
    return (@_ &gt;1) ? @new : $new[0];
}
sub neat {
    my $v = shift;
    return "undef" unless defined $v;
    return $v      if looks_like_number($v);
    my $maxlen = shift || $DBI::neat_maxlen;
    if ($maxlen &amp;&amp; $maxlen &lt; length($v) + 2) {
	$v = substr($v,0,$maxlen-5);
	$v .= '...';
    }
    return "'$v'";
}

package DBI::var;              # ============ DBI::var

sub FETCH {
    my($key)=shift;
    return $DBI::err     if $$key eq '*err';
    return $DBI::errstr  if $$key eq '&amp;errstr';
    if ($$key eq '"state'){
die; # XXX
        my $state = $DBI::state;
        return $state if $state;
        return '' unless defined $state;
	$state= ($DBI::err) ? "S1000" : "00000" unless $state;
        return $state;
    }
    Carp::croak("FETCH $key not supported when using DBI::PurePerl");
}

package DBD::_::common;		# ============ DBD::_::common

sub trace {	# XXX should set per-handle level, not global
    my ($h, $level, $file) = @_;
    my $old_level = $DBI::dbi_debug;
    if (defined $level) {
	$DBI::dbi_debug = $level;
	printf $DBI::tfh
            "    %s trace level set to %d in DBI $DBI::VERSION (PurePerl)\n",
	    $h, $level if $file;
    }
    _set_trace_file($file) if defined $file;
    return $old_level;
}
*debug = \&amp;trace; *debug = \&amp;trace; # twice to avoid typo warning

sub FETCH {
    my($h,$key)= @_;
    if (!$h-&gt;{$key} and $key =~ /^NAME_.c$/) {
        my $cols = $h-&gt;FETCH('NAME');
        return undef unless $cols;
        my @lcols = map { lc $_ } @$cols;
        $h-&gt;STORE('NAME_lc', \@lcols);
        my @ucols = map { uc $_ } @$cols;
        $h-&gt;STORE('NAME_uc',\@ucols);
        return $h-&gt;FETCH($key);
    }
    if (!$h-&gt;{$key} and $key =~ /^NAME.*_hash$/) {
        my $i=0;
        for my $c(@{$h-&gt;FETCH('NAME')}) {
            $h-&gt;{'NAME_hash'}-&gt;{$c}    = $i;
            $h-&gt;{'NAME_lc_hash'}-&gt;{"\L$c"} = $i;
            $h-&gt;{'NAME_uc_hash'}-&gt;{"\U$c"} = $i;
            $i++;
        }
    }
    my $v = $h-&gt;{$key};
    if (!defined $v &amp;&amp; !exists $h-&gt;{$key}) {
	Carp::croak( sprintf "Can't get %s-&gt;{%s}: unrecognised attribute (@{[ %$h ]})",$h,$key)
	    if !$is_valid_attribute{$key} and $key =~ m/^[A-Z]/;
    }
    return $v;
}
sub STORE {
    my ($h,$key,$value) = @_;
    if ($key eq 'AutoCommit') {
	croak("DBD driver has not implemented the AutoCommit attribute")
	    unless $value == -900 || $value == -901;
	$value = ($value == -901);
    }
    elsif (!$is_valid_attribute{$key} &amp;&amp; $key =~ /^[A-Z]/ &amp;&amp; !exists $h-&gt;{$key}) {
       Carp::croak(sprintf "Can't set %s-&gt;{%s}: unrecognised attribute or invalid value %s",
	    $h,$key,$value);
    }
    $h-&gt;{$key} = $value;
    return 1;
}
sub err {
    my $h = shift;
    # XXX need to be shared between dbh and sth?
    my $err = $h-&gt;{'err'} || $h-&gt;{'errstr'};
    return $err;
}
sub errstr {
    my $h = shift;
    my $errstr = $h-&gt;{'errstr'} || '';   # $h-&gt;{'err'}; caught in DBD-CSV
    return $errstr;
}
sub state {
    return shift-&gt;{state};
}
sub event { }
sub set_err {
    my ($h, $errnum,$msg,$state, $method, $rv) = @_;
    $h = tied(%$h) || $h; # for code that calls $h-&gt;DBI::set_err(...)
    $msg = $errnum unless defined $msg;
    $h-&gt;{'_last_method'} = $method if $method;
    $h-&gt;{errstr} = $DBI::errstr = $msg;
    $h-&gt;{state}  = $DBI::state  = (defined $state) ? ($state eq "00000" ? "" : $state) : ($errnum ? "S1000" : "");
    $h-&gt;{err}    = $DBI::err    = $errnum;
    if (my $dbh = $h-&gt;{Database}) {
	$dbh-&gt;{errstr} = $msg;
	$dbh-&gt;{err} = $errnum;
    }
    return $rv; # usually undef
}
sub trace_msg {
    my ($h, $msg, $minlevel)=@_;
    $minlevel = 1 unless defined $minlevel;
    #my $curlevel = (ref $h) ? $h-&gt;{TraceLevel} : 0;	# XXX
    my $curlevel = $DBI::dbi_debug; # XXX if $DBI::dbi_debug &gt; $curlevel;
    return if $curlevel &lt; $minlevel;
    print $DBI::tfh $msg;
    return 1;
}
sub private_data {
    warn "private_data @_";
}
sub rows {
    return -1; # always returns -1 here, see DBD::_::st::rows below
}
sub DESTROY {
}

package DBD::_::st;		# ============ DBD::_::st

sub fetchrow_arrayref	{
    my $h = shift;
    # if we're here then driver hasn't implemented fetch/fetchrow_arrayref
    # so we assume they've implemented fetchrow_array and call that instead
    my @row = $h-&gt;fetchrow_array or return;
    return $h-&gt;_set_fbav(\@row);
}
# twice to avoid typo warning
*fetch = \&amp;fetchrow_arrayref;  *fetch = \&amp;fetchrow_arrayref;

sub fetchrow_array	{
    my $h = shift;
    # if we're here then driver hasn't implemented fetchrow_array
    # so we assume they've implemented fetch/fetchrow_arrayref
    my $row = $h-&gt;fetch or return;
    return @$row;
}
*fetchrow = \&amp;fetchrow_array; *fetchrow = \&amp;fetchrow_array;

sub fetchrow_hashref {
    my $h         = shift;
    my $row       = $h-&gt;fetch or return;
    my $FetchCase = shift;
    my $FetchHashKeyName = $FetchCase || $h-&gt;{'FetchHashKeyName'} || 'NAME';
    my $FetchHashKeys    = $h-&gt;FETCH($FetchHashKeyName);
    my %rowhash;
    @rowhash{ @$FetchHashKeys } = @$row;
    return \%rowhash;
}
sub dbih_setup_fbav {
    my $h = shift;
    return $h-&gt;{'_fbav'} || do {
        $DBI::PurePerl::var-&gt;{rows} = $h-&gt;{'_rows'} = 0;
        my $fields = $h-&gt;{'NUM_OF_FIELDS'}
                  or DBI::croak("NUM_OF_FIELDS not set");
        my @row = (undef) x $fields;
        \@row;
    };
}
sub _get_fbav {
    my $h = shift;
    my $av = $h-&gt;{'_fbav'} ||= dbih_setup_fbav($h);
    ++$h-&gt;{'_rows'};
    return $av;
}
sub _set_fbav {
    my $h = shift;
    my $fbav = $h-&gt;{'_fbav'};
    if ($fbav) {
	++$h-&gt;{'_rows'};
    }
    else {
	$fbav = $h-&gt;_get_fbav;
    }
    my $row = shift;
    if (my $bc = $h-&gt;{'_bound_cols'}) {
        for my $i (0..@$row-1) {
            my $bound = $bc-&gt;[$i];
            $fbav-&gt;[$i] = ($bound) ? ($$bound = $row-&gt;[$i]) : $row-&gt;[$i];
        }
    }
    else {
        @$fbav = @$row;
    }
    return $fbav;
}
sub bind_col {
    my ($h, $col, $value_ref,$from_bind_columns) = @_;
    $col-- unless $from_bind_columns; # XXX fix later
    DBI::croak("bind_col($col,$value_ref) needs a reference to a scalar")
	unless ref $value_ref eq 'SCALAR';
    my $fbav = $h-&gt;_get_fbav;
    $h-&gt;{'_bound_cols'}-&gt;[$col] = $value_ref;
    return 1;
}
sub bind_columns {
    my $h = shift;
    shift if !defined $_[0] or ref $_[0] eq 'HASH'; # old style args
    my $fbav = $h-&gt;_get_fbav;
    DBI::croak("bind_columns called with wrong number of args")
	if @_ != @$fbav;
    foreach (0..@_-1) {
        $h-&gt;bind_col($_, $_[$_],'from_bind_columns')
    }
    return 1;
}
sub finish {
    my $h = shift;
    $h-&gt;{'_fbav'} = undef;
    $h-&gt;{'Active'} = 0;
    return 1;
}
sub rows {
    my $h = shift;
    my $rows = $h-&gt;{'_rows'} || $DBI::PurePerl::var-&gt;{rows};
    return -1 unless defined $rows;
    return $rows;
}

1;
__END__

=pod

=head1 NAME

 DBI::PurePerl -- a DBI emulation using pure perl (no C/XS compilation required)

=head1 SYNOPSIS

 BEGIN { $ENV{DBI_PUREPERL} = 2 }
 use DBI;

=head1 DESCRIPTION

This is a pure perl emulation of the DBI internals.  In almost all
cases you will be better off using standard DBI since the portions
of the standard version written in C make it *much* faster.

However, if you are in a situation where it isn't possible to install
a compiled version of standard DBI, and you're using pure-perl DBD
drivers, then this module allows you to use most common features
of DBI without needing any changes in your scripts.

=head1 EXPERIMENTAL STATUS

DBI::PurePerl is very new so please treat it as experimental pending
more extensive testing.  So far it has passed all tests with DBD::CSV,
DBD::AnyData, DBD::XBase, DBD::Sprite, DBD::mysqlPP.  Please send
bug reports to Jeff Zucker at &lt;jeff@vpservices.com&gt; with a cc to
&lt;dbi-dev@perl.org&gt;.

=head1 USAGE

The usage is the same as for standard DBI with the exception
that you need to set the enviornment variable DBI_PUREPERL if
you want to use the PurePerl version.

 DBI_PUREPERL == 0 (the default) Always use compiled DBI, die
                   if it isn't properly compiled &amp; installed

 DBI_PUREPERL == 1 Use compiled DBI if it is properly compiled
                   &amp; installed, otherwise use PurePerl

 DBI_PUREPERL == 2 Always use PurePerl

You may set the enviornment variable in your shell (e.g. with
set or setenv or export, etc) or else set it in your script like
this:

 BEGIN { $ENV{DBI_PUREPERL}=2 }

before you C&lt;use DBI;&gt;.

=head1 INSTALLATION

In most situations simply install DBI (see the DBI pod for details).

In the situation in which you can not install DBI itself, you
may manually copy DBI.pm and PurePerl.pm into the appropriate
directories.

For example:

 cp DBI.pm      /usr/jdoe/mylibs/.
 cp PurePerl.pm /usr/jdoe/mylibs/DBI/.

Then add this to the top of scripts:

 BEGIN {
   $ENV{DBI_PUREPERL} = 1;	# or =2
   unshift @INC, '/usr/jdoe/mylibs';
 }

(Or should we perhaps patch Makefile.PL so that if DBI_PUREPERL
is set to 2 prior to make, the normal compile process is skipped
and the files are installed automatically?)

=head1 DIFFERENCES BETWEEN DBI AND DBI::PurePerl

=head2 Attributes

Some handle attributes are either not supported or have very limited
functionality:

  ActiveKids
  InactiveDestroy
  Kids
  Taint
  TraceLevel

(and probably others)

=head2 Tracing

Trace functionality is more limited and the code to handle tracing is
only embeded into DBI:PurePerl if the DBI_TRACE environment variable
is defined.  To enable total tracing you can set the DBI_TRACE
environment variable as usual.  But to enable individual handle
tracing using the trace() method you also need to set the DBI_TRACE
environment variable, but set it to 0.
 
=head2 Parameter Usage Checking

The DBI does some basic parameter count checking on method calls.
DBI::PurePerl doesn't.

=head2 Speed

DBI::PurePerl is slower. Although, with some drivers in some
contexts this may not be very significant for you.

By way of example... the test.pl script in the DBI source
distribution has a simple benchmark that just does:

    my $null_dbh = DBI-&gt;connect('dbi:NullP:','','');
    my $i = 10_000;
    $null_dbh-&gt;prepare('') while $i--;

In other words just prepares a statement, creating and destroying
a statement handle, over and over again.  Using the real DBI this
runs at ~4550 handles per second whereas DBI::PurePerl manages
~2800 per second on the same machine (not too bad really).

=head2 May not fully support hash()

If you want to use type 1 hash, i.e., C&lt;hash($string,1)&gt; with
DBI::PurePerl, you'll need version 1.56 or higher of Math::BigInt
(available on CPAN).

=head2 Doesn't support preparse()

The DBI-&gt;preparse() method isn't supported in DBI::PurePerl.

=head2 Doesn't support DBD::Proxy

There's a subtle problem somewhere I've not been able to identify.
DBI::ProxyServer seem to work fine with DBI::PurePerl but DBD::Proxy
does not work 100% (which is sad because that would be far more useful :)
Try re-enabling t/80proxy.t for DBI::PurePerl to see if the problem
that remains will affect you're usage.

=head2 Undoubtedly Others

Please let us know if you find any other differences between DBI
and DBI::PurePerl.

=head1 AUTHORS

Tim Bunce and Jeff Zucker.

Tim provided the direction and basis for the code.  The original
idea for the module and most of the brute force porting from C to
Perl was by Jeff. Tim then reworked some core parts to boost the
performance and accuracy of the emulation. Thanks also to Randal
Schwartz and John Tobey for patches.

=head1 COPYRIGHT

Copyright (c) 2002  Tim Bunce  Ireland.

See COPYRIGHT section in DBI.pm for usage and distribution rights.

=cut
</pre></body></html>