�ɲɾ�����ӯ�����һ��ˣ��������С���˴��ͣ�������P���ҹ��ñ˽��ά�Բ��������˸߸ԣ�������ơ��ҹ��ñ�����ά�Բ���ˡ���˳^�ӣ������ӡ� ���ͯj�ӣ��ƺ���ӣ� ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!PK1]+ Profile.pmnu[package DBI::Profile; =head1 NAME DBI::Profile - Performance profiling and benchmarking for the DBI =head1 SYNOPSIS The easiest way to enable DBI profiling is to set the DBI_PROFILE environment variable to 2 and then run your code as usual: DBI_PROFILE=2 prog.pl This will profile your program and then output a textual summary grouped by query when the program exits. You can also enable profiling by setting the Profile attribute of any DBI handle: $dbh->{Profile} = 2; Then the summary will be printed when the handle is destroyed. Many other values apart from are possible - see L<"ENABLING A PROFILE"> below. =head1 DESCRIPTION The DBI::Profile module provides a simple interface to collect and report performance and benchmarking data from the DBI. For a more elaborate interface, suitable for larger programs, see L and L. For Apache/mod_perl applications see L. =head1 OVERVIEW Performance data collection for the DBI is built around several concepts which are important to understand clearly. =over 4 =item Method Dispatch Every method call on a DBI handle passes through a single 'dispatch' function which manages all the common aspects of DBI method calls, such as handling the RaiseError attribute. =item Data Collection If profiling is enabled for a handle then the dispatch code takes a high-resolution timestamp soon after it is entered. Then, after calling the appropriate method and just before returning, it takes another high-resolution timestamp and calls a function to record the information. That function is passed the two timestamps plus the DBI handle and the name of the method that was called. That data about a single DBI method call is called a I. =item Data Filtering If the method call was invoked by the DBI or by a driver then the call is ignored for profiling because the time spent will be accounted for by the original 'outermost' call for your code. For example, the calls that the selectrow_arrayref() method makes to prepare() and execute() etc. are not counted individually because the time spent in those methods is going to be allocated to the selectrow_arrayref() method when it returns. If this was not done then it would be very easy to double count time spent inside the DBI. =item Data Storage Tree The profile data is accumulated as 'leaves on a tree'. The 'path' through the branches of the tree to a particular leaf is determined dynamically for each sample. This is a key feature of DBI profiling. For each profiled method call the DBI walks along the Path and uses each value in the Path to step into and grow the Data tree. For example, if the Path is [ 'foo', 'bar', 'baz' ] then the new profile sample data will be I into the tree at $h->{Profile}->{Data}->{foo}->{bar}->{baz} But it's not very useful to merge all the call data into one leaf node (except to get an overall 'time spent inside the DBI' total). It's more common to want the Path to include dynamic values such as the current statement text and/or the name of the method called to show what the time spent inside the DBI was for. The Path can contain some 'magic cookie' values that are automatically replaced by corresponding dynamic values when they're used. These magic cookies always start with a punctuation character. For example a value of 'C' in the Path causes the corresponding entry in the Data to be the name of the method that was called. For example, if the Path was: [ 'foo', '!MethodName', 'bar' ] and the selectall_arrayref() method was called, then the profile sample data for that call will be merged into the tree at: $h->{Profile}->{Data}->{foo}->{selectall_arrayref}->{bar} =item Profile Data Profile data is stored at the 'leaves' of the tree as references to an array of numeric values. For example: [ 106, # 0: count of samples at this node 0.0312958955764771, # 1: total duration 0.000490069389343262, # 2: first duration 0.000176072120666504, # 3: shortest duration 0.00140702724456787, # 4: longest duration 1023115819.83019, # 5: time of first sample 1023115819.86576, # 6: time of last sample ] After the first sample, later samples always update elements 0, 1, and 6, and may update 3 or 4 depending on the duration of the sampled call. =back =head1 ENABLING A PROFILE Profiling is enabled for a handle by assigning to the Profile attribute. For example: $h->{Profile} = DBI::Profile->new(); The Profile attribute holds a blessed reference to a hash object that contains the profile data and attributes relating to it. The class the Profile object is blessed into is expected to provide at least a DESTROY method which will dump the profile data to the DBI trace file handle (STDERR by default). All these examples have the same effect as each other: $h->{Profile} = 0; $h->{Profile} = "/DBI::Profile"; $h->{Profile} = DBI::Profile->new(); $h->{Profile} = {}; $h->{Profile} = { Path => [] }; Similarly, these examples have the same effect as each other: $h->{Profile} = 6; $h->{Profile} = "6/DBI::Profile"; $h->{Profile} = "!Statement:!MethodName/DBI::Profile"; $h->{Profile} = { Path => [ '!Statement', '!MethodName' ] }; If a non-blessed hash reference is given then the DBI::Profile module is automatically C'd and the reference is blessed into that class. If a string is given then it is processed like this: ($path, $module, $args) = split /\//, $string, 3 @path = split /:/, $path @args = split /:/, $args eval "require $module" if $module $module ||= "DBI::Profile" $module->new( Path => \@Path, @args ) So the first value is used to select the Path to be used (see below). The second value, if present, is used as the name of a module which will be loaded and it's C method called. If not present it defaults to DBI::Profile. Any other values are passed as arguments to the C method. For example: "C<2/DBIx::OtherProfile/Foo:42>". Numbers can be used as a shorthand way to enable common Path values. The simplest way to explain how the values are interpreted is to show the code: push @Path, "DBI" if $path_elem & 0x01; push @Path, "!Statement" if $path_elem & 0x02; push @Path, "!MethodName" if $path_elem & 0x04; push @Path, "!MethodClass" if $path_elem & 0x08; push @Path, "!Caller2" if $path_elem & 0x10; So "2" is the same as "!Statement" and "6" (2+4) is the same as "!Statement:!Method". Those are the two most commonly used values. Using a negative number will reverse the path. Thus "-6" will group by method name then statement. The splitting and parsing of string values assigned to the Profile attribute may seem a little odd, but there's a good reason for it. Remember that attributes can be embedded in the Data Source Name string which can be passed in to a script as a parameter. For example: dbi:DriverName(Profile=>2):dbname dbi:DriverName(Profile=>{Username}:!Statement/MyProfiler/Foo:42):dbname And also, if the C environment variable is set then The DBI arranges for every driver handle to share the same profile object. When perl exits a single profile summary will be generated that reflects (as nearly as practical) the total use of the DBI by the application. =head1 THE PROFILE OBJECT The DBI core expects the Profile attribute value to be a hash reference and if the following values don't exist it will create them as needed: =head2 Data A reference to a hash containing the collected profile data. =head2 Path The Path value is a reference to an array. Each element controls the value to use at the corresponding level of the profile Data tree. If the value of Path is anything other than an array reference, it is treated as if it was: [ '!Statement' ] The elements of Path array can be one of the following types: =head3 Special Constant B Use the current Statement text. Typically that's the value of the Statement attribute for the handle the method was called with. Some methods, like commit() and rollback(), are unrelated to a particular statement. For those methods !Statement records an empty string. For statement handles this is always simply the string that was given to prepare() when the handle was created. For database handles this is the statement that was last prepared or executed on that database handle. That can lead to a little 'fuzzyness' because, for example, calls to the quote() method to build a new statement will typically be associated with the previous statement. In practice this isn't a significant issue and the dynamic Path mechanism can be used to setup your own rules. B Use the name of the DBI method that the profile sample relates to. B Use the fully qualified name of the DBI method, including the package, that the profile sample relates to. This shows you where the method was implemented. For example: 'DBD::_::db::selectrow_arrayref' => 0.022902s 'DBD::mysql::db::selectrow_arrayref' => 2.244521s / 99 = 0.022445s avg (first 0.022813s, min 0.022051s, max 0.028932s) The "DBD::_::db::selectrow_arrayref" shows that the driver has inherited the selectrow_arrayref method provided by the DBI. But you'll note that there is only one call to DBD::_::db::selectrow_arrayref but another 99 to DBD::mysql::db::selectrow_arrayref. Currently the first call doesn't record the true location. That may change. B Use a string showing the filename and line number of the code calling the method. B Use a string showing the filename and line number of the code calling the method, as for !Caller, but also include filename and line number of the code that called that. Calls from DBI:: and DBD:: packages are skipped. B Same as !Caller above except that only the filename is included, not the line number. B Same as !Caller2 above except that only the filenames are included, not the line number. B Use the current value of time(). Rarely used. See the more useful C below. B Where C is an integer. Use the current value of time() but with reduced precision. The value used is determined in this way: int( time() / N ) * N This is a useful way to segregate a profile into time slots. For example: [ '!Time~60', '!Statement' ] =head3 Code Reference The subroutine is passed the handle it was called on and the DBI method name. The current Statement is in $_. The statement string should not be modified, so most subs start with C. The list of values it returns is used at that point in the Profile Path. Any undefined values are treated as the string "C". The sub can 'veto' (reject) a profile sample by including a reference to undef (C<\undef>) in the returned list. That can be useful when you want to only profile statements that match a certain pattern, or only profile certain methods. =head3 Subroutine Specifier A Path element that begins with 'C<&>' is treated as the name of a subroutine in the DBI::ProfileSubs namespace and replaced with the corresponding code reference. Currently this only works when the Path is specified by the C environment variable. Also, currently, the only subroutine in the DBI::ProfileSubs namespace is C<'&norm_std_n3'>. That's a very handy subroutine when profiling code that doesn't use placeholders. See L for more information. =head3 Attribute Specifier A string enclosed in braces, such as 'C<{Username}>', specifies that the current value of the corresponding database handle attribute should be used at that point in the Path. =head3 Reference to a Scalar Specifies that the current value of the referenced scalar be used at that point in the Path. This provides an efficient way to get 'contextual' values into your profile. =head3 Other Values Any other values are stringified and used literally. (References, and values that begin with punctuation characters are reserved.) =head1 REPORTING =head2 Report Format The current accumulated profile data can be formatted and output using print $h->{Profile}->format; To discard the profile data and start collecting fresh data you can do: $h->{Profile}->{Data} = undef; The default results format looks like this: DBI::Profile: 0.001015s 42.7% (5 calls) programname @ YYYY-MM-DD HH:MM:SS '' => 0.000024s / 2 = 0.000012s avg (first 0.000015s, min 0.000009s, max 0.000015s) 'SELECT mode,size,name FROM table' => 0.000991s / 3 = 0.000330s avg (first 0.000678s, min 0.000009s, max 0.000678s) Which shows the total time spent inside the DBI, with a count of the total number of method calls and the name of the script being run, then a formatted version of the profile data tree. If the results are being formatted when the perl process is exiting (which is usually the case when the DBI_PROFILE environment variable is used) then the percentage of time the process spent inside the DBI is also shown. If the process is not exiting then the percentage is calculated using the time between the first and last call to the DBI. In the example above the paths in the tree are only one level deep and use the Statement text as the value (that's the default behaviour). The merged profile data at the 'leaves' of the tree are presented as total time spent, count, average time spent (which is simply total time divided by the count), then the time spent on the first call, the time spent on the fastest call, and finally the time spent on the slowest call. The 'avg', 'first', 'min' and 'max' times are not particularly useful when the profile data path only contains the statement text. Here's an extract of a more detailed example using both statement text and method name in the path: 'SELECT mode,size,name FROM table' => 'FETCH' => 0.000076s 'fetchrow_hashref' => 0.036203s / 108 = 0.000335s avg (first 0.000490s, min 0.000152s, max 0.002786s) Here you can see the 'avg', 'first', 'min' and 'max' for the 108 calls to fetchrow_hashref() become rather more interesting. Also the data for FETCH just shows a time value because it was only called once. Currently the profile data is output sorted by branch names. That may change in a later version so the leaf nodes are sorted by total time per leaf node. =head2 Report Destination The default method of reporting is for the DESTROY method of the Profile object to format the results and write them using: DBI->trace_msg($results, 0); # see $ON_DESTROY_DUMP below to write them to the DBI trace() filehandle (which defaults to STDERR). To direct the DBI trace filehandle to write to a file without enabling tracing the trace() method can be called with a trace level of 0. For example: DBI->trace(0, $filename); The same effect can be achieved without changing the code by setting the C environment variable to C<0=filename>. The $DBI::Profile::ON_DESTROY_DUMP variable holds a code ref that's called to perform the output of the formatted results. The default value is: $ON_DESTROY_DUMP = sub { DBI->trace_msg($results, 0) }; Apart from making it easy to send the dump elsewhere, it can also be useful as a simple way to disable dumping results. =head1 CHILD HANDLES Child handles inherit a reference to the Profile attribute value of their parent. So if profiling is enabled for a database handle then by default the statement handles created from it all contribute to the same merged profile data tree. =head1 PROFILE OBJECT METHODS =head2 format See L. =head2 as_node_path_list @ary = $dbh->{Profile}->as_node_path_list(); @ary = $dbh->{Profile}->as_node_path_list($node, $path); Returns the collected data ($dbh->{Profile}{Data}) restructured into a list of array refs, one for each leaf node in the Data tree. This 'flat' structure is often much simpler for applications to work with. The first element of each array ref is a reference to the leaf node. The remaining elements are the 'path' through the data tree to that node. For example, given a data tree like this: {key1a}{key2a}[node1] {key1a}{key2b}[node2] {key1b}{key2a}{key3a}[node3] The as_node_path_list() method will return this list: [ [node1], 'key1a', 'key2a' ] [ [node2], 'key1a', 'key2b' ] [ [node3], 'key1b', 'key2a', 'key3a' ] The nodes are ordered by key, depth-first. The $node argument can be used to focus on a sub-tree. If not specified it defaults to $dbh->{Profile}{Data}. The $path argument can be used to specify a list of path elements that will be added to each element of the returned list. If not specified it defaults to a ref to an empty array. =head2 as_text @txt = $dbh->{Profile}->as_text(); $txt = $dbh->{Profile}->as_text({ node => undef, path => [], separator => " > ", format => '%1$s: %11$fs / %10$d = %2$fs avg (first %12$fs, min %13$fs, max %14$fs)'."\n"; sortsub => sub { ... }, ); Returns the collected data ($dbh->{Profile}{Data}) reformatted into a list of formatted strings. In scalar context the list is returned as a single concatenated string. A hashref can be used to pass in arguments, the default values are shown in the example above. The C and arguments are passed to as_node_path_list(). The C argument is used to join the elements of the path for each leaf node. The C argument is used to pass in a ref to a sub that will order the list. The subroutine will be passed a reference to the array returned by as_node_path_list() and should sort the contents of the array in place. The return value from the sub is ignored. For example, to sort the nodes by the second level key you could use: sortsub => sub { my $ary=shift; @$ary = sort { $a->[2] cmp $b->[2] } @$ary } The C argument is a C format string that specifies the format to use for each leaf node. It uses the explicit format parameter index mechanism to specify which of the arguments should appear where in the string. The arguments to sprintf are: 1: path to node, joined with the separator 2: average duration (total duration/count) (3 thru 9 are currently unused) 10: count 11: total duration 12: first duration 13: smallest duration 14: largest duration 15: time of first call 16: time of first call =head1 CUSTOM DATA MANIPULATION Recall that C<< $h->{Profile}->{Data} >> is a reference to the collected data. Either to a 'leaf' array (when the Path is empty, i.e., DBI_PROFILE env var is 1), or a reference to hash containing values that are either further hash references or leaf array references. Sometimes it's useful to be able to summarise some or all of the collected data. The dbi_profile_merge_nodes() function can be used to merge leaf node values. =head2 dbi_profile_merge_nodes use DBI qw(dbi_profile_merge_nodes); $time_in_dbi = dbi_profile_merge_nodes(my $totals=[], @$leaves); Merges profile data node. Given a reference to a destination array, and zero or more references to profile data, merges the profile data into the destination array. For example: $time_in_dbi = dbi_profile_merge_nodes( my $totals=[], [ 10, 0.51, 0.11, 0.01, 0.22, 1023110000, 1023110010 ], [ 15, 0.42, 0.12, 0.02, 0.23, 1023110005, 1023110009 ], ); $totals will then contain [ 25, 0.93, 0.11, 0.01, 0.23, 1023110000, 1023110010 ] and $time_in_dbi will be 0.93; The second argument need not be just leaf nodes. If given a reference to a hash then the hash is recursively searched for leaf nodes and all those found are merged. For example, to get the time spent 'inside' the DBI during an http request, your logging code run at the end of the request (i.e. mod_perl LogHandler) could use: my $time_in_dbi = 0; if (my $Profile = $dbh->{Profile}) { # if DBI profiling is enabled $time_in_dbi = dbi_profile_merge_nodes(my $total=[], $Profile->{Data}); $Profile->{Data} = {}; # reset the profile data } If profiling has been enabled then $time_in_dbi will hold the time spent inside the DBI for that handle (and any other handles that share the same profile data) since the last request. Prior to DBI 1.56 the dbi_profile_merge_nodes() function was called dbi_profile_merge(). That name still exists as an alias. =head1 CUSTOM DATA COLLECTION =head2 Using The Path Attribute XXX example to be added later using a selectall_arrayref call XXX nested inside a fetch loop where the first column of the XXX outer loop is bound to the profile Path using XXX bind_column(1, \${ $dbh->{Profile}->{Path}->[0] }) XXX so you end up with separate profiles for each loop XXX (patches welcome to add this to the docs :) =head2 Adding Your Own Samples The dbi_profile() function can be used to add extra sample data into the profile data tree. For example: use DBI; use DBI::Profile (dbi_profile dbi_time); my $t1 = dbi_time(); # floating point high-resolution time ... execute code you want to profile here ... my $t2 = dbi_time(); dbi_profile($h, $statement, $method, $t1, $t2); The $h parameter is the handle the extra profile sample should be associated with. The $statement parameter is the string to use where the Path specifies !Statement. If $statement is undef then $h->{Statement} will be used. Similarly $method is the string to use if the Path specifies !MethodName. There is no default value for $method. The $h->{Profile}{Path} attribute is processed by dbi_profile() in the usual way. The $h parameter is usually a DBI handle but it can also be a reference to a hash, in which case the dbi_profile() acts on each defined value in the hash. This is an efficient way to update multiple profiles with a single sample, and is used by the L module. =head1 SUBCLASSING Alternate profile modules must subclass DBI::Profile to help ensure they work with future versions of the DBI. =head1 CAVEATS Applications which generate many different statement strings (typically because they don't use placeholders) and profile with !Statement in the Path (the default) will consume memory in the Profile Data structure for each statement. Use a code ref in the Path to return an edited (simplified) form of the statement. If a method throws an exception itself (not via RaiseError) then it won't be counted in the profile. If a HandleError subroutine throws an exception (rather than returning 0 and letting RaiseError do it) then the method call won't be counted in the profile. Time spent in DESTROY is added to the profile of the parent handle. Time spent in DBI->*() methods is not counted. The time spent in the driver connect method, $drh->connect(), when it's called by DBI->connect is counted if the DBI_PROFILE environment variable is set. Time spent fetching tied variables, $DBI::errstr, is counted. Time spent in FETCH for $h->{Profile} is not counted, so getting the profile data doesn't alter it. DBI::PurePerl does not support profiling (though it could in theory). For asynchronous queries, time spent while the query is running on the backend is not counted. A few platforms don't support the gettimeofday() high resolution time function used by the DBI (and available via the dbi_time() function). In which case you'll get integer resolution time which is mostly useless. On Windows platforms the dbi_time() function is limited to millisecond resolution. Which isn't sufficiently fine for our needs, but still much better than integer resolution. This limited resolution means that fast method calls will often register as taking 0 time. And timings in general will have much more 'jitter' depending on where within the 'current millisecond' the start and end timing was taken. This documentation could be more clear. Probably needs to be reordered to start with several examples and build from there. Trying to explain the concepts first seems painful and to lead to just as many forward references. (Patches welcome!) =cut use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); use Exporter (); use UNIVERSAL (); use Carp; use Module::Load (); use DBI qw(dbi_time dbi_profile dbi_profile_merge_nodes dbi_profile_merge); $VERSION = "2.015065"; @ISA = qw(Exporter); @EXPORT = qw( DBIprofile_Statement DBIprofile_MethodName DBIprofile_MethodClass dbi_profile dbi_profile_merge_nodes dbi_profile_merge dbi_time ); @EXPORT_OK = qw( format_profile_thingy ); use constant DBIprofile_Statement => '!Statement'; use constant DBIprofile_MethodName => '!MethodName'; use constant DBIprofile_MethodClass => '!MethodClass'; our $ON_DESTROY_DUMP = sub { DBI->trace_msg(shift, 0) }; our $ON_FLUSH_DUMP = sub { DBI->trace_msg(shift, 0) }; sub new { my $class = shift; my $profile = { @_ }; return bless $profile => $class; } sub _auto_new { my $class = shift; my ($arg) = @_; # This sub is called by DBI internals when a non-hash-ref is # assigned to the Profile attribute. For example # dbi:mysql(RaiseError=>1,Profile=>!Statement:!MethodName/DBIx::MyProfile/arg1:arg2):dbname # This sub works out what to do and returns a suitable hash ref. $arg =~ s/^DBI::/2\/DBI::/ and carp "Automatically changed old-style DBI::Profile specification to $arg"; # it's a path/module/k1:v1:k2:v2:... list my ($path, $package, $args) = split /\//, $arg, 3; my @args = (defined $args) ? split(/:/, $args, -1) : (); my @Path; for my $element (split /:/, $path) { if (DBI::looks_like_number($element)) { my $reverse = ($element < 0) ? ($element=-$element, 1) : 0; my @p; # a single "DBI" is special-cased in format() push @p, "DBI" if $element & 0x01; push @p, DBIprofile_Statement if $element & 0x02; push @p, DBIprofile_MethodName if $element & 0x04; push @p, DBIprofile_MethodClass if $element & 0x08; push @p, '!Caller2' if $element & 0x10; push @Path, ($reverse ? reverse @p : @p); } elsif ($element =~ m/^&(\w.*)/) { my $name = "DBI::ProfileSubs::$1"; # capture $1 early require DBI::ProfileSubs; my $code = do { no strict; *{$name}{CODE} }; if (defined $code) { push @Path, $code; } else { warn "$name: subroutine not found\n"; push @Path, $element; } } else { push @Path, $element; } } eval { Module::Load::load $package if $package; # silently ignores errors }; $package ||= $class; return $package->new(Path => \@Path, @args); } sub empty { # empty out profile data my $self = shift; DBI->trace_msg("profile data discarded\n",0) if $self->{Trace}; $self->{Data} = undef; } sub filename { # baseclass method, see DBI::ProfileDumper return undef; } sub flush_to_disk { # baseclass method, see DBI::ProfileDumper & DashProfiler::Core my $self = shift; return unless $ON_FLUSH_DUMP; return unless $self->{Data}; my $detail = $self->format(); $ON_FLUSH_DUMP->($detail) if $detail; } sub as_node_path_list { my ($self, $node, $path) = @_; # convert the tree into an array of arrays # from # {key1a}{key2a}[node1] # {key1a}{key2b}[node2] # {key1b}{key2a}{key3a}[node3] # to # [ [node1], 'key1a', 'key2a' ] # [ [node2], 'key1a', 'key2b' ] # [ [node3], 'key1b', 'key2a', 'key3a' ] $node ||= $self->{Data} or return; $path ||= []; if (ref $node eq 'HASH') { # recurse $path = [ @$path, undef ]; return map { $path->[-1] = $_; ($node->{$_}) ? $self->as_node_path_list($node->{$_}, $path) : () } sort keys %$node; } return [ $node, @$path ]; } sub as_text { my ($self, $args_ref) = @_; my $separator = $args_ref->{separator} || " > "; my $format_path_element = $args_ref->{format_path_element} || "%s"; # or e.g., " key%2$d='%s'" my $format = $args_ref->{format} || '%1$s: %11$fs / %10$d = %2$fs avg (first %12$fs, min %13$fs, max %14$fs)'."\n"; my @node_path_list = $self->as_node_path_list(undef, $args_ref->{path}); $args_ref->{sortsub}->(\@node_path_list) if $args_ref->{sortsub}; my $eval = "qr/".quotemeta($separator)."/"; my $separator_re = eval($eval) || quotemeta($separator); #warn "[$eval] = [$separator_re]"; my @text; my @spare_slots = (undef) x 7; for my $node_path (@node_path_list) { my ($node, @path) = @$node_path; my $idx = 0; for (@path) { s/[\r\n]+/ /g; s/$separator_re/ /g; ++$idx; if ($format_path_element eq "%s") { $_ = sprintf $format_path_element, $_; } else { $_ = sprintf $format_path_element, $_, $idx; } } push @text, sprintf $format, join($separator, @path), # 1=path ($node->[0] ? $node->[1]/$node->[0] : 0), # 2=avg @spare_slots, @$node; # 10=count, 11=dur, 12=first_dur, 13=min, 14=max, 15=first_called, 16=last_called } return @text if wantarray; return join "", @text; } sub format { my $self = shift; my $class = ref($self) || $self; my $prologue = "$class: "; my $detail = $self->format_profile_thingy( $self->{Data}, 0, " ", my $path = [], my $leaves = [], )."\n"; if (@$leaves) { dbi_profile_merge_nodes(my $totals=[], @$leaves); my ($count, $time_in_dbi, undef, undef, undef, $t1, $t2) = @$totals; (my $progname = $0) =~ s:.*/::; if ($count) { $prologue .= sprintf "%fs ", $time_in_dbi; my $perl_time = ($DBI::PERL_ENDING) ? time() - $^T : $t2-$t1; $prologue .= sprintf "%.2f%% ", $time_in_dbi/$perl_time*100 if $perl_time; my @lt = localtime(time); my $ts = sprintf "%d-%02d-%02d %02d:%02d:%02d", 1900+$lt[5], $lt[4]+1, @lt[3,2,1,0]; $prologue .= sprintf "(%d calls) $progname \@ $ts\n", $count; } if (@$leaves == 1 && ref($self->{Data}) eq 'HASH' && $self->{Data}->{DBI}) { $detail = ""; # hide the "DBI" from DBI_PROFILE=1 } } return ($prologue, $detail) if wantarray; return $prologue.$detail; } sub format_profile_leaf { my ($self, $thingy, $depth, $pad, $path, $leaves) = @_; croak "format_profile_leaf called on non-leaf ($thingy)" unless UNIVERSAL::isa($thingy,'ARRAY'); push @$leaves, $thingy if $leaves; my ($count, $total_time, $first_time, $min, $max, $first_called, $last_called) = @$thingy; return sprintf "%s%fs\n", ($pad x $depth), $total_time if $count <= 1; return sprintf "%s%fs / %d = %fs avg (first %fs, min %fs, max %fs)\n", ($pad x $depth), $total_time, $count, $count ? $total_time/$count : 0, $first_time, $min, $max; } sub format_profile_branch { my ($self, $thingy, $depth, $pad, $path, $leaves) = @_; croak "format_profile_branch called on non-branch ($thingy)" unless UNIVERSAL::isa($thingy,'HASH'); my @chunk; my @keys = sort keys %$thingy; while ( @keys ) { my $k = shift @keys; my $v = $thingy->{$k}; push @$path, $k; push @chunk, sprintf "%s'%s' =>\n%s", ($pad x $depth), $k, $self->format_profile_thingy($v, $depth+1, $pad, $path, $leaves); pop @$path; } return join "", @chunk; } sub format_profile_thingy { my ($self, $thingy, $depth, $pad, $path, $leaves) = @_; return "undef" if not defined $thingy; return $self->format_profile_leaf( $thingy, $depth, $pad, $path, $leaves) if UNIVERSAL::isa($thingy,'ARRAY'); return $self->format_profile_branch($thingy, $depth, $pad, $path, $leaves) if UNIVERSAL::isa($thingy,'HASH'); return "$thingy\n"; } sub on_destroy { my $self = shift; return unless $ON_DESTROY_DUMP; return unless $self->{Data}; my $detail = $self->format(); $ON_DESTROY_DUMP->($detail) if $detail; $self->{Data} = undef; } sub DESTROY { my $self = shift; local $@; DBI->trace_msg("profile data DESTROY\n",0) if (($self->{Trace}||0) >= 2); eval { $self->on_destroy }; if ($@) { chomp $@; my $class = ref($self) || $self; DBI->trace_msg("$class on_destroy failed: $@", 0); } } 1; PK1]{q Changes.pmnu[=head1 NAME DBI::Changes - List of significant changes to the DBI =encoding ISO8859-1 =cut =head2 Changes in DBI 1.641 - 19th March 2018 Remove dependency on Storable 2.16 introduced in DBI 1.639 thanks to Ribasushi #60 Avoid compiler warnings in Driver.xst #59 thanks to pali #59 =head2 Changes in DBI 1.640 - 28th January 2018 Fix test t/91_store_warning.t for perl 5.10.0 thanks to pali #57 Add Perl 5.10.0 and 5.8.1 specific versions to Travis testing thanks to pali #57 Add registration of mariadb_ prefix for new DBD::MariaDB driver thanks to pali #56 =head2 Changes in DBI 1.639 - 28th December 2017 Fix UTF-8 support for warn/croak calls within DBI internals, thanks to pali #53 Fix dependency on Storable for perl older than 5.8.9, thanks to H.Merijn Brand. Add DBD::Mem driver, a pure-perl in-memory driver using DBI::DBD::SqlEngine, thanks to Jens Rehsack #42 Corrected missing semicolon in example in documentation, thanks to pali #55 =head2 Changes in DBI 1.637 - 16th August 2017 Fix use of externally controlled format string (CWE-134) thanks to pali #44 This could cause a crash if, for example, a db error contained a %. https://cwe.mitre.org/data/definitions/134.html Fix extension detection for DBD::File related drivers Fix tests for perl without dot in @INC RT#120443 Fix loss of error message on parent handle, thanks to charsbar #34 Fix disappearing $_ inside callbacks, thanks to robschaber #47 Fix dependency on Storable for perl older than 5.8.9 Allow objects to be used as passwords without throwing an error, thanks to demerphq #40 Allow $sth NAME_* attributes to be set from Perl code, re #45 Added support for DBD::XMLSimple thanks to nigelhorne #38 Documentation updates: Improve examples using eval to be more correct, thanks to pali #39 Add cautionary note to prepare_cached docs re refs in %attr #46 Small POD changes (Getting Help -> Online) thanks to openstrike #33 Adds links to more module names and fix typo, thanks to oalders #43 Typo fix thanks to bor #37 =head2 Changes in DBI 1.636 - 24th April 2016 Fix compilation for threaded perl <= 5.12 broken in 1.635 RT#113955 Revert change to DBI::PurePerl DESTROY in 1.635 Change t/16destroy.t to avoid race hazard RT#113951 Output perl version and archname in t/01basics.t Add perl 5.22 and 5.22-extras to travis-ci config =head2 Changes in DBI 1.635 - 24th April 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 thanks to Ed Avis RT#106411 Added appveyor support (Travis like CI for windows) thanks to mbeijen PR#30 Corrected spelling errors in pod thanks to Gregor Herrmann RT#107838 Corrected and/or removed broken links to SQL standards thanks to David Pottage RT#111437 Corrected doc example to use dbi: instead of DBI: in DSN thanks to Michael R. Davis RT#101181 Removed/updated broken links in docs thanks to mbeijen PR#29 Clarified docs for DBI::hash($string) Removed the ancient DBI::FAQ module RT#102714 Fixed t/pod.t to require Test::Pod >= 1.41 RT#101769 This release was developed at the Perl QA Hackathon 2016 L which was made possible by the generosity of many sponsors: L FastMail, L ZipRecruiter, L ActiveState, L OpusVL, L Strato, L SureVoIP, L CV-Library, L Infinity, L Perl Careers, L MongoDB, L thinkproject!, L Dreamhost, L Perl 6, L Perl Services, L Evozon, L Booking, L Eligo, L Oetiker+Partner, L CAPSiDE, L Procura, L Constructor.io, L Robbie Bow, L Ron Savage, L Charlie Gonzalez, L Justin Cook. =head2 Changes in DBI 1.634 - 3rd August 2015 Enabled strictures on all modules (Jose Luis Perez Diez) #22 Note that this might cause new exceptions in existing code. Please take time for extra testing before deploying to production. Improved handling of row counts for compiled drivers and enable them to return larger row counts (IV type) by defining new *_iv macros. Fixed quote_identifier that was adding a trailing separator when there was only a catalog (Martin J. Evans) Removed redundant keys() call in fetchall_arrayref with hash slice (ilmari) #24 Corrected pod xref to Placeholders section (Matthew D. Fuller) Corrected pod grammar (Nick Tonkin) #25 Added support for tables('', '', '', '%') special case (Martin J. Evans) Added support for DBD prefixes with numbers (Jens Rehsack) #19 Added extra initializer for DBI::DBD::SqlEngine based DBD's (Jens Rehsack) Added Memory Leaks section to the DBI docs (Tim) Added Artistic v1 & GPL v1 LICENSE file (Jose Luis Perez Diez) #21 =head2 Changes in DBI 1.633 - 11th Jan 2015 Fixed selectrow_*ref to return undef on error in list context instead if an empty list. Changed t/42prof_data.t more informative Changed $sth->{TYPE} to be NUMERIC in DBD::File drivers as per the DBI docs. Note TYPE_NAME is now also available. [H.Merijn Brand] Fixed compilation error on bleadperl due DEFSV no longer being an lvalue [Dagfinn Ilmari Mannsker] Added docs for escaping placeholders using a backslash. Added docs for get_info(9000) indicating ability to escape placeholders. Added multi_ prefix for DBD::Multi (Dan Wright) and ad2_ prefix for DBD::AnyData2 =head2 Changes in DBI 1.632 - 9th Nov 2014 Fixed risk of memory corruption with many arguments to methods originally reported by OSCHWALD for Callbacks but may apply to other functionality in DBI method dispatch RT#86744. Fixed DBD::PurePerl to not set $sth->{Active} true by default drivers are expected to set it true as needed. Fixed DBI::DBD::SqlEngine to complain loudly when prerequite driver_prefix is not fulfilled (RT#93204) [Jens Rehsack] Fixed redundant sprintf argument warning RT#97062 [Reini Urban] Fixed security issue where DBD::File drivers would open files from folders other than specifically passed using the f_dir attribute RT#99508 [H.Merijn Brand] Changed delete $h->{$key} to work for keys with 'private_' prefix per request in RT#83156. local $h->{$key} works as before. Added security notice to DBD::Proxy and DBI::ProxyServer because they use Storable which is insecure. Thanks to ppisar@redhat.com RT#90475 Added note to AutoInactiveDestroy docs strongly recommending that it is enabled in all new code. =head2 Changes in DBI 1.631 - 20th Jan 2014 NOTE: This release changes the handle passed to Callbacks from being an 'inner' handle to being an 'outer' handle. If you have code that makes use of Callbacks, ensure that you understand what this change means and review your callback code. Fixed err_hash handling of integer err RT#92172 [Dagfinn Ilmari] Fixed use of \Q vs \E in t/70callbacks.t Changed the handle passed to Callbacks from being an 'inner' handle to being an 'outer' handle. Improved reliability of concurrent testing PR#8 [Peter Rabbitson] Changed optional dependencies to "suggest" PR#9 [Karen Etheridge] Changed to avoid mg_get in neatsvpv during global destruction PR#10 [Matt Phillips] =head2 Changes in DBI 1.630 - 28th Oct 2013 NOTE: This release enables PrintWarn by default regardless of $^W. Your applications may generate more log messages than before. Fixed err for new drh to be undef not to 0 [Martin J. Evans] Fixed RT#83132 - moved DBIstcf* constants to util export tag [Martin J. Evans] PrintWarn is now triggered by warnings recorded in methods like STORE that don't clear err RT#89015 [Tim Bunce] Changed tracing to no longer show quote and quote_identifier calls at trace level 1. Changed DBD::Gofer ping while disconnected set_err from warn to info. Clarified wording of log message when err is cleared. Changed bootstrap to use $XS_VERSION RT#89618 [Andreas Koenig] Added connect_cached.connected Callback PR#3 [David E. Wheeler] Clarified effect of refs in connect_cached attributes [David E. Wheeler] Extended ReadOnly attribute docs for when the driver cannot ensure read only [Martin J. Evans] Corrected SQL_BIGINT docs to say ODBC value is used PR#5 [ilmari] There was no DBI 1.629 release. =head2 Changes in DBI 1.628 - 22nd July 2013 Fixed missing fields on partial insert via DBI::DBD::SqlEngine engines (DBD::CSV, DBD::DBM etc.) [H.Merijn Brand, Jens Rehsack] Fixed stack corruption on callbacks RT#85562 RT#84974 [Aaron Schweiger] Fixed DBI::SQL::Nano_::Statement handling of "0" [Jens Rehsack] Fixed exit op precedence in test RT#87029 [Reni Urban] Added support for finding tables in multiple directories via new DBD::File f_dir_search attribute [H.Merijn Brand] Enable compiling by C++ RT#84285 [Kurt Jaeger] Typo fixes in pod and comment [David Steinbrunner] Change DBI's docs to refer to git not svn [H.Merijn Brand] Clarify bind_col TYPE attribute is sticky [Martin J. Evans] Fixed reference to $sth in selectall_arrayref docs RT#84873 Spelling fixes [Ville Skytt] Changed $VERSIONs to hardcoded strings [H.Merijn Brand] =head2 Changes in DBI 1.627 - 16th May 2013 Fixed VERSION regression in DBI::SQL::Nano [Tim Bunce] =head2 Changes in DBI 1.626 - 15th May 2013 Fixed pod text/link was reversed in a few cases RT#85168 [H.Merijn Brand] Handle aliasing of STORE'd attributes in DBI::DBD::SqlEngine [Jens Rehsack] Updated repository URI to git [Jens Rehsack] Fixed skip() count arg in t/48dbi_dbd_sqlengine.t [Tim Bunce] =head2 Changes in DBI 1.625 (svn r15595) 28th March 2013 Fixed heap-use-after-free during global destruction RT#75614 thanks to Reini Urban. Fixed ignoring RootClass attribute during connect() by DBI::DBD::SqlEngine reported in RT#84260 by Michael Schout =head2 Changes in DBI 1.624 (svn r15576) 22nd March 2013 Fixed Gofer for hash randomization in perl 5.17.10+ RT#84146 Clarify docs for can() re RT#83207 =head2 Changes in DBI 1.623 (svn r15547) 2nd Jan 2013 Fixed RT#64330 - ping wipes out errstr (Martin J. Evans). Fixed RT#75868 - DBD::Proxy shouldn't call connected() on the server. Fixed RT#80474 - segfault in DESTROY with threads. Fixed RT#81516 - Test failures due to hash randomisation in perl 5.17.6 thanks to Jens Rehsack and H.Merijn Brand and feedback on IRC Fixed RT#81724 - Handle copy-on-write scalars (sprout) Fixed unused variable / self-assignment compiler warnings. Fixed default table_info in DBI::DBD::SqlEngine which passed NAMES attribute instead of NAME to DBD::Sponge RT72343 (Martin J. Evans) Corrected a spelling error thanks to Chris Sanders. Corrected typo in DBI->installed_versions docs RT#78825 thanks to Jan Dubois. Refactored table meta information management from DBD::File into DBI::DBD::SqlEngine (H.Merijn Brand, Jens Rehsack) Prevent undefined f_dir being used in opendir (H.Merijn Brand) Added logic to force destruction of children before parents during global destruction. See RT#75614. Added DBD::File Plugin-Support for table names and data sources (Jens Rehsack, #dbi Team) Added new tests to 08keeperr for RT#64330 thanks to Kenichi Ishigaki. Added extra internal handle type check, RT#79952 thanks to Reini Urban. Added cubrid_ registered prefix for DBD::cubrid, RT#78453 Removed internal _not_impl method (Martin J. Evans). NOTE: The "old-style" DBD::DBM attributes 'dbm_ext' and 'dbm_lockfile' have been deprecated for several years and their use will now generate a warning. =head2 Changes in DBI 1.622 (svn r15327) 6th June 2012 Fixed lack of =encoding in non-ASCII pod docs. RT#77588 Corrected typo in DBI::ProfileDumper thanks to Finn Hakansson. =head2 Changes in DBI 1.621 (svn r15315) 21st May 2012 Fixed segmentation fault when a thread is created from within another thread RT#77137, thanks to Dave Mitchell. Updated previous Changes to credit Booking.com for sponsoring Dave Mitchell's recent DBI optimization work. =head2 Changes in DBI 1.620 (svn r15300) 25th April 2012 Modified column renaming in fetchall_arrayref, added in 1.619, to work on column index numbers not names (an incompatible change). Reworked the fetchall_arrayref documentation. Hash slices in fetchall_arrayref now detect invalid column names. =head2 Changes in DBI 1.619 (svn r15294) 23rd April 2012 Fixed the connected method to stop showing the password in trace file (Martin J. Evans). Fixed _install_method to set CvFILE correctly thanks to sprout RT#76296 Fixed SqlEngine "list_tables" thanks to David McMath and Norbert Gruener. RT#67223 RT#69260 Optimized DBI method dispatch thanks to Dave Mitchell. Optimized driver access to DBI internal state thanks to Dave Mitchell. Optimized driver access to handle data thanks to Dave Mitchell. Dave's work on these optimizations was sponsored by Booking.com. Optimized fetchall_arrayref with hash slice thanks to Dagfinn Ilmari Mannsker. RT#76520 Allow renaming columns in fetchall_arrayref hash slices thanks to Dagfinn Ilmari Mannsker. RT#76572 Reserved snmp_ and tree_ for DBD::SNMP and DBD::TreeData =head2 Changes in DBI 1.618 (svn r15170) 25rd February 2012 Fixed compiler warnings in Driver_xst.h (Martin J. Evans) Fixed compiler warning in DBI.xs (H.Merijn Brand) Fixed Gofer tests failing on Windows RT74975 (Manoj Kumar) Fixed my_ctx compile errors on Windows (Dave Mitchell) Significantly optimized method dispatch via cache (Dave Mitchell) Significantly optimized DBI internals for threads (Dave Mitchell) Dave's work on these optimizations was sponsored by Booking.com. Xsub to xsub calling optimization now enabled for threaded perls. Corrected typo in example in docs (David Precious) Added note that calling clone() without an arg may warn in future. Minor changes to the install_method() docs in DBI::DBD. Updated dbipport.h from Devel::PPPort 3.20 =head2 Changes in DBI 1.617 (svn r15107) 30th January 2012 NOTE: The officially supported minimum perl version will change from perl 5.8.1 (2003) to perl 5.8.3 (2004) in a future release. (The last change, from perl 5.6 to 5.8.1, was announced in July 2008 and implemented in DBI 1.611 in April 2010.) Fixed ParamTypes example in the pod (Martin J. Evans) Fixed the definition of ArrayTupleStatus and remove confusion over rows affected in list context of execute_array (Martin J. Evans) Fixed sql_type_cast example and typo in errors (Martin J. Evans) Fixed Gofer error handling for keeperr methods like ping (Tim Bunce) Fixed $dbh->clone({}) RT73250 (Tim Bunce) Fixed is_nested_call logic error RT73118 (Reini Urban) Enhanced performance for threaded perls (Dave Mitchell, Tim Bunce) Dave's work on this optimization was sponsored by Booking.com. Enhanced and standardized driver trace level mechanism (Tim Bunce) Removed old code that was an inneffective attempt to detect people doing DBI->{Attrib}. Clear ParamValues on bind_param param count error RT66127 (Tim Bunce) Changed DBI::ProxyServer to require DBI at compile-time RT62672 (Tim Bunce) Added pod for default_user to DBI::DBD (Martin J. Evans) Added CON, ENC and DBD trace flags and extended 09trace.t (Martin J. Evans) Added TXN trace flags and applied CON and TXN to relevant methods (Tim Bunce) Added some more fetchall_arrayref(..., $maxrows) tests (Tim Bunce) Clarified docs for fetchall_arrayref called on an inactive handle. Clarified docs for clone method (Tim Bunce) Added note to DBI::Profile about async queries (Marcel Grnauer). Reserved spatialite_ as a driver prefix for DBD::Spatialite Reserved mo_ as a driver prefix for DBD::MO Updated link to the SQL Reunion 95 docs, RT69577 (Ash Daminato) Changed links for DBI recipes. RT73286 (Martin J. Evans) =head2 Changes in DBI 1.616 (svn r14616) 30th December 2010 Fixed spurious dbi_profile lines written to the log when profiling is enabled and a trace flag, like SQL, is used. Fixed to recognize SQL::Statement errors even if instantiated with RaiseError=0 (Jens Rehsack) Fixed RT#61513 by catching attribute assignment to tied table access interface (Jens Rehsack) Fixing some misbehavior of DBD::File when running within the Gofer server. Fixed compiler warnings RT#62640 Optimized connect() to remove redundant FETCH of \%attrib values. Improved initialization phases in DBI::DBD::SqlEngine (Jens Rehsack) Added DBD::Gofer::Transport::corostream. An experimental proof-of-concept transport that enables asynchronous database calls with few code changes. It enables asynchronous use of DBI frameworks like DBIx::Class. Added additional notes on DBDs which avoid creating a statement in the do() method and the effects on error handlers (Martin J. Evans) Adding new attribute "sql_dialect" to DBI::DBD::SqlEngine to allow users control used SQL dialect (ANSI, CSV or AnyData), defaults to CSV (Jens Rehsack) Add documentation for DBI::DBD::SqlEngine attributes (Jens Rehsack) Documented dbd_st_execute return (Martin J. Evans) Fixed typo in InactiveDestroy thanks to Emmanuel Rodriguez. =head2 Changes in DBI 1.615 (svn r14438) 21st September 2010 Fixed t/51dbm_file for file/directory names with whitespaces in them RT#61445 (Jens Rehsack) Fixed compiler warnings from ignored hv_store result (Martin J. Evans) Fixed portability to VMS (Craig A. Berry) =head2 Changes in DBI 1.614 (svn r14408) 17th September 2010 Fixed bind_param () in DBI::DBD::SqlEngine (rt#61281) Fixed internals to not refer to old perl symbols that will no longer be visible in perl >5.13.3 (Andreas Koenig) Many compiled drivers are likely to need updating. Fixed issue in DBD::File when absolute filename is used as table name (Jens Rehsack) Croak manually when file after tie doesn't exists in DBD::DBM when it have to exists (Jens Rehsack) Fixed issue in DBD::File when users set individual file name for tables via f_meta compatibility interface - reported by H.Merijn Brand while working on RT#61168 (Jens Rehsack) Changed 50dbm_simple to simplify and fix problems (Martin J. Evans) Changed 50dbm_simple to skip aggregation tests when not using SQL::Statement (Jens Rehsack) Minor speed improvements in DBD::File (Jens Rehsack) Added $h->{AutoInactiveDestroy} as simpler safer form of $h->{InactiveDestroy} (David E. Wheeler) Added ability for parallel testing "prove -j4 ..." (Jens Rehsack) Added tests for delete in DBM (H.Merijn Brand) Added test for absolute filename as table to 51dbm_file (Jens Rehsack) Added two initialization phases to DBI::DBD::SqlEngine (Jens Rehsack) Added improved developers documentation for DBI::DBD::SqlEngine (Jens Rehsack) Added guides how to write DBI drivers using DBI::DBD::SqlEngine or DBD::File (Jens Rehsack) Added register_compat_map() and table_meta_attr_changed() to DBD::File::Table to support clean fix of RT#61168 (Jens Rehsack) =head2 Changes in DBI 1.613 (svn r14271) 22nd July 2010 Fixed Win32 prerequisite module from PathTools to File::Spec. Changed attribute headings and fixed references in DBI pod (Martin J. Evans) Corrected typos in DBI::FAQ and DBI::ProxyServer (Ansgar Burchardt) =head2 Changes in DBI 1.612 (svn r14254) 16th July 2010 NOTE: This is a minor release for the DBI core but a major release for DBD::File and drivers that depend on it, like DBD::DBM and DBD::CSV. This is also the first release where the bulk of the development work has been done by other people. I'd like to thank (in no particular order) Jens Rehsack, Martin J. Evans, and H.Merijn Brand for all their contributions. Fixed DBD::File's {ChopBlank} handling (it stripped \s instead of space only as documented in DBI) (H.Merijn Brand) Fixed DBD::DBM breakage with SQL::Statement (Jens Rehsack, fixes RT#56561) Fixed DBD::File file handle leak (Jens Rehsack) Fixed problems in 50dbm.t when running tests with multiple dbms (Martin J. Evans) Fixed DBD::DBM bugs found during tests (Jens Rehsack) Fixed DBD::File doesn't find files without extensions under some circumstances (Jens Rehsack, H.Merijn Brand, fixes RT#59038) Changed Makefile.PL to modernize with CONFLICTS, recommended dependencies and resources (Jens Rehsack) Changed DBI::ProfileDumper to rename any existing profile file by appending .prev, instead of overwriting it. Changed DBI::ProfileDumper::Apache to work in more configurations including vhosts using PerlOptions +Parent. Add driver_prefix method to DBI (Jens Rehsack) Added more tests to 50dbm_simple.t to prove optimizations in DBI::SQL::Nano and SQL::Statement (Jens Rehsack) Updated tests to cover optional installed SQL::Statement (Jens Rehsack) Synchronize API between SQL::Statement and DBI::SQL::Nano (Jens Rehsack) Merged some optimizations from SQL::Statement into DBI::SQL::Nano (Jens Rehsack) Added basic test for DBD::File (H.Merijn Brand, Jens Rehsack) Extract dealing with Perl SQL engines from DBD::File into DBI::DBD::SqlEngine for better subclassing of 3rd party non-db DBDs (Jens Rehsack) Updated and clarified documentation for finish method (Tim Bunce). Changes to DBD::File for better English and hopefully better explanation (Martin J. Evans) Update documentation of DBD::DBM to cover current implementation, tried to explain some things better and changes most examples to preferred style of Merijn and myself (Jens Rehsack) Added developer documentation (including a roadmap of future plans) for DBD::File =head2 Changes in DBI 1.611 (svn r13935) 29th April 2010 NOTE: minimum perl version is now 5.8.1 (as announced in DBI 1.607) Fixed selectcol_arrayref MaxRows attribute to count rows not values thanks to Vernon Lyon. Fixed DBI->trace(0, *STDERR); (H.Merijn Brand) which tried to open a file named "*main::STDERR" in perl-5.10.x Fixes in DBD::DBM for use under threads (Jens Rehsack) Changed "Issuing rollback() due to DESTROY without explicit disconnect" warning to not be issued if ReadOnly set for that dbh. Added f_lock and f_encoding support to DBD::File (H.Merijn Brand) Added ChildCallbacks => { ... } to Callbacks as a way to specify Callbacks for child handles. With tests added by David E. Wheeler. Added DBI::sql_type_cast($value, $type, $flags) to cast a string value to an SQL type. e.g. SQL_INTEGER effectively does $value += 0; Has other options plus an internal interface for drivers. Documentation changes: Small fixes in the documentation of DBD::DBM (H.Merijn Brand) Documented specification of type casting behaviour for bind_col() based on DBI::sql_type_cast() and two new bind_col attributes StrictlyTyped and DiscardString. Thanks to Martin Evans. Document fetchrow_hashref() behaviour for functions, aliases and duplicate names (H.Merijn Brand) Updated DBI::Profile and DBD::File docs to fix pod nits thanks to Frank Wiegand. Corrected typos in Gopher documentation reported by Jan Krynicky. Documented the Callbacks attribute thanks to David E. Wheeler. Corrected the Timeout examples as per rt 50621 (Martin J. Evans). Removed some internal broken links in the pod (Martin J. Evans) Added Note to column_info for drivers which do not support it (Martin J. Evans) Updated dbipport.h to Devel::PPPort 3.19 (H.Merijn Brand) =head2 Changes in DBI 1.609 (svn r12816) 8th June 2009 Fixes to DBD::File (H.Merijn Brand) added f_schema attribute table names case sensitive when quoted, insensitive when unquoted workaround a bug in SQL::Statement (temporary fix) related to the "You passed x parameters where y required" error Added ImplementorClass and Name info to the "Issuing rollback() due to DESTROY without explicit disconnect" warning to identify the handle. Applies to compiled drivers when they are recompiled. Added DBI->visit_handles($coderef) method. Added $h->visit_child_handles($coderef) method. Added docs for column_info()'s COLUMN_DEF value. Clarified docs on stickyness of data type via bind_param(). Clarified docs on stickyness of data type via bind_col(). =head2 Changes in DBI 1.608 (svn r12742) 5th May 2009 Fixes to DBD::File (H.Merijn Brand) bind_param () now honors the attribute argument added f_ext attribute File::Spec is always required. (CORE since 5.00405) Fail and set errstr on parameter count mismatch in execute () Fixed two small memory leaks when running in mod_perl one in DBI->connect and one in DBI::Gofer::Execute. Both due to "local $ENV{...};" leaking memory. Fixed DBD_ATTRIB_DELETE macro for driver authors and updated DBI::DBD docs thanks to Martin J. Evans. Fixed 64bit issues in trace messages thanks to Charles Jardine. Fixed FETCH_many() method to work with drivers that incorrectly return an empty list from $h->FETCH. Affected gofer. Added 'sqlite_' as registered prefix for DBD::SQLite. Corrected many typos in DBI docs thanks to Martin J. Evans. Improved DBI::DBD docs thanks to H.Merijn Brand. =head2 Changes in DBI 1.607 (svn r11571) 22nd July 2008 NOTE: Perl 5.8.1 is now the minimum supported version. If you need support for earlier versions send me a patch. Fixed missing import of carp in DBI::Gofer::Execute. Added note to docs about effect of execute(@empty_array). Clarified docs for ReadOnly thanks to Martin Evans. =head2 Changes in DBI 1.605 (svn r11434) 16th June 2008 Fixed broken DBIS macro with threads on big-endian machines with 64bit ints but 32bit pointers. Ticket #32309. Fixed the selectall_arrayref, selectrow_arrayref, and selectrow_array methods that get embedded into compiled drivers to use the inner sth handle when passed a $sth instead of an sql string. Drivers will need to be recompiled to pick up this change. Fixed leak in neat() for some kinds of values thanks to Rudolf Lippan. Fixed DBI::PurePerl neat() to behave more like XS neat(). Increased default $DBI::neat_maxlen from 400 to 1000. Increased timeout on tests to accommodate very slow systems. Changed behaviour of trace levels 1..4 to show less information at lower levels. Changed the format of the key used for $h->{CachedKids} (which is undocumented so you shouldn't depend on it anyway) Changed gofer error handling to avoid duplicate error text in errstr. Clarified docs re ":N" style placeholders. Improved gofer retry-on-error logic and refactored to aid subclassing. Improved gofer trace output in assorted ways. Removed the beeps "\a" from Makefile.PL warnings. Removed check for PlRPC-modules from Makefile.PL Added sorting of ParamValues reported by ShowErrorStatement thanks to to Rudolf Lippan. Added cache miss trace message to DBD::Gofer transport class. Added $drh->dbixs_revision method. Added explicit LICENSE specification (perl) to META.yaml =head2 Changes in DBI 1.604 (svn rev 10994) 24th March 2008 Fixed fetchall_arrayref with $max_rows argument broken in 1.603, thanks to Greg Sabino Mullane. Fixed a few harmless compiler warnings on cygwin. =head2 Changes in DBI 1.603 Fixed pure-perl fetchall_arrayref with $max_rows argument to not error when fetching after all rows already fetched. (Was fixed for compiled drivers back in DBI 1.31.) Thanks to Mark Overmeer. Fixed C sprintf formats and casts, fixing compiler warnings. Changed dbi_profile() to accept a hash of profiles and apply to all. Changed gofer stream transport to improve error reporting. Changed gofer test timeout to avoid spurious failures on slow systems. Added options to t/85gofer.t so it's more useful for manual testing. =head2 Changes in DBI 1.602 (svn rev 10706) 8th February 2008 Fixed potential coredump if stack reallocated while calling back into perl from XS code. Thanks to John Gardiner Myers. Fixed DBI::Util::CacheMemory->new to not clear the cache. Fixed avg in DBI::Profile as_text() thanks to Abe Ingersoll. Fixed DBD::DBM bug in push_names thanks to J M Davitt. Fixed take_imp_data for some platforms thanks to Jeffrey Klein. Fixed docs tie'ing CacheKids (ie LRU cache) thanks to Peter John Edwards. Expanded DBI::DBD docs for driver authors thanks to Martin Evans. Enhanced t/80proxy.t test script. Enhanced t/85gofer.t test script thanks to Stig. Enhanced t/10examp.t test script thanks to David Cantrell. Documented $DBI::stderr as the default value of err for internal errors. Gofer changes: track_recent now also keeps track of N most recent errors. The connect method is now also counted in stats. =head2 Changes in DBI 1.601 (svn rev 10103), 21st October 2007 Fixed t/05thrclone.t to work with Test::More >= 0.71 thanks to Jerry D. Hedden and Michael G Schwern. Fixed DBI for VMS thanks to Peter (Stig) Edwards. Added client-side caching to DBD::Gofer. Can use any cache with get($k)/set($k,$v) methods, including all the Cache and Cache::Cache distribution modules plus Cache::Memcached, Cache::FastMmap etc. 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), 23rd August 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), 25th June 2007 Fixed code triggering fatal error in bleadperl, thanks to Steve Hay. Fixed compiler warning thanks to Jerry D. Hedden. Fixed t/40profile.t to use int(dbi_time()) for systems like Cygwin where time() seems to be rounded not truncated from the high resolution time. Removed dump_results() test from t/80proxy.t. =head2 Changes in DBI 1.57 (svn rev 9639), 13th June 2007 Note: this release includes a change to the DBI::hash() function which will now produce different values than before *if* your perl was built with 64-bit 'int' type (i.e. "perl -V:intsize" says intsize='8'). It's relatively rare for perl to be configured that way, even on 64-bit systems. Fixed XS versions of select*_*() methods to call execute() fetch() etc., with inner handle instead of outer. Fixed execute_for_fetch() to not cache errstr values thanks to Bart Degryse. Fixed unused var compiler warning thanks to JDHEDDEN. Fixed t/86gofer_fail tests to be less likely to fail falsely. Changed DBI::hash to return 'I32' type instead of 'int' so results are portable/consistent regardless of size of the int type. Corrected timeout example in docs thanks to Egmont Koblinger. Changed t/01basic.t to warn instead of failing when it detects a problem with Math::BigInt (some recent versions had problems). Added support for !Time and !Time~N to DBI::Profile Path. See docs. Added extra trace info to connect_cached thanks to Walery Studennikov. Added non-random (deterministic) mode to DBI_GOFER_RANDOM mechanism. Added DBIXS_REVISION macro that drivers can use. Added more docs for private_attribute_info() method. DBI::Profile changes: dbi_profile() now returns ref to relevant leaf node. Don't profile DESTROY during global destruction. Added as_node_path_list() and as_text() methods. DBI::ProfileDumper changes: Don't write file if there's no profile data. Uses full natural precision when saving data (was using %.6f) Optimized flush_to_disk(). Locks the data file while writing. Enabled filename to be a code ref for dynamic names. DBI::ProfileDumper::Apache changes: Added Quiet=>1 to avoid write to STDERR in flush_to_disk(). Added Dir=>... to specify a writable destination directory. Enabled DBI_PROFILE_APACHE_LOG_DIR for mod_perl 1 as well as 2. Added parent pid to default data file name. DBI::ProfileData changes: Added DeleteFiles option to rename & delete files once read. Locks the data files while reading. Added ability to sort by Path elements. dbiprof changes: Added --dumpnodes and --delete options. Added/updated docs for both DBI::ProfileDumper && ::Apache. =head2 Changes in DBI 1.56 (svn rev 9660), 18th June 2007 Fixed printf arg warnings thanks to JDHEDDEN. Fixed returning driver-private sth attributes via gofer. Changed pod docs docs to use =head3 instead of =item so now in html you get links to individual methods etc. Changed default gofer retry_limit from 2 to 0. Changed tests to workaround Math::BigInt broken versions. Changed dbi_profile_merge() to dbi_profile_merge_nodes() old name still works as an alias for the new one. Removed old DBI internal sanity check that's no longer valid causing "panic: DESTROY (dbih_clearcom)" when tracing enabled Added DBI_GOFER_RANDOM env var that can be use to trigger random failures and delays when executing gofer requests. Designed to help test automatic retry on failures and timeout handling. Added lots more docs to all the DBD::Gofer and DBI::Gofer classes. =head2 Changes in DBI 1.55 (svn rev 9504), 4th May 2007 Fixed set_err() so HandleSetErr hook is executed reliably, if set. Fixed accuracy of profiling when perl configured to use long doubles. Fixed 42prof_data.t on fast systems with poor timers thanks to Malcolm Nooning. Fixed potential corruption in selectall_arrayref and selectrow_arrayref for compiled drivers, thanks to Rob Davies. Rebuild your compiled drivers after installing DBI. Changed some handle creation code from perl to C code, to reduce handle creation cost by ~20%. Changed internal implementation of the CachedKids attribute so it's a normal handle attribute (and initially undef). Changed connect_cached and prepare_cached to avoid a FETCH method call, and thereby reduced cost by ~5% and ~30% respectively. Changed _set_fbav to not croak when given a wrongly sized array, it now warns and adjusts the row buffer to match. Changed some internals to improve performance with threaded perls. Changed DBD::NullP to be slightly more useful for testing. Changed File::Spec prerequisite to not require a minimum version. Changed tests to work with other DBMs thanks to ZMAN. Changed ex/perl_dbi_nulls_test.pl to be more descriptive. Added more functionality to the (undocumented) Callback mechanism. Callbacks can now elect to provide a value to be returned, in which case the method won't be called. A callback for "*" is applied to all methods that don't have their own callback. Added $h->{ReadOnly} attribute. Added support for DBI Profile Path to contain refs to scalars which will be de-ref'd for each profile sample. Added dbilogstrip utility to edit DBI logs for diff'ing (gets installed) Added details for SQLite 3.3 to NULL handling docs thanks to Alex Teslik. Added take_imp_data() to DBI::PurePerl. Gofer related changes: Fixed gofer pipeone & stream transports to avoid risk of hanging. Improved error handling and tracing significantly. Added way to generate random 1-in-N failures for methods. Added automatic retry-on-error mechanism to gofer transport base class. Added tests to show automatic retry mechanism works a treat! Added go_retry_hook callback hook so apps can fine-tune retry behaviour. Added header to request and response packets for sanity checking and to enable version skew between client and server. Added forced_single_resultset, max_cached_sth_per_dbh and max_cached_dbh_per_drh to gofer executor config. Driver-private methods installed with install_method are now proxied. No longer does a round-trip to the server for methods it knows have not been overridden by the remote driver. Most significant aspects of gofer behaviour are controlled by policy mechanism. Added policy-controlled caching of results for some methods, such as schema metadata. The connect_cached and prepare_cached methods cache on client and server. The bind_param_array and execute_array methods are now supported. Worked around a DBD::Sybase bind_param bug (which is fixed in DBD::Sybase 1.07) Added goferperf.pl utility (doesn't get installed). Many other assorted Gofer related bug fixes, enhancements and docs. The http and mod_perl transports have been remove to their own distribution. Client and server will need upgrading together for this release. =head2 Changes in DBI 1.54 (svn rev 9157), 23rd February 2007 NOTE: This release includes the 'next big thing': DBD::Gofer. Take a look! WARNING: This version has some subtle changes in DBI internals. It's possible, though doubtful, that some may affect your code. I recommend some extra testing before using this release. Or perhaps I'm just being over cautious... Fixed type_info when called for multiple dbh thanks to Cosimo Streppone. Fixed compile warnings in bleadperl on freebsd-6.1-release and solaris 10g thanks to Philip M. Gollucci. Fixed to compile for perl built with -DNO_MATHOMS thanks to Jerry D. Hedden. Fixed to work for bleadperl (r29544) thanks to Nicholas Clark. Users of Perl >= 5.9.5 will require DBI >= 1.54. Fixed rare error when profiling access to $DBI::err etc tied variables. Fixed DBI::ProfileDumper to not be affected by changes to $/ and $, thanks to Michael Schwern. Changed t/40profile.t to skip tests for perl < 5.8.0. Changed setting trace file to no longer write "Trace file set" to new file. Changed 'handle cleared whilst still active' warning for dbh to only be given for dbh that have active sth or are not AutoCommit. Changed take_imp_data to call finish on all Active child sth. Changed DBI::PurePerl trace() method to be more consistent. Changed set_err method to effectively not append to errstr if the new errstr is the same as the current one. Changed handle factory methods, like connect, prepare, and table_info, to copy any error/warn/info state of the handle being returned up into the handle the method was called on. Changed row buffer handling to not alter NUM_OF_FIELDS if it's inconsistent with number of elements in row buffer array. Updated DBI::DBD docs re handling multiple result sets. Updated DBI::DBD docs for driver authors thanks to Ammon Riley and Dean Arnold. Updated column_info docs to note that if a table doesn't exist you get an sth for an empty result set and not an error. Added new DBD::Gofer 'stateless proxy' driver and framework, and the DBI test suite is now also executed via DBD::Gofer, 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), 31st October 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. Added array context support to execute_array and execute_for_fetch methods which returns executed tuples and rows affected. Added Tie::Cache::LRU example to docs thanks to Brandon Black. =head2 Changes in DBI 1.52 (svn rev 6840), 30th July 2006 Fixed memory leak (per handle) thanks to Nicholas Clark and Ephraim Dan. Fixed memory leak (16 bytes per sth) thanks to Doru Theodor Petrescu. Fixed execute_for_fetch/execute_array to RaiseError thanks to Martin J. Evans. Fixed for perl 5.9.4. Users of Perl >= 5.9.4 will require DBI >= 1.52. Updated DBD::File to 0.35 to match the latest release on CPAN. Added $dbh->statistics_info specification thanks to Brandon Black. Many changes and additions to profiling: Profile Path can now uses sane strings instead of obscure numbers, 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), 6th June 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. Improved performance for thread-enabled perls thanks to Gisle Aas. Drivers can now use PERL_NO_GET_CONTEXT thanks to Gisle Aas. Driver authors please read the notes in the DBI::DBD docs. Changed DBI::Profile format to always include a percentage, if not exiting then uses time between the first and last DBI call. Changed DBI::ProfileData to be more forgiving of systems with unstable clocks (where time may go backwards occasionally). Clarified the 'Subclassing the DBI' docs. Assorted minor changes to docs from comments on annocpan.org. Changed Makefile.PL to avoid incompatible options for old gcc. Added 'fetch array of hash refs' example to selectall_arrayref docs thanks to Tom Schindl. Added docs for $sth->{ParamArrays} thanks to Martin J. Evans. Added reference to $DBI::neat_maxlen in TRACING section of docs. Added ability for DBI::Profile Path to include attributes and a summary of where the code was called from. =head2 Changes in DBI 1.50 (svn rev 2307), 13 December 2005 Fixed Makefile.PL options for gcc bug introduced in 1.49. Fixed handle magic order to keep DBD::Oracle happy. Fixed selectrow_array to return empty list on error. Changed dbi_profile_merge() to be able to recurse and merge sub-trees of profile data. Added documentation for dbi_profile_merge(), including how to measure the time spent inside the DBI for an http request. =head2 Changes in DBI 1.49 (svn rev 2287), 29th November 2005 Fixed assorted attribute handling bugs in DBD::Proxy. Fixed croak() in DBD::NullP thanks to Sergey Skvortsov. Fixed handling of take_imp_data() and dbi_imp_data attribute. Fixed bugs in DBD::DBM thanks to Jeff Zucker. Fixed bug in DBI::ProfileDumper thanks to Sam Tregar. Fixed ping in DBD::Proxy thanks to George Campbell. Fixed dangling ref in $sth after parent $dbh destroyed with thanks to il@rol.ru for the bug report #13151 Fixed prerequisites to include Storable thanks to Michael Schwern. Fixed take_imp_data to be more practical. Change to require perl 5.6.1 (as advertised in 2003) not 5.6.0. Changed internals to be more strictly coded thanks to Andy Lester. Changed warning about multiple copies of Driver.xst found in @INC to ignore duplicated directories thanks to Ed Avis. Changed Driver.xst to enable drivers to define an dbd_st_prepare_sv function where the statement parameter is an SV. That enables compiled drivers to support SQL strings that are UTF-8. Changed "use DBI" to only set $DBI::connect_via if not already set. Changed docs to clarify pre-method clearing of err values. Added ability for DBI::ProfileData to edit profile path on loading. This enables aggregation of different SQL statements into the same profile node - very handy when not using placeholders or when working multiple separate tables for the same thing (ie logtable_2005_11_28) Added $sth->{ParamTypes} specification thanks to Dean Arnold. Added $h->{Callbacks} attribute to enable code hooks to be invoked when certain methods are called. For example: $dbh->{Callbacks}->{prepare} = sub { ... }; With thanks to David Wheeler for the kick start. Added $h->{ChildHandles} (using weakrefs) thanks to Sam Tregar I've recoded it in C so there's no significant performance impact. Added $h->{Type} docs (returns 'dr', 'db', or 'st') Adding trace message in DESTROY if InactiveDestroy enabled. Added %drhs = DBI->installed_drivers(); Ported DBI::ProfileDumper::Apache to mod_perl2 RC5+ thanks to Philip M. Golluci =head2 Changes in DBI 1.48 (svn rev 928), 14th March 2005 Fixed DBI::DBD::Metadata generation of type_info_all thanks to Steffen Goeldner (driver authors who have used it should rerun it). Updated docs for NULL Value placeholders thanks to Brian Campbell. Added multi-keyfield nested hash fetching to fetchall_hashref() thanks to Zhuang (John) Li for polishing up my draft. Added registered driver prefixes: amzn_ for DBD::Amazon and yaswi_ for DBD::Yaswi. =head2 Changes in DBI 1.47 (svn rev 854), 2nd February 2005 Fixed DBI::ProxyServer to not create pid files by default. References: Ubuntu Security Notice USN-70-1, CAN-2005-0077 Thanks to Javier Fernndez-Sanguino Pea from the Debian Security Audit Project, and Jonathan Leffler. Fixed some tests to work with older Test::More versions. Fixed setting $DBI::err/errstr in DBI::PurePerl. Fixed potential undef warning from connect_cached(). Fixed $DBI::lasth handling for DESTROY so lasth points to parent even if DESTROY called other methods. Fixed DBD::Proxy method calls to not alter $@. Fixed DBD::File problem with encoding pragma thanks to Erik Rijkers. Changed error handling so undef errstr doesn't cause warning. Changed DBI::DBD docs to use =head3/=head4 pod thanks to Jonathan Leffler. This may generate warnings for perl 5.6. 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. Added $GetInfoType{SQL_DATABASE_NAME} thanks to Steffen Goeldner. Updated docs to recommend some common DSN string attributes. Updated connect_cached() docs with issues and suggestions. Updated docs for NULL Value placeholders thanks to Brian Campbell. Updated docs for primary_key_info and primary_keys. Updated docs to clarify that the default fetchrow_hashref behaviour, of returning a ref to a new hash for each row, will not change. 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. Added DBD::JDBC as a registered driver. =head2 Changes in DBI 1.46 (svn rev 584), 16th November 2004 Fixed parsing bugs in DBI::SQL::Nano thanks to Jeff Zucker. Fixed a couple of bad links in docs thanks to Graham Barr. Fixed test.pl Win32 undef warning thanks to H.Merijn Brand & David Repko. Fixed minor issues in DBI::DBD::Metadata thanks to Steffen Goeldner. Fixed DBI::PurePerl neat() to use double quotes for utf8. Changed execute_array() definition, and default implementation, to not consider scalar values for execute tuple count. See docs. Changed DBD::File to enable ShowErrorStatement by default, which affects DBD::File subclasses such as DBD::CSV and DBD::DBM. Changed use DBI qw(:utils) tag to include $neat_maxlen. Updated Roadmap and ToDo. Added data_string_diff() data_string_desc() and data_diff() utility functions to help diagnose Unicode issues. All can be imported via the use DBI qw(:utils) tag. =head2 Changes in DBI 1.45 (svn rev 480), 6th October 2004 Fixed DBI::DBD code for drivers broken in 1.44. Fixed "Free to wrong pool"/"Attempt to free unreferenced scalar" in FETCH. =head2 Changes in DBI 1.44 (svn rev 478), 5th October 2004 Fixed build issues on VMS thanks to Jakob Snoer. Fixed DBD::File finish() method to return 1 thanks to Jan Dubois. Fixed rare core dump during global destruction thanks to Mark Jason Dominus. Fixed risk of utf8 flag persisting from one row to the next. Changed bind_param_array() so it doesn't require all bind arrays to have the same number of elements. Changed bind_param_array() to error if placeholder number <= 0. Changed execute_array() definition, and default implementation, to effectively NULL-pad shorter bind arrays. Changed execute_array() to return "0E0" for 0 as per the docs. Changed execute_for_fetch() definition, and default implementation, to return "0E0" for 0 like execute() and execute_array(). Changed Test::More prerequisite to Test::Simple (which is also the name of the distribution both are packaged in) to work around ppm behaviour. Corrected docs to say that get/set of unknown attribute generates a warning and is no longer fatal. Thanks to Vadim. Corrected fetchall_arrayref() docs example thanks to Drew Broadley. Added $h1->swap_inner_handle($h2) sponsored by BizRate.com =head2 Changes in DBI 1.43 (svn rev 377), 2nd July 2004 Fixed connect() and connect_cached() RaiseError/PrintError which would sometimes show "(no error string)" as the error. Fixed compiler warning thanks to Paul Marquess. Fixed "trace level set to" trace message thanks to H.Merijn Brand. Fixed DBD::DBM $dbh->{dbm_tables}->{...} to be keyed by the table name not the file name thanks to Jeff Zucker. Fixed last_insert_id(...) thanks to Rudy Lippan. Fixed propagation of scalar/list context into proxied methods. Fixed DBI::Profile::DESTROY to not alter $@. Fixed DBI::ProfileDumper new() docs thanks to Michael Schwern. Fixed _load_class to propagate $@ thanks to Drew Taylor. Fixed compile warnings on Win32 thanks to Robert Baron. Fixed problem building with recent versions of MakeMaker. Fixed DBD::Sponge not to generate warning with threads. Fixed DBI_AUTOPROXY to work more than once thanks to Steven Hirsch. Changed TraceLevel 1 to not show recursive/nested calls. Changed getting or setting an invalid attribute to no longer be a fatal error but generate a warning instead. Changed selectall_arrayref() to call finish() if $attr->{MaxRows} is defined. Changed all tests to use Test::More and enhanced the tests thanks to Stevan Little and Andy Lester. See http://qa.perl.org/phalanx/ Changed Test::More minimum prerequisite version to 0.40 (2001). Changed DBI::Profile header to include the date and time. Added DBI->parse_dsn($dsn) method. Added warning if build directory path contains white space. Added docs for parse_trace_flags() and parse_trace_flag(). Removed "may change" warnings from the docs for table_info(), primary_key_info(), and foreign_key_info() methods. =head2 Changes in DBI 1.42 (svn rev 222), 12th March 2004 Fixed $sth->{NUM_OF_FIELDS} of non-executed statement handle to be undef as per the docs (it was 0). Fixed t/41prof_dump.t to work with perl5.9.1. Fixed DBD_ATTRIB_DELETE macro thanks to Marco Paskamp. Fixed DBI::PurePerl looks_like_number() and $DBI::rows. Fixed ref($h)->can("foo") to not croak. Changed attributes (NAME, TYPE etc) of non-executed statement handle to be undef instead of triggering an error. Changed ShowErrorStatement to apply to more $dbh methods. Changed DBI_TRACE env var so just does this at load time: DBI->trace(split '=', $ENV{DBI_TRACE}, 2); Improved "invalid number of parameters" error message. Added DBI::common as base class for DBI::db, DBD::st etc. Moved methods common to all handles into DBI::common. Major tracing enhancement: Added $h->parse_trace_flags("foo|SQL|7") to map a group of trace flags into the corresponding trace flag bits. Added automatic calling of parse_trace_flags() if setting the trace level to a non-numeric value: $h->{TraceLevel}="foo|SQL|7"; $h->trace("foo|SQL|7"); DBI->connect("dbi:Driver(TraceLevel=SQL|foo):...", ...); Currently no trace flags have been defined. Added to, and reworked, the trace documentation. Added dbivport.h for driver authors to use. Major driver additions that Jeff Zucker and I have been working on: Added DBI::SQL::Nano a 'smaller than micro' SQL parser with an SQL::Statement compatible API. If SQL::Statement is installed then DBI::SQL::Nano becomes an empty subclass of SQL::Statement, unless the DBI_SQL_NANO env var is true. Added DBD::File, modified to use DBI::SQL::Nano. Added DBD::DBM, an SQL interface to DBM files using DBD::File. Documentation changes: Corrected typos in docs thanks to Steffen Goeldner. Corrected execute_for_fetch example thanks to Dean Arnold. =head2 Changes in DBI 1.41 (svn rev 130), 22nd February 2004 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 any of the execute() calls fail. Fixed take_imp_data() test on m68k reported by Christian Hammers. Fixed write_typeinfo_pm inconsistencies in DBI::DBD::Metadata thanks to Andy Hassall. Fixed $h->{TraceLevel} to not return DBI->trace trace level which it used to if DBI->trace trace level was higher. Changed set_err() to append to errstr, with a leading "\n" if it's not empty, so that multiple error/warning messages are recorded. Changed trace to limit elements dumped when an array reference is returned from a method to the max(40, $DBI::neat_maxlen/10) so that fetchall_arrayref(), for example, doesn't flood the trace. Changed trace level to be a four bit integer (levels 0 thru 15) and a set of topic flags (no topics have been assigned yet). Changed column_info() to check argument count. Extended bind_param() TYPE attribute specification to imply standard formating of value, eg SQL_DATE implies 'YYYY-MM-DD'. Added way for drivers to indicate 'success with info' or 'warning' by setting err to "0" for warning and "" for information. Both values are false and so don't trigger RaiseError etc. Thanks to Steffen Goeldner for the original idea. Added $h->{HandleSetErr} = sub { ... } to be called at the point that an error, warn, or info state is recorded. The code can alter the err, errstr, and state values (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 \%attr parameter to foreign_key_info() method. 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. Added TYPE attribute to bind_col and specified the expected driver behaviour. Major update to signal handling docs thanks to Lincoln Baxter. 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 Fixed handling of CachedKids when DESTROYing threaded handles. Fixed sql_user_name() in DBI::DBD::Metadata (used by write_getinfo_pm) to use $dbh->{Username}. Driver authors please update your code. Changed connect_cached() when running under Apache::DBI to route calls to Apache::DBI::connect(). Added CLONE() to DBD::Sponge and DBD::ExampleP. Added warning when starting a new thread about any loaded driver which does not have a CLONE() function. Added new prepare_cache($sql, \%attr, 3) option to manage Active handles. Added SCALE and NULLABLE support to DBD::Sponge. Added missing execute() in fetchall_hashref docs thanks to Iain Truskett. Added a CONTRIBUTING section to the docs with notes on creating patches. =head2 Changes in DBI 1.39, 27th November 2003 Fixed STORE to not clear error during nested DBI call, again/better, thanks to Tony Bowden for the report and helpful test case. Fixed DBI dispatch to not try to use AUTOLOAD for driver methods unless the method has been declared (as methods should be when using AUTOLOAD). This fixes a problem when the Attribute::Handlers module is loaded. Fixed cwd check code to use $Config{path_sep} thanks to Steve Hay. Fixed unqualified croak() calls thanks to Steffen Goeldner. Fixed DBD::ExampleP TYPE and PRECISION attributes thanks to Tom Lowery. Fixed tracing of methods that only get traced at high trace levels. The level 1 trace no longer includes nested method calls so it generally just shows the methods the application explicitly calls. Added line to trace log (level>=4) when err/errstr is cleared. Updated docs for InactiveDestroy and point out where and when the trace includes the process id. Update DBI::DBD docs thanks to Steffen Goeldner. Removed docs saying that the DBI->data_sources method could be passed a $dbh. The $dbh->data_sources method should be used instead. Added link to 'DBI recipes' thanks to Giuseppe Maxia: http://gmax.oltrelinux.com/dbirecipes.html (note that this is not an endorsement that the recipies are 'optimal') Note: There is a bug in perl 5.8.2 when configured with threads and debugging enabled (bug #24463) which causes a DBI test to fail. =head2 Changes in DBI 1.38, 21th August 2003 NOTE: The DBI now requires perl version 5.6.0 or later. (As per notice in DBI 1.33 released 27th February 2003) Fixed spurious t/03handles failure on 64bit perls reported by H.Merijn Brand. Fixed spurious t/15array failure on some perl versions thanks to Ed Avis. Fixed build using dmake on windows thanks to Steffen Goeldner. Fixed build on using some shells thanks to Gurusamy Sarathy. Fixed ParamValues to only be appended to ShowErrorStatement if not empty. Fixed $dbh->{Statement} not being writable by drivers in some cases. Fixed occasional undef warnings on connect failures thanks to Ed Avis. Fixed small memory leak when using $sth->{NAME..._hash}. Fixed 64bit warnings thanks to Marian Jancar. Fixed DBD::Proxy::db::DESTROY to not alter $@ thanks to Keith Chapman. Fixed Makefile.PL status from WriteMakefile() thanks to Leon Brocard. Changed "Can't set ...->{Foo}: unrecognised attribute" from an error to a warning when running with DBI::ProxyServer to simplify upgrades. Changed execute_array() to no longer require ArrayTupleStatus attribute. Changed DBI->available_drivers to not hide DBD::Sponge. Updated/moved placeholder docs to a better place thanks to Johan Vromans. Changed dbd_db_do4 api in Driver.xst to match dbd_st_execute (return int, not bool), relevant only to driver authors. Changed neat(), and thus trace(), so strings marked as utf8 are presented in double quotes instead of single quotes and are not sanitized. Added $dbh->data_sources method. Added $dbh->last_insert_id method. Added $sth->execute_for_fetch($fetch_tuple_sub, \@tuple_status) method. Added DBI->installed_versions thanks to Jeff Zucker. Added $DBI::Profile::ON_DESTROY_DUMP variable. Added docs for DBD::Sponge thanks to Mark Stosberg. =head2 Changes in DBI 1.37, 15th May 2003 Fixed "Can't get dbh->{Statement}: unrecognised attribute" error in test caused by change to perl internals in 5.8.0 Fixed to build with latest development perl (5.8.1@19525). Fixed C code to use all ANSI declarations thanks to Steven Lembark. =head2 Changes in DBI 1.36, 11th May 2003 Fixed DBI->connect to carp instead of croak on 'old-style' usage. Fixed connect(,,, { RootClass => $foo }) to not croak if module not found. Fixed code generated by DBI::DBD::Metadata thanks to DARREN@cpan.org (#2270) Fixed DBI::PurePerl to not reset $@ during method dispatch. Fixed VMS build thanks to Michael Schwern. Fixed Proxy disconnect thanks to Steven Hirsch. Fixed error in DBI::DBD docs thanks to Andy Hassall. Changed t/40profile.t to not require Time::HiRes. Changed DBI::ProxyServer to load DBI only on first request, which helps threaded server mode, thanks to Bob Showalter. Changed execute_array() return value from row count to executed tuple count, and now the ArrayTupleStatus attribute is mandatory. NOTE: That is an API definition change that may affect your code. Changed CompatMode attribute to also disable attribute 'quick FETCH'. Changed attribute FETCH to be slightly faster thanks to Stas Bekman. Added workaround for perl bug #17575 tied hash nested FETCH thanks to Silvio Wanka. Added Username and Password attributes to connect(..., \%attr) and so also embedded in DSN like "dbi:Driver(Username=user,Password=pass):..." Username and Password can't contain ")", ",", or "=" characters. The predence is DSN first, then \%attr, then $user & $pass parameters, and finally the DBI_USER & DBI_PASS environment variables. The Username attribute is stored in the $dbh but the Password is not. Added ProxyServer HOWTO configure restrictions docs thanks to Jochen Wiedmann. Added MaxRows attribute to selectcol_arrayref prompted by Wojciech Pietron. Added dump_handle as a method not just a DBI:: utility function. Added on-demand by-row data feed into execute_array() using code ref, or statement handle. For example, to insert from a select: $insert_sth->execute_array( { ArrayTupleFetch => $select_sth, ... } ) Added warning to trace log when $h->{foo}=... is ignored due to invalid prefix (e.g., not 'private_'). =head2 Changes in DBI 1.35, 7th March 2003 Fixed memory leak in fetchrow_hashref introduced in DBI 1.33. Fixed various DBD::Proxy errors introduced in DBI 1.33. Fixed to ANSI C in dbd_dr_data_sources thanks to Jonathan Leffler. Fixed $h->can($method_name) to return correct code ref. Removed DBI::Format from distribution as it's now part of the separate DBI::Shell distribution by Tom Lowery. Updated DBI::DBD docs with a note about the CLONE method. Updated DBI::DBD docs thanks to Jonathan Leffler. Updated DBI::DBD::Metadata for perl 5.5.3 thanks to Jonathan Leffler. Added note to install_method docs about setup_driver() method. =head2 Changes in DBI 1.34, 28th February 2003 Fixed DBI::DBD docs to refer to DBI::DBD::Metadata thanks to Jonathan Leffler. Fixed dbi_time() compile using BorlandC on Windows thanks to Steffen Goeldner. Fixed profile tests to do enough work to measure on Windows. Fixed disconnect_all() to not be required by drivers. Added $okay = $h->can($method_name) to check if a method exists. Added DBD::*::*->install_method($method_name, \%attr) so driver private methods can be 'installed' into the DBI dispatcher and no longer need to be called using $h->func(..., $method_name). Enhanced $dbh->clone() and documentation. Enhanced docs to note that dbi_time(), and thus profiling, is limited to only millisecond (seconds/1000) resolution on Windows. Removed old DBI::Shell from distribution and added Tom Lowery's improved version to the Bundle::DBI file. Updated minimum version numbers for modules in Bundle::DBI. =head2 Changes in DBI 1.33, 27th February 2003 NOTE: Future versions of the DBI *will not* support perl 5.6.0 or earlier. : Perl 5.6.1 will be the minimum supported version. NOTE: The "old-style" connect: DBI->connect($database, $user, $pass, $driver); : has been deprecated for several years and will now generate a warning. : It will be removed in a later release. Please change any old connect() calls. Added $dbh2 = $dbh1->clone to make a new connection to the database that is identical to the original one. clone() can be called even after the original handle has been disconnected. See the docs for more details. Fixed merging of profile data to not sum DBIprof_FIRST_TIME values. Fixed unescaping of newlines in DBI::ProfileData thanks to Sam Tregar. Fixed Taint bug with fetchrow_hashref with help from Bradley Baetz. Fixed $dbh->{Active} for DBD::Proxy, reported by Bob Showalter. Fixed STORE to not clear error during nested DBI call, thanks to Tony Bowden for the report and helpful test case. Fixed DBI::PurePerl error clearing behaviour. Fixed dbi_time() and thus DBI::Profile on Windows thanks to Smejkal Petr. Fixed problem that meant ShowErrorStatement could show wrong statement, thanks to Ron Savage for the report and test case. Changed Apache::DBI hook to check for $ENV{MOD_PERL} instead of $ENV{GATEWAY_INTERFACE} thanks to Ask Bjoern Hansen. No longer tries to dup trace logfp when an interpreter is being cloned. Database handles no longer inherit shared $h->err/errstr/state storage from their drivers, so each $dbh has it's own $h->err etc. values and is no longer affected by calls made on other dbh's. Now when a dbh is destroyed it's err/errstr/state values are copied up to the driver so checking $DBI::errstr still works as expected. Build / portability fixes: Fixed t/40profile.t to not use Time::HiRes. Fixed t/06attrs.t to not be locale sensitive, reported by Christian Hammers. Fixed sgi compiler warnings, reported by Paul Blake. Fixed build using make -j4, reported by Jonathan Leffler. Fixed build and tests under VMS thanks to Craig A. Berry. Documentation changes: Documented $high_resolution_time = dbi_time() function. Documented that bind_col() can take an attribute hash. Clarified documentation for ParamValues attribute hash keys. Many good DBI documentation tweaks from Jonathan Leffler, including a major update to the DBI::DBD driver author guide. Clarified that execute() should itself call finish() if it's called on a statement handle that's still active. Clarified $sth->{ParamValues}. Driver authors please note. Removed "NEW" markers on some methods and attributes and added text to each giving the DBI version it was added in, if it was added after DBI 1.21 (Feb 2002). Changes of note for authors of all drivers: Added SQL_DATA_TYPE, SQL_DATETIME_SUB, NUM_PREC_RADIX, and INTERVAL_PRECISION fields to docs for type_info_all. There were already in type_info(), but type_info_all() didn't specify the index values. Please check and update your type_info_all() code. Added DBI::DBD::Metadata module that auto-generates your drivers get_info and type_info_all data and code, thanks mainly to Jonathan Leffler and Steffen Goeldner. If you've not implemented get_info and type_info_all methods and your database has an ODBC driver available then this will do all the hard work for you! Drivers should no longer pass Err, Errstr, or State to _new_drh or _new_dbh functions. Please check that you support the slightly modified behaviour of $sth->{ParamValues}, e.g., always return hash with keys if possible. Changes of note for authors of compiled drivers: Added dbd_db_login6 & dbd_st_finish3 prototypes thanks to Jonathan Leffler. All dbd_*_*() functions implemented by drivers must have a corresponding #define dbd_*_* _*_* otherwise the driver may not work with a future release of the DBI. Changes of note for authors of drivers which use Driver.xst: Some new method hooks have been added are are enabled by defining corresponding macros: $drh->data_sources() - dbd_dr_data_sources $dbh->do() - dbd_db_do4 The following methods won't be compiled into the driver unless the corresponding macro has been #defined: $drh->disconnect_all() - dbd_discon_all =head2 Changes in DBI 1.32, 1st December 2002 Fixed to work with 5.005_03 thanks to Tatsuhiko Miyagawa (I've not tested it). Reenabled taint tests (accidentally left disabled) spotted by Bradley Baetz. Improved docs for FetchHashKeyName attribute thanks to Ian Barwick. Fixed core dump if fetchrow_hashref given bad argument (name of attribute with a value that wasn't an array reference), spotted by Ian Barwick. Fixed some compiler warnings thanks to David Wheeler. Updated Steven Hirsch's enhanced proxy work (seems I left out a bit). Made t/40profile.t tests more reliable, reported by Randy, who is part of the excellent CPAN testers team: http://testers.cpan.org/ (Please visit, see the valuable work they do and, ideally, join in!) =head2 Changes in DBI 1.31, 29th November 2002 The fetchall_arrayref method, when called with a $maxrows parameter, no longer gives an error if called again after all rows have been fetched. This simplifies application logic when fetching in batches. Also added batch-fetch while() loop example to the docs. The proxy now supports non-lazy (synchronous) prepare, positioned updates (for selects containing 'for update'), PlRPC config set via attributes, and accurate propagation of errors, all thanks to Steven Hirsch (plus a minor fix from Sean McMurray and doc tweaks from Michael A Chase). The DBI_AUTOPROXY env var can now hold the full dsn of the proxy driver plus attributes, like "dbi:Proxy(proxy_foo=>1):host=...". Added TaintIn & TaintOut attributes to give finer control over tainting thanks to Bradley Baetz. The RootClass attribute no longer ignores failure to load a module, but also doesn't try to load a module if the class already exists, with thanks to James FitzGibbon. HandleError attribute works for connect failures thanks to David Wheeler. The connect() RaiseError/PrintError message now includes the username. Changed "last handle unknown or destroyed" warning to be a trace message. Removed undocumented $h->event() method. Further enhancements to DBD::PurePerl accuracy. The CursorName attribute now defaults to undef and not an error. DBI::Profile changes: New DBI::ProfileDumper, DBI::ProfileDumper::Apache, and DBI::ProfileData modules (to manage the storage and processing of profile data), plus dbiprof program for analyzing profile data - with many thanks to Sam Tregar. Added $DBI::err (etc) tied variable lookup time to profile. Added time for DESTROY method into parent handles profile (used to be ignored). Documentation changes: Documented $dbh = $sth->{Database} attribute. Documented $dbh->connected(...) post-connection call when subclassing. Updated some minor doc issues thanks to H.Merijn Brand. Updated Makefile.PL example in DBI::DBD thanks to KAWAI,Takanori. Fixed execute_array() example thanks to Peter van Hardenberg. Changes for driver authors, not required but strongly recommended: Change DBIS to DBIc_DBISTATE(imp_xxh) [or imp_dbh, imp_sth etc] Change DBILOGFP to DBIc_LOGPIO(imp_xxh) [or imp_dbh, imp_sth etc] Any function from which all instances of DBIS and DBILOGFP are removed can also have dPERLINTERP removed (a good thing). All use of the DBIh_EVENT* macros should be removed. Major update to DBI::DBD docs thanks largely to Jonathan Leffler. Add these key values: 'Err' => \my $err, 'Errstr' => \my $errstr, to the hash passed to DBI::_new_dbh() in your driver source code. That will make each $dbh have it's own $h->err and $h->errstr values separate from other $dbh belonging to the same driver. If you have a ::db or ::st DESTROY methods that do nothing you can now remove them - which speeds up handle destruction. =head2 Changes in DBI 1.30, 18th July 2002 Fixed problems with selectrow_array, selectrow_arrayref, and selectall_arrayref introduced in DBI 1.29. Fixed FETCHing a handle attribute to not clear $DBI::err etc (broken in 1.29). Fixed core dump at trace level 9 or above. Fixed compilation with perl 5.6.1 + ithreads (i.e. Windows). Changed definition of behaviour of selectrow_array when called in a scalar context to match fetchrow_array. Corrected selectrow_arrayref docs which showed selectrow_array thanks to Paul DuBois. =head2 Changes in DBI 1.29, 15th July 2002 NOTE: This release changes the specified behaviour for the : fetchrow_array method when called in a scalar context: : The DBI spec used to say that it would return the FIRST field. : Which field it returns (i.e., the first or the last) is now undefined. : This does not affect statements that only select one column, which is : usually the case when fetchrow_array is called in a scalar context. : FYI, this change was triggered by discovering that the fetchrow_array : implementation in Driver.xst (used by most compiled drivers) : didn't match the DBI specification. Rather than change the code : to match, and risk breaking existing applications, I've changed the : specification (that part was always of dubious value anyway). NOTE: Future versions of the DBI may not support for perl 5.5 much longer. : If you are still using perl 5.005_03 you should be making plans to : upgrade to at least perl 5.6.1, or 5.8.0. Perl 5.8.0 is due to be : released in the next week or so. (Although it's a "point 0" release, : it is the most thoroughly tested release ever.) Added XS/C implementations of selectrow_array, selectrow_arrayref, and selectall_arrayref to Driver.xst. See DBI 1.26 Changes for more info. Removed support for the old (fatally flawed) "5005" threading model. Added support for new perl 5.8 iThreads thanks to Gerald Richter. (Threading support and safety should still be regarded as beta quality until further notice. But it's much better than it was.) Updated the "Threads and Thread Safety" section of the docs. The trace output can be sent to STDOUT instead of STDERR by using "STDOUT" as the name of the file, i.e., $h->trace(..., "STDOUT") Added pointer to perlreftut, perldsc, perllol, and perlboot manuals into the intro section of the docs, suggested by Brian McCain. Fixed DBI::Const::GetInfo::* pod docs thanks to Zack Weinberg. Some changes to how $dbh method calls are treated by DBI::Profile: Meta-data methods now clear $dbh->{Statement} on entry. Some $dbh methods are now profiled as if $dbh->{Statement} was empty (because thet're unlikely to actually relate to its contents). Updated dbiport.h to ppport.h from perl 5.8.0. Tested with perl 5.5.3 (vanilla, Solaris), 5.6.1 (vanilla, Solaris), and perl 5.8.0 (RC3@17527 with iThreads & Multiplicity on Solaris and FreeBSD). =head2 Changes in DBI 1.28, 14th June 2002 Added $sth->{ParamValues} to return a hash of the most recent values bound to placeholders via bind_param() or execute(). Individual drivers need to be updated to support it. Enhanced ShowErrorStatement to include ParamValues if available: "DBD::foo::st execute failed: errstr [for statement ``...'' with params: 1='foo']" Further enhancements to DBD::PurePerl accuracy. =head2 Changes in DBI 1.27, 13th June 2002 Fixed missing column in C implementation of fetchall_arrayref() thanks to Philip Molter for the prompt reporting of the problem. =head2 Changes in DBI 1.26, 13th June 2002 Fixed t/40profile.t to work on Windows thanks to Smejkal Petr. Fixed $h->{Profile} to return undef, not error, if not set. Fixed DBI->available_drivers in scalar context thanks to Michael Schwern. Added C implementations of selectrow_arrayref() and fetchall_arrayref() in Driver.xst. All compiled drivers using Driver.xst will now be faster making those calls. Most noticeable with fetchall_arrayref for many rows or selectrow_arrayref with a fast query. For example, using DBD::mysql a selectrow_arrayref for a single row using a primary key is ~20% faster, and fetchall_arrayref for 20000 rows is twice as fast! Drivers just need to be recompiled and reinstalled to enable it. The fetchall_arrayref speed up only applies if $slice parameter is not used. Added $max_rows parameter to fetchall_arrayref() to optionally limit the number of rows returned. Can now fetch batches of rows. Added MaxRows attribute to selectall_arrayref() which then passes it to fetchall_arrayref(). Changed selectrow_array to make use of selectrow_arrayref. Trace level 1 now shows first two parameters of all methods (used to only for that for some, like prepare,execute,do etc) Trace indicator for recursive calls (first char on trace lines) now starts at 1 not 2. Documented that $h->func() does not trigger RaiseError etc so applications must explicitly check for errors. DBI::Profile with DBI_PROFILE now shows percentage time inside DBI. HandleError docs updated to show that handler can edit error message. HandleError subroutine interface is now regarded as stable. =head2 Changes in DBI 1.25, 5th June 2002 Fixed build problem on Windows and some compiler warnings. Fixed $dbh->{Driver} and $sth->{Statement} for driver internals These are 'inner' handles as per behaviour prior to DBI 1.16. Further minor improvements to DBI::PurePerl accuracy. =head2 Changes in DBI 1.24, 4th June 2002 Fixed reference loop causing a handle/memory leak that was introduced in DBI 1.16. Fixed DBI::Format to work with 'filehandles' from IO::Scalar and similar modules thanks to report by Jeff Boes. Fixed $h->func for DBI::PurePerl thanks to Jeff Zucker. Fixed $dbh->{Name} for DBI::PurePerl thanks to Dean Arnold. Added DBI method call profiling and benchmarking. This is a major new addition to the DBI. See $h->{Profile} attribute and DBI::Profile module. For a quick trial, set the DBI_PROFILE environment variable and run your favourite DBI script. Try it with DBI_PROFILE set to 1, then try 2, 4, 8, 10, and -10. Have fun! Added execute_array() and bind_param_array() documentation with thanks to Dean Arnold. Added notes about the DBI having not yet been tested with iThreads (testing and patches for SvLOCK etc welcome). Removed undocumented Handlers attribute (replaced by HandleError). Tested with 5.5.3 and 5.8.0 RC1. =head2 Changes in DBI 1.23, 25th May 2002 Greatly improved DBI::PurePerl in performance and accuracy. Added more detail to DBI::PurePerl docs about what's not supported. Fixed undef warnings from t/15array.t and DBD::Sponge. =head2 Changes in DBI 1.22, 22nd May 2002 Added execute_array() and bind_param_array() with special thanks to Dean Arnold. Not yet documented. See t/15array.t for examples. All drivers now automatically support these methods. Added DBI::PurePerl, a transparent DBI emulation for pure-perl drivers with special thanks to Jeff Zucker. Perldoc DBI::PurePerl for details. Added DBI::Const::GetInfo* modules thanks to Steffen Goeldner. Added write_getinfo_pm utility to DBI::DBD thanks to Steffen Goeldner. Added $allow_active==2 mode for prepare_cached() thanks to Stephen Clouse. Updated DBI::Format to Revision 11.4 thanks to Tom Lowery. Use File::Spec in Makefile.PL (helps VMS etc) thanks to Craig Berry. Extend $h->{Warn} to commit/rollback ineffective warning thanks to Jeff Baker. Extended t/preparse.t and removed "use Devel::Peek" thanks to Scott Hildreth. Only copy Changes to blib/lib/Changes.pm once thanks to Jonathan Leffler. Updated internals for modern perls thanks to Jonathan Leffler and Jeff Urlwin. Tested with perl 5.7.3 (just using default perl config). Documentation changes: Added 'Catalog Methods' section to docs thanks to Steffen Goeldner. Updated README thanks to Michael Schwern. Clarified that driver may choose not to start new transaction until next use of $dbh after commit/rollback. Clarified docs for finish method. Clarified potentials problems with prepare_cached() thanks to Stephen Clouse. =head2 Changes in DBI 1.21, 7th February 2002 The minimum supported perl version is now 5.005_03. Fixed DBD::Proxy support for AutoCommit thanks to Jochen Wiedmann. Fixed DBI::ProxyServer bind_param(_inout) handing thanks to Oleg Mechtcheriakov. Fixed DBI::ProxyServer fetch loop thanks to nobull@mail.com. Fixed install_driver do-the-right-thing with $@ on error. It, and connect(), will leave $@ empty on success and holding the error message on error. Thanks to Jay Lawrence, Gavin Sherlock and others for the bug report. Fixed fetchrow_hashref to assign columns to the hash left-to-right so later fields with the same name overwrite earlier ones as per DBI < 1.15, thanks to Kay Roepke. Changed tables() to use quote_indentifier() if the driver returns a true value for $dbh->get_info(29) # SQL_IDENTIFIER_QUOTE_CHAR Changed ping() so it no longer triggers RaiseError/PrintError. Changed connect() to not call $class->install_driver unless needed. Changed DESTROY to catch fatal exceptions and append to $@. Added ISO SQL/CLI & ODBCv3 data type definitions thanks to Steffen Goeldner. Removed the definition of SQL_BIGINT data type constant as the value is inconsistent between standards (ODBC=-5, SQL/CLI=25). Added $dbh->column_info(...) thanks to Steffen Goeldner. Added $dbh->foreign_key_info(...) thanks to Steffen Goeldner. Added $dbh->quote_identifier(...) insipred by Simon Oliver. Added $dbh->set_err(...) for DBD authors and DBI subclasses (actually been there for a while, now expanded and documented). Added $h->{HandleError} = sub { ... } addition and/or alternative to RaiseError/PrintError. See the docs for more info. Added $h->{TraceLevel} = N attribute to set/get trace level of handle thus can set trace level via an (eg externally specified) DSN using the embedded attribute syntax: $dsn = 'dbi:DB2(PrintError=1,TraceLevel=2):dbname'; Plus, you can also now do: local($h->{TraceLevel}) = N; (but that leaks a little memory in some versions of perl). Added some call tree information to trace output if trace level >= 3 With thanks to Graham Barr for the stack walking code. Added experimental undocumented $dbh->preparse(), see t/preparse.t With thanks to Scott T. Hildreth for much of the work. Added Fowler/Noll/Vo hash type as an option to DBI::hash(). Documentation changes: Added DBI::Changes so now you can "perldoc DBI::Changes", yeah! Added selectrow_arrayref & selectrow_hashref docs thanks to Doug Wilson. Added 'Standards Reference Information' section to docs to gather together all references to relevant on-line standards. Added link to poop.sourceforge.net into the docs thanks to Dave Rolsky. Added link to hyperlinked BNF for SQL92 thanks to Jeff Zucker. Added 'Subclassing the DBI' docs thanks to Stephen Clouse, and then changed some of them to reflect the new approach to subclassing. Added stronger wording to description of $h->{private_*} attributes. Added docs for DBI::hash. Driver API changes: Now a COPY of the DBI->connect() attributes is passed to the driver connect() method, so it can process and delete any elements it wants. Deleting elements reduces/avoids the explicit $dbh->{$_} = $attr->{$_} foreach keys %$attr; that DBI->connect does after the driver connect() method returns. =head2 Changes in DBI 1.20, 24th August 2001 WARNING: This release contains two changes that may affect your code. : Any code using selectall_hashref(), which was added in March 2001, WILL : need to be changed. Any code using fetchall_arrayref() with a non-empty : hash slice parameter may, in a few rare cases, need to be changed. : See the change list below for more information about the changes. : See the DBI documentation for a description of current behaviour. Fixed memory leak thanks to Toni Andjelkovic. Changed fetchall_arrayref({ foo=>1, ...}) specification again (sorry): The key names of the returned hashes is identical to the letter case of the names in the parameter hash, regardless of the L attribute. The letter case is ignored for matching. Changed fetchall_arrayref([...]) array slice syntax specification to clarify that the numbers in the array slice are perl index numbers (which start at 0) and not column numbers (which start at 1). Added { Columns=>... } and { Slice =>... } attributes to selectall_arrayref() which is passed to fetchall_arrayref() so it can fetch hashes now. Added a { Columns => [...] } attribute to selectcol_arrayref() so that the list it returns can be built from more than one column per row. Why? Consider my %hash = @{$dbh->selectcol_arrayref($sql,{ Columns=>[1,2]})} to return id-value pairs which can be used directly to build a hash. Added $hash_ref = $sth->fetchall_hashref( $key_field ) which returns a ref to a hash with, typically, one element per row. $key_field is the name of the field to get the key for each row from. The value of the hash for each row is a hash returned by fetchrow_hashref. Changed selectall_hashref to return a hash ref (from fetchall_hashref) and not an array of hashes as it has since DBI 1.15 (end March 2001). WARNING: THIS CHANGE WILL BREAK ANY CODE USING selectall_hashref()! Sorry, but I think this is an important regularization of the API. To get previous selectall_hashref() behaviour (an array of hash refs) change $ary_ref = $dbh->selectall_hashref( $statement, undef, @bind); to $ary_ref = $dbh->selectall_arrayref($statement, { Columns=>{} }, @bind); Added NAME_lc_hash, NAME_uc_hash, NAME_hash statement handle attributes. which return a ref to a hash of field_name => field_index (0..n-1) pairs. Fixed select_hash() example thanks to Doug Wilson. Removed (unbundled) DBD::ADO and DBD::Multiplex from the DBI distribution. The latest versions of those modules are available from CPAN sites. Added $dbh->begin_work. This method causes AutoCommit to be turned off just until the next commit() or rollback(). Driver authors: if the DBIcf_BegunWork flag is set when your commit or rollback method is called then please turn AutoCommit on and clear the DBIcf_BegunWork flag. If you don't then the DBI will but it'll be much less efficient and won't handle error conditions very cleanly. Retested on perl 5.4.4, but the DBI won't support 5.4.x much longer. Added text to SUPPORT section of the docs: For direct DBI and DBD::Oracle support, enhancement, and related work I am available for consultancy on standard commercial terms. Added text to ACKNOWLEDGEMENTS section of the docs: Much of the DBI and DBD::Oracle was developed while I was Technical Director (CTO) of the Paul Ingram Group (www.ig.co.uk). So I'd especially like to thank Paul for his generosity and vision in supporting this work for many years. =head2 Changes in DBI 1.19, 20th July 2001 Made fetchall_arrayref({ foo=>1, ...}) be more strict to the specification in relation to wanting hash slice keys to be lowercase names. WARNING: If you've used fetchall_arrayref({...}) with a hash slice that contains keys with uppercase letters then your code will break. (As far as I recall the spec has always said don't do that.) Fixed $sth->execute() to update $dbh->{Statement} to $sth->{Statement}. Added row number to trace output for fetch method calls. Trace level 1 no longer shows fetches with row>1 (to reduce output volume). Added $h->{FetchHashKeyName} = 'NAME_lc' or 'NAME_uc' to alter behaviour of fetchrow_hashref() method. See docs. Added type_info quote caching to quote() method thanks to Dean Kopesky. Makes using quote() with second data type param much much faster. Added type_into_all() caching to type_info(), spotted by Dean Kopesky. Added new API definition for table_info() and tables(), driver authors please note! Added primary_key_info() to DBI API thanks to Steffen Goeldner. Added primary_key() to DBI API as simpler interface to primary_key_info(). Indent and other fixes for DBI::DBD doc thanks to H.Merijn Brand. Added prepare_cached() insert_hash() example thanks to Doug Wilson. Removed false docs for fetchall_hashref(), use fetchall_arrayref({}). =head2 Changes in DBI 1.18, 4th June 2001 Fixed that altering ShowErrorStatement also altered AutoCommit! Thanks to Jeff Boes for spotting that clanger. Fixed DBD::Proxy to handle commit() and rollback(). Long overdue, sorry. Fixed incompatibility with perl 5.004 (but no one's using that right? :) Fixed connect_cached and prepare_cached to not be affected by the order of elements in the attribute hash. Spotted by Mitch Helle-Morrissey. Fixed version number of DBI::Shell reported by Stuhlpfarrer Gerhard and others. Defined and documented table_info() attribute semantics (ODBC compatible) thanks to Olga Voronova, who also implemented then in DBD::Oracle. Updated Win32::DBIODBC (Win32::ODBC emulation) thanks to Roy Lee. =head2 Changes in DBI 1.16, 30th May 2001 Reimplemented fetchrow_hashref in C, now fetches about 25% faster! Changed behaviour if both PrintError and RaiseError are enabled to simply do both (in that order, obviously :) Slight reduction in DBI handle creation overhead. Fixed $dbh->{Driver} & $sth->{Database} to return 'outer' handles. Fixed execute param count check to honour RaiseError spotted by Belinda Giardie. Fixed build for perl5.6.1 with PERLIO thanks to H.Merijn Brand. Fixed client sql restrictions in ProxyServer.pm thanks to Jochen Wiedmann. Fixed batch mode command parsing in Shell thanks to Christian Lemburg. Fixed typo in selectcol_arrayref docs thanks to Jonathan Leffler. Fixed selectrow_hashref to be available to callers thanks to T.J.Mather. Fixed core dump if statement handle didn't define Statement attribute. Added bind_param_inout docs to DBI::DBD thanks to Jonathan Leffler. Added note to data_sources() method docs that some drivers may require a connected database handle to be supplied as an attribute. Trace of install_driver method now shows path of driver file loaded. Changed many '||' to 'or' in the docs thanks to H.Merijn Brand. Updated DBD::ADO again (improvements in error handling) from Tom Lowery. Updated Win32::DBIODBC (Win32::ODBC emulation) thanks to Roy Lee. Updated email and web addresses in DBI::FAQ thanks to Michael A Chase. =head2 Changes in DBI 1.15, 28th March 2001 Added selectrow_arrayref Added selectrow_hashref Added selectall_hashref thanks to Leon Brocard. Added DBI->connect(..., { dbi_connect_method => 'method' }) Added $dbh->{Statement} aliased to most recent child $sth->{Statement}. Added $h->{ShowErrorStatement}=1 to cause the appending of the relevant Statement text to the RaiseError/PrintError text. Modified type_info to always return hash keys in uppercase and to not require uppercase 'DATA_TYPE' key from type_info_all. Thanks to Jennifer Tong and Rob Douglas. Added \%attr param to tables() and table_info() methods. Trace method uses warn() if it can't open the new file. Trace shows source line and filename during global destruction. Updated packages: Updated Win32::DBIODBC (Win32::ODBC emulation) thanks to Roy Lee. Updated DBD::ADO to much improved version 0.4 from Tom Lowery. Updated DBD::Sponge to include $sth->{PRECISION} thanks to Tom Lowery. Changed DBD::ExampleP to use lstat() instead of stat(). Documentation: Documented $DBI::lasth (which has been there since day 1). Documented SQL_* names. Clarified and extended docs for $h->state thanks to Masaaki Hirose. Clarified fetchall_arrayref({}) docs (thanks to, er, someone!). Clarified type_info_all re lettercase and index values. Updated DBI::FAQ to 0.38 thanks to Alligator Descartes. Added cute bind_columns example thanks to H.Merijn Brand. Extended docs on \%attr arg to data_sources method. Makefile.PL Removed obscure potential 'rm -rf /' (thanks to Ulrich Pfeifer). Removed use of glob and find (thanks to Michael A. Chase). Proxy: Removed debug messages from DBD::Proxy AUTOLOAD thanks to Brian McCauley. Added fix for problem using table_info thanks to Tom Lowery. Added better determination of where to put the pid file, and... Added KNOWN ISSUES section to DBD::Proxy docs thanks to Jochen Wiedmann. Shell: Updated DBI::Format to include DBI::Format::String thanks to Tom Lowery. Added describe command thanks to Tom Lowery. Added columnseparator option thanks to Tom Lowery (I think). Added 'raw' format thanks to, er, someone, maybe Tom again. Known issues: Perl 5.005 and 5.006 both leak memory doing local($handle->{Foo}). Perl 5.004 doesn't. The leak is not a DBI or driver bug. =head2 Changes in DBI 1.14, 14th June 2000 NOTE: This version is the one the DBI book is based on. NOTE: This version requires at least Perl 5.004. Perl 5.6 ithreads changes with thanks to Doug MacEachern. Changed trace output to use PerlIO thanks to Paul Moore. Fixed bug in RaiseError/PrintError handling. (% chars in the error string could cause a core dump.) Fixed Win32 PerlEx IIS concurrency bugs thanks to Murray Nesbitt. Major documentation polishing thanks to Linda Mui at O'Reilly. Password parameter now shown as **** in trace output. Added two fields to type_info and type_info_all. Added $dsn to PrintError/RaiseError message from DBI->connect(). Changed prepare_cached() croak to carp if sth still Active. Added prepare_cached() example to the docs. Added further DBD::ADO enhancements from Thomas Lowery. =head2 Changes in DBI 1.13, 11th July 1999 Fixed Win32 PerlEx IIS concurrency bugs thanks to Murray Nesbitt. Fixed problems with DBD::ExampleP long_list test mode. Added SQL_WCHAR SQL_WVARCHAR SQL_WLONGVARCHAR and SQL_BIT to list of known and exportable SQL types. Improved data fetch performance of DBD::ADO. Added GetTypeInfo to DBD::ADO thanks to Thomas Lowery. Actually documented connect_cached thanks to Michael Schwern. Fixed user/key/cipher bug in ProxyServer thanks to Joshua Pincus. =head2 Changes in DBI 1.12, 29th June 1999 Fixed significant DBD::ADO bug (fetch skipped first row). Fixed ProxyServer bug handling non-select statements. Fixed VMS problem with t/examp.t thanks to Craig Berry. Trace only shows calls to trace_msg and _set_fbav at high levels. Modified t/examp.t to workaround Cygwin buffering bug. =head2 Changes in DBI 1.11, 17th June 1999 Fixed bind_columns argument checking to allow a single arg. Fixed problems with internal default_user method. Fixed broken DBD::ADO. Made default $DBI::rows more robust for some obscure cases. =head2 Changes in DBI 1.10, 14th June 1999 Fixed trace_msg.al error when using Apache. Fixed dbd_st_finish enhancement in Driver.xst (internals). Enable drivers to define default username and password and temporarily disabled warning added in 1.09. Thread safety optimised for single thread case. =head2 Changes in DBI 1.09, 9th June 1999 Added optional minimum trace level parameter to trace_msg(). Added warning in Makefile.PL that DBI will require 5.004 soon. Added $dbh->selectcol_arrayref($statement) method. Fixed fetchall_arrayref hash-slice mode undef NAME problem. Fixed problem with tainted parameter checking and t/examp.t. Fixed problem with thread safety code, including 64 bit machines. Thread safety now enabled by default for threaded perls. Enhanced code for MULTIPLICITY/PERL_OBJECT from ActiveState. Enhanced prepare_cached() method. Minor changes to trace levels (less internal info at level 2). Trace log now shows "!! ERROR..." before the "<- method" line. DBI->connect() now warn's if user / password is undefined and DBI_USER / DBI_PASS environment variables are not defined. The t/proxy.t test now ignores any /etc/dbiproxy.conf file. Added portability fixes for MacOS from Chris Nandor. Updated mailing list address from fugue.com to isc.org. =head2 Changes in DBI 1.08, 12th May 1999 Much improved DBD::ADO driver thanks to Phlip Plumlee and others. Connect now allows you to specify attribute settings within the DSN E.g., "dbi:Driver(RaiseError=>1,Taint=>1,AutoCommit=>0):dbname" The $h->{Taint} attribute now also enables taint checking of arguments to almost all DBI methods. Improved trace output in various ways. Fixed bug where $sth->{NAME_xx} was undef in some situations. Fixed code for MULTIPLICITY/PERL_OBJECT thanks to Alex Smishlajev. Fixed and documented DBI->connect_cached. Workaround for Cygwin32 build problem with help from Jong-Pork Park. bind_columns no longer needs undef or hash ref as first parameter. =head2 Changes in DBI 1.07, 6th May 1999 Trace output now shows contents of array refs returned by DBI. Changed names of some result columns from type_info, type_info_all, tables and table_info to match ODBC 3.5 / ISO/IEC standards. Many fixes for DBD::Proxy and ProxyServer. Fixed error reporting in install_driver. Major enhancement to DBI::W32ODBC from Patrick Hollins. Added $h->{Taint} to taint fetched data if tainting (perl -T). Added code for MULTIPLICITY/PERL_OBJECT contributed by ActiveState. Added $sth->more_results (undocumented for now). =head2 Changes in DBI 1.06, 6th January 1999 Fixed Win32 Makefile.PL problem in 1.04 and 1.05. Significant DBD::Proxy enhancements and fixes including support for bind_param_inout (Jochen and I) Added experimental DBI->connect_cached method. Added $sth->{NAME_uc} and $sth->{NAME_lc} attributes. Enhanced fetchrow_hashref to take an attribute name arg. =head2 Changes in DBI 1.05, 4th January 1999 Improved DBD::ADO connect (thanks to Phlip Plumlee). Improved thread safety (thanks to Jochen Wiedmann). [Quick release prompted by truncation of copies on CPAN] =head2 Changes in DBI 1.04, 3rd January 1999 Fixed error in Driver.xst. DBI build now tests Driver.xst. Removed unused variable compiler warnings in Driver.xst. DBI::DBD module now tested during DBI build. Further clarification in the DBI::DBD driver writers manual. Added optional name parameter to $sth->fetchrow_hashref. =head2 Changes in DBI 1.03, 1st January 1999 Now builds with Perl>=5.005_54 (PERL_POLLUTE in DBIXS.h) DBI trace trims path from "at yourfile.pl line nnn". Trace level 1 now shows statement passed to prepare. Assorted improvements to the DBI manual. Assorted improvements to the DBI::DBD driver writers manual. Fixed $dbh->quote prototype to include optional $data_type. Fixed $dbh->prepare_cached problems. $dbh->selectrow_array behaves better in scalar context. Added a (very) experimental DBD::ADO driver for Win32 ADO. Added experimental thread support (perl Makefile.PL -thread). Updated the DBI::FAQ - thanks to Alligator Descartes. The following changes were implemented and/or packaged by Jochen Wiedmann - thanks Jochen: Added a Bundle for CPAN installation of DBI, the DBI proxy server and prerequisites (lib/Bundle/DBI.pm). DBI->available_drivers uses File::Spec, if available. This makes it work on MacOS. (DBI.pm) Modified type_info to work with read-only values returned by type_info_all. (DBI.pm) Added handling of magic values in $sth->execute, $sth->bind_param and other methods (Driver.xst) Added Perl's CORE directory to the linkers path on Win32, required by recent versions of ActiveState Perl. Fixed DBD::Sponge to work with empty result sets. Complete rewrite of DBI::ProxyServer and DBD::Proxy. =head2 Changes in DBI 1.02, 2nd September 1998 Fixed DBI::Shell including @ARGV and /current. Added basic DBI::Shell test. Renamed DBI::Shell /display to /format. =head2 Changes in DBI 1.01, 2nd September 1998 Many enhancements to Shell (with many contributions from Jochen Wiedmann, Tom Lowery and Adam Marks). Assorted fixes to DBD::Proxy and DBI::ProxyServer. Tidied up trace messages - trace(2) much cleaner now. Added $dbh->{RowCacheSize} and $sth->{RowsInCache}. Added experimental DBI::Format (mainly for DBI::Shell). Fixed fetchall_arrayref($slice_hash). DBI->connect now honours PrintError=1 if connect fails. Assorted clarifications to the docs. =head2 Changes in DBI 1.00, 14th August 1998 The DBI is no longer 'alpha' software! Added $dbh->tables and $dbh->table_info. Documented \%attr arg to data_sources method. Added $sth->{TYPE}, $sth->{PRECISION} and $sth->{SCALE}. Added $sth->{Statement}. DBI::Shell now uses neat_list to print results It also escapes "'" chars and converts newlines to spaces. =head2 Changes in DBI 0.95, 10th August 1998 WARNING: THIS IS AN EXPERIMENTAL RELEASE! Fixed 0.94 slip so it will build on pre-5.005 again. Added DBI_AUTOPROXY environment variable. Array ref returned from fetch/fetchrow_arrayref now readonly. Improved connect error reporting by DBD::Proxy. All trace/debug messages from DBI now go to trace file. =head2 Changes in DBI 0.94, 9th August 1998 WARNING: THIS IS AN EXPERIMENTAL RELEASE! Added DBD::Shell and dbish interactive DBI shell. Try it! Any database attribs can be set via DBI->connect(,,, \%attr). Added _get_fbav and _set_fbav methods for Perl driver developers (see ExampleP driver for perl usage). Drivers which don't use one of these methods (either via XS or Perl) are not compliant. DBI trace now shows adds " at yourfile.pl line nnn"! PrintError and RaiseError now prepend driver and method name. The available_drivers method no longer returns NullP or Sponge. Added $dbh->{Name}. Added $dbh->quote($value, $data_type). Added more hints to install_driver failure message. Added DBD::Proxy and DBI::ProxyServer (from Jochen Wiedmann). Added $DBI::neat_maxlen to control truncation of trace output. Added $dbh->selectall_arrayref and $dbh->selectrow_array methods. Added $dbh->tables. Added $dbh->type_info and $dbh->type_info_all. Added $h->trace_msg($msg) to write to trace log. Added @bool = DBI::looks_like_number(@ary). Many assorted improvements to the DBI docs. =head2 Changes in DBI 0.93, 13th February 1998 Fixed DBI::DBD::dbd_postamble bug causing 'Driver.xsi not found' errors. Changes to handling of 'magic' values in neatsvpv (used by trace). execute (in Driver.xst) stops binding after first bind error. This release requires drivers to be rebuilt. =head2 Changes in DBI 0.92, 3rd February 1998 Fixed per-handle memory leak (with many thanks to Irving Reid). Added $dbh->prepare_cached() caching variant of $dbh->prepare. Added some attributes: $h->{Active} is the handle 'Active' (vague concept) (boolean) $h->{Kids} e.g. number of sth's associated with a dbh $h->{ActiveKids} number of the above which are 'Active' $dbh->{CachedKids} ref to prepare_cached sth cache Added support for general-purpose 'private_' attributes. Added experimental support for subclassing the DBI: see t/subclass.t Added SQL_ALL_TYPES to exported :sql_types. Added dbd_dbi_dir() and dbd_dbi_arch_dir() to DBI::DBD module so that DBD Makefile.PLs can work with the DBI installed in non-standard locations. Fixed 'Undefined value' warning and &sv_no output from neatsvpv/trace. Fixed small 'once per interpreter' leak. Assorted minor documentation fixes. =head2 Changes in DBI 0.91, 10th December 1997 NOTE: This fix may break some existing scripts: DBI->connect("dbi:...",$user,$pass) was not setting AutoCommit and PrintError! DBI->connect(..., { ... }) no longer sets AutoCommit or PrintError twice. DBI->connect(..., { RaiseError=>1 }) now croaks if connect fails. Fixed $fh parameter of $sth->dump_results; Added default statement DESTROY method which carps. Added default driver DESTROY method to silence AUTOLOAD/__DIE__/CGI::Carp Added more SQL_* types to %EXPORT_TAGS and @EXPORT_OK. Assorted documentation updates (mainly clarifications). Added workaround for perl's 'sticky lvalue' bug. Added better warning for bind_col(umns) where fields==0. Fixed to build okay with 5.004_54 with or without USE_THREADS. Note that the DBI has not been tested for thread safety yet. =head2 Changes in DBI 0.90, 6th September 1997 Can once again be built with Perl 5.003. The DBI class can be subclassed more easily now. InactiveDestroy fixed for drivers using the *.xst template. Slightly faster handle creation. Changed prototype for dbd_*_*_attrib() to add extra param. Note: 0.90, 0.89 and possibly some other recent versions have a small memory leak. This will be fixed in the next release. =head2 Changes in DBI 0.89, 25th July 1997 Minor fix to neatsvpv (mainly used for debug trace) to workaround bug in perl where SvPV removes IOK flag from an SV. Minor updates to the docs. =head2 Changes in DBI 0.88, 22nd July 1997 Fixed build for perl5.003 and Win32 with Borland. Fixed documentation formatting. Fixed DBI_DSN ignored for old-style connect (with explicit driver). Fixed AutoCommit in DBD::ExampleP Fixed $h->trace. The DBI can now export SQL type values: use DBI ':sql_types'; Modified Driver.xst and renamed DBDI.h to dbd_xsh.h =head2 Changes in DBI 0.87, 18th July 1997 Fixed minor type clashes. Added more docs about placeholders and bind values. =head2 Changes in DBI 0.86, 16th July 1997 Fixed failed connect causing 'unblessed ref' and other errors. Drivers must handle AutoCommit FETCH and STORE else DBI croaks. Added $h->{LongReadLen} and $h->{LongTruncOk} attributes for BLOBS. Added DBI_USER and DBI_PASS env vars. See connect docs for usage. Added DBI->trace() to set global trace level (like per-handle $h->trace). PERL_DBI_DEBUG env var renamed DBI_DEBUG (old name still works for now). Updated docs, including commit, rollback, AutoCommit and Transactions sections. Added bind_param method and execute(@bind_values) to docs. Fixed fetchall_arrayref. Since the DBIS structure has change the internal version numbers have also changed (DBIXS_VERSION == 9 and DBISTATE_VERSION == 9) so drivers will have to be recompiled. The test is also now more sensitive and the version mismatch error message now more clear about what to do. Old drivers are likely to core dump (this time) until recompiled for this DBI. In future DBI/DBD version mismatch will always produce a clear error message. Note that this DBI release contains and documents many new features that won't appear in drivers for some time. Driver writers might like to read perldoc DBI::DBD and comment on or apply the information given. =head2 Changes in DBI 0.85, 25th June 1997 NOTE: New-style connect now defaults to AutoCommit mode unless { AutoCommit => 0 } specified in connect attributes. See the docs. AutoCommit attribute now defined and tracked by DBI core. Drivers should use/honour this and not implement their own. Added pod doc changes from Andreas and Jonathan. New DBI_DSN env var default for connect method. See docs. Documented the func method. Fixed "Usage: DBD::_::common::DESTROY" error. Fixed bug which set some attributes true when there value was fetched. Added new internal DBIc_set() macro for drivers to use. =head2 Changes in DBI 0.84, 20th June 1997 Added $h->{PrintError} attribute which, if set true, causes all errors to trigger a warn(). New-style DBI->connect call now automatically sets PrintError=1 unless { PrintError => 0 } specified in the connect attributes. See the docs. The old-style connect with a separate driver parameter is deprecated. Fixed fetchrow_hashref. Renamed $h->debug to $h->trace() and added a trace filename arg. Assorted other minor tidy-ups. =head2 Changes in DBI 0.83, 11th June 1997 Added driver specification syntax to DBI->connect data_source parameter: DBI->connect('dbi:driver:...', $user, $passwd); The DBI->data_sources method should return data_source names with the appropriate 'dbi:driver:' prefix. DBI->connect will warn if \%attr is true but not a hash ref. Added the new fetchrow methods: @row_ary = $sth->fetchrow_array; $ary_ref = $sth->fetchrow_arrayref; $hash_ref = $sth->fetchrow_hashref; The old fetch and fetchrow methods still work. Driver implementors should implement the new names for fetchrow_array and fetchrow_arrayref ASAP (use the xs ALIAS: directive to define aliases for fetch and fetchrow). Fixed occasional problems with t/examp.t test. Added automatic errstr reporting to the debug trace output. Added the DBI FAQ from Alligator Descartes in module form for easy reading via "perldoc DBI::FAQ". Needs reformatting. Unknown driver specific attribute names no longer croak. Fixed problem with internal neatsvpv macro. =head2 Changes in DBI 0.82, 23rd May 1997 Added $h->{RaiseError} attribute which, if set true, causes all errors to trigger a die(). This makes it much easier to implement robust applications in terms of higher level eval { ... } blocks and rollbacks. Added DBI->data_sources($driver) method for implementation by drivers. The quote method now returns the string NULL (without quotes) for undef. Added VMS support thanks to Dan Sugalski. Added a 'quick start guide' to the README. Added neatsvpv function pointer to DBIS structure to make it available for use by drivers. A macro defines neatsvpv(sv,len) as (DBIS->neatsvpv(sv,len)). Old XS macro SV_YES_NO changes to standard boolSV. Since the DBIS structure has change the internal version numbers have also changed (DBIXS_VERSION == 8 and DBISTATE_VERSION == 8) so drivers will have to be recompiled. =head2 Changes in DBI 0.81, 7th May 1997 Minor fix to let DBI build using less modern perls. Fixed a suprious typo warning. =head2 Changes in DBI 0.80, 6th May 1997 Builds with no changes on NT using perl5.003_99 (with thanks to Jeffrey Urlwin). Automatically supports Apache::DBI (with thanks to Edmund Mergl). DBI scripts no longer need to be modified to make use of Apache::DBI. Added a ping method and an experimental connect_test_perf method. Added a fetchhash and fetch_all methods. The func method no longer pre-clears err and errstr. Added ChopBlanks attribute (currently defaults to off, that may change). Support for the attribute needs to be implemented by individual drivers. Reworked tests into standard t/*.t form. Added more pod text. Fixed assorted bugs. =head2 Changes in DBI 0.79, 7th Apr 1997 Minor release. Tidied up pod text and added some more descriptions (especially disconnect). Minor changes to DBI.xs to remove compiler warnings. =head2 Changes in DBI 0.78, 28th Mar 1997 Greatly extended the pod documentation in DBI.pm, including the under used bind_columns method. Use 'perldoc DBI' to read after installing. Fixed $h->err. Fetching an attribute value no longer resets err. Added $h->{InactiveDestroy}, see documentation for details. Improved debugging of cached ('quick') attribute fetches. errstr will return err code value if there is no string value. Added DBI/W32ODBC to the distribution. This is a pure-perl experimental DBI emulation layer for Win32::ODBC. Note that it's unsupported, your mileage will vary, and bug reports without fixes will probably be ignored. =head2 Changes in DBI 0.77, 21st Feb 1997 Removed erroneous $h->errstate and $h->errmsg methods from DBI.pm. Added $h->err, $h->errstr and $h->state default methods in DBI.xs. Updated informal DBI API notes in DBI.pm. Updated README slightly. DBIXS.h now correctly installed into INST_ARCHAUTODIR. (DBD authors will need to edit their Makefile.PL's to use -I$(INSTALLSITEARCH)/auto/DBI -I$(INSTALLSITEARCH)/DBI) =head2 Changes in DBI 0.76, 3rd Feb 1997 Fixed a compiler type warnings (pedantic IRIX again). =head2 Changes in DBI 0.75, 27th Jan 1997 Fix problem introduced by a change in Perl5.003_XX. Updated README and DBI.pm docs. =head2 Changes in DBI 0.74, 14th Jan 1997 Dispatch now sets dbi_debug to the level of the current handle (this makes tracing/debugging individual handles much easier). The '>> DISPATCH' log line now only logged at debug >= 3 (was 2). The $csr->NUM_OF_FIELDS attribute can be set if not >0 already. You can log to a file using the env var PERL_DBI_DEBUG=/tmp/dbi.log. Added a type cast needed by IRIX. No longer sets perl_destruct_level unless debug set >= 4. Make compatible with PerlIO and sfio. =head2 Changes in DBI 0.73, 10th Oct 1996 Fixed some compiler type warnings (IRIX). Fixed DBI->internal->{DebugLog} = $filename. Made debug log file unbuffered. Added experimental bind_param_inout method to interface. Usage: $dbh->bind_param_inout($param, \$value, $maxlen [, \%attribs ]) (only currently used by DBD::Oracle at this time.) =head2 Changes in DBI 0.72, 23 Sep 1996 Using an undefined value as a handle now gives a better error message (mainly useful for emulators like Oraperl). $dbh->do($sql, @params) now works for binding placeholders. =head2 Changes in DBI 0.71, 10 July 1996 Removed spurious abort() from invalid handle check. Added quote method to DBI interface and added test. =head2 Changes in DBI 0.70, 16 June 1996 Added extra invalid handle check (dbih_getcom) Fixed broken $dbh->quote method. Added check for old GCC in Makefile.PL =head2 Changes in DBI 0.69 Fixed small memory leak. Clarified the behaviour of DBI->connect. $dbh->do now returns '0E0' instead of 'OK'. Fixed "Can't read $DBI::errstr, lost last handle" problem. =head2 Changes in DBI 0.68, 2 Mar 1996 Changes to suit perl5.002 and site_lib directories. Detects old versions ahead of new in @INC. =head2 Changes in DBI 0.67, 15 Feb 1996 Trivial change to test suite to fix a problem shown up by the Perl5.002gamma release Test::Harness. =head2 Changes in DBI 0.66, 29 Jan 1996 Minor changes to bring the DBI into line with 5.002 mechanisms, specifically the xs/pm VERSION checking mechanism. No functionality changes. One no-last-handle bug fix (rare problem). Requires 5.002 (beta2 or later). =head2 Changes in DBI 0.65, 23 Oct 1995 Added $DBI::state to hold SQL CLI / ODBC SQLSTATE value. SQLSTATE "00000" (success) is returned as "" (false), all else is true. If a driver does not explicitly initialise it (via $h->{State} or DBIc_STATE(imp_xxh) then $DBI::state will automatically return "" if $DBI::err is false otherwise "S1000" (general error). As always, this is a new feature and liable to change. The is *no longer* a default error handler! You can add your own using push(@{$h->{Handlers}}, sub { ... }) but be aware that this interface may change (or go away). The DBI now automatically clears $DBI::err, errstr and state before calling most DBI methods. Previously error conditions would persist. Added DBIh_CLEAR_ERROR(imp_xxh) macro. DBI now EXPORT_OK's some utility functions, neat($value), neat_list(@values) and dump_results($sth). Slightly enhanced t/min.t minimal test script in an effort to help narrow down the few stray core dumps that some porters still report. Renamed readblob to blob_read (old name still works but warns). Added default blob_copy_to_file method. Added $sth = $dbh->tables method. This returns an $sth for a query which has these columns: TABLE_CATALOGUE, TABLE_OWNER, TABLE_NAME, TABLE_TYPE, REMARKS in that order. The TABLE_CATALOGUE column should be ignored for now. =head2 Changes in DBI 0.64, 23 Oct 1995 Fixed 'disconnect invalidates 1 associated cursor(s)' problem. Drivers using DBIc_ACTIVE_on/off() macros should not need any changes other than to test for DBIc_ACTIVE_KIDS() instead of DBIc_KIDS(). Fixed possible core dump in dbih_clearcom during global destruction. =head2 Changes in DBI 0.63, 1 Sep 1995 Minor update. Fixed uninitialised memory bug in method attribute handling and streamlined processing and debugging. Revised usage definitions for bind_* methods and readblob. =head2 Changes in DBI 0.62, 26 Aug 1995 Added method redirection method $h->func(..., $method_name). This is now the official way to call private driver methods that are not part of the DBI standard. E.g.: @ary = $sth->func('ora_types'); It can also be used to call existing methods. Has very low cost. $sth->bind_col columns now start from 1 (not 0) to match SQL. $sth->bind_columns now takes a leading attribute parameter (or undef), e.g., $sth->bind_columns($attribs, \$col1 [, \$col2 , ...]); Added handy DBD_ATTRIBS_CHECK macro to vet attribs in XS. Added handy DBD_ATTRIB_GET_SVP, DBD_ATTRIB_GET_BOOL and DBD_ATTRIB_GET_IV macros for handling attributes. Fixed STORE for NUM_OF_FIELDS and NUM_OF_PARAMS. Added FETCH for NUM_OF_FIELDS and NUM_OF_PARAMS. Dispatch no longer bothers to call _untie(). Faster startup via install_method/_add_dispatch changes. =head2 Changes in DBI 0.61, 22 Aug 1995 Added $sth->bind_col($column, \$var [, \%attribs ]); This method enables perl variable to be directly and automatically updated when a row is fetched. It requires no driver support (if the driver has been written to use DBIS->get_fbav). Currently \%attribs is unused. Added $sth->bind_columns(\$var [, \$var , ...]); This method is a short-cut for bind_col which binds all the columns of a query in one go (with no attributes). It also requires no driver support. Added $sth->bind_param($parameter, $var [, \%attribs ]); This method enables attributes to be specified when values are bound to placeholders. It also enables binding to occur away from the execute method to improve execute efficiency. The DBI does not provide a default implementation of this. See the DBD::Oracle module for a detailed example. The DBI now provides default implementations of both fetch and fetchrow. Each is written in terms of the other. A driver is expected to implement at least one of them. More macro and assorted structure changes in DBDXS.h. Sorry! The old dbihcom definitions have gone. All fields have macros. The imp_xxh_t type is now used within the DBI as well as drivers. Drivers must set DBIc_NUM_FIELDS(imp_sth) and DBIc_NUM_PARAMS(imp_sth). test.pl includes a trivial test of bind_param and bind_columns. =head2 Changes in DBI 0.60, 17 Aug 1995 This release has significant code changes but much less dramatic than the previous release. The new implementors data handling mechanism has matured significantly (don't be put off by all the struct typedefs in DBIXS.h, there's just to make it easier for drivers while keeping things type-safe). The DBI now includes two new methods: do $dbh->do($statement) This method prepares, executes and finishes a statement. It is designed to be used for executing one-off non-select statements where there is no benefit in reusing a prepared statement handle. fetch $array_ref = $sth->fetch; This method is the new 'lowest-level' row fetching method. The previous @row = $sth->fetchrow method now defaults to calling the fetch method and expanding the returned array reference. The DBI now provides fallback attribute FETCH and STORE functions which drivers should call if they don't recognise an attribute. THIS RELEASE IS A GOOD STARTING POINT FOR DRIVER DEVELOPERS! Study DBIXS.h from the DBI and Oracle.xs etc from DBD::Oracle. There will be further changes in the interface but nothing as dramatic as these last two releases! (I hope :-) =head2 Changes in DBI 0.59 15 Aug 1995 NOTE: THIS IS AN UNSTABLE RELEASE! Major reworking of internal data management! Performance improvements and memory leaks fixed. Added a new NullP (empty) driver and a -m flag to test.pl to help check for memory leaks. Study DBD::Oracle version 0.21 for more details. (Comparing parts of v0.21 with v0.20 may be useful.) =head2 Changes in DBI 0.58 21 June 1995 Added DBI->internal->{DebugLog} = $filename; Reworked internal logging. Added $VERSION. Made disconnect_all a compulsory method for drivers. =head1 ANCIENT HISTORY 12th Oct 1994: First public release of the DBI module. (for Perl 5.000-beta-3h) 19th Sep 1994: DBperl project renamed to DBI. 29th Sep 1992: DBperl project started. =cut PK1])KKDBD.pmnu[package DBI::DBD; # vim:ts=8:sw=4 use strict; use vars qw($VERSION); # set $VERSION early so we don't confuse PAUSE/CPAN etc # don't use Revision here because that's not in svn:keywords so that the # examples that use it below won't be messed up $VERSION = "12.015129"; # $Id: DBD.pm 15128 2012-02-04 20:51:39Z Tim $ # # Copyright (c) 1997-2006 Jonathan Leffler, Jochen Wiedmann, Steffen # Goeldner and Tim Bunce # # You may distribute under the terms of either the GNU General Public # License or the Artistic License, as specified in the Perl README file. =head1 NAME DBI::DBD - Perl DBI Database Driver Writer's Guide =head1 SYNOPSIS perldoc DBI::DBD =head2 Version and volatility This document is I a minimal draft which is in need of further work. Please read the B documentation first and fully. Then look at the implementation of some high-profile and regularly maintained drivers like DBD::Oracle, DBD::ODBC, DBD::Pg etc. (Those are no no particular order.) Then reread the B specification and the code of those drivers again as you're reading this. It'll help. Where this document and the driver code differ it's likely that the driver code is more correct, especially if multiple drivers do the same thing. This document is a patchwork of contributions from various authors. More contributions (preferably as patches) are very welcome. =head1 DESCRIPTION This document is primarily intended to help people writing new database drivers for the Perl Database Interface (Perl DBI). It may also help others interested in discovering why the internals of a B driver are written the way they are. This is a guide. Few (if any) of the statements in it are completely authoritative under all possible circumstances. This means you will need to use judgement in applying the guidelines in this document. If in I doubt at all, please do contact the I mailing list (details given below) where Tim Bunce and other driver authors can help. =head1 CREATING A NEW DRIVER The first rule for creating a new database driver for the Perl DBI is very simple: B There is usually a driver already available for the database you want to use, almost regardless of which database you choose. Very often, the database will provide an ODBC driver interface, so you can often use B to access the database. This is typically less convenient on a Unix box than on a Microsoft Windows box, but there are numerous options for ODBC driver managers on Unix too, and very often the ODBC driver is provided by the database supplier. Before deciding that you need to write a driver, do your homework to ensure that you are not wasting your energies. [As of December 2002, the consensus is that if you need an ODBC driver manager on Unix, then the unixODBC driver (available from L) is the way to go.] The second rule for creating a new database driver for the Perl DBI is also very simple: B Nevertheless, there are occasions when it is necessary to write a new driver, often to use a proprietary language or API to access the database more swiftly, or more comprehensively, than an ODBC driver can. Then you should read this document very carefully, but with a suitably sceptical eye. If there is something in here that does not make any sense, question it. You might be right that the information is bogus, but don't come to that conclusion too quickly. =head2 URLs and mailing lists The primary web-site for locating B software and information is http://dbi.perl.org/ There are two main and one auxiliary mailing lists for people working with B. The primary lists are I for general users of B and B drivers, and I mainly for B driver writers (don't join the I list unless you have a good reason). The auxiliary list is I for announcing new releases of B or B drivers. You can join these lists by accessing the web-site L. The lists are closed so you cannot send email to any of the lists unless you join the list first. You should also consider monitoring the I newsgroups, especially I. =head2 The Cheetah book The definitive book on Perl DBI is the Cheetah book, so called because of the picture on the cover. Its proper title is 'I' by Alligator Descartes and Tim Bunce, published by O'Reilly Associates, February 2000, ISBN 1-56592-699-4. Buy it now if you have not already done so, and read it. =head2 Locating drivers Before writing a new driver, it is in your interests to find out whether there already is a driver for your database. If there is such a driver, it would be much easier to make use of it than to write your own! The primary web-site for locating Perl software is L. You should look under the various modules listings for the software you are after. For example: http://search.cpan.org/modlist/Database_Interfaces Follow the B and B links at the top to see those subsets. See the B docs for information on B web sites and mailing lists. =head2 Registering a new driver Before going through any official registration process, you will need to establish that there is no driver already in the works. You'll do that by asking the B mailing lists whether there is such a driver available, or whether anybody is working on one. When you get the go ahead, you will need to establish the name of the driver and a prefix for the driver. Typically, the name is based on the name of the database software it uses, and the prefix is a contraction of that. Hence, B has the name I and the prefix 'I'. The prefix must be lowercase and contain no underscores other than the one at the end. This information will be recorded in the B module. Apart from documentation purposes, registration is a prerequisite for L. If you are writing a driver which will not be distributed on CPAN, then you should choose a prefix beginning with 'I', to avoid potential prefix collisions with drivers registered in the future. Thus, if you wrote a non-CPAN distributed driver called B, the prefix might be 'I'. This document assumes you are writing a driver called B, and that the prefix 'I' is assigned to the driver. =head2 Two styles of database driver There are two distinct styles of database driver that can be written to work with the Perl DBI. Your driver can be written in pure Perl, requiring no C compiler. When feasible, this is the best solution, but most databases are not written in such a way that this can be done. Some examples of pure Perl drivers are B and B. Alternatively, and most commonly, your driver will need to use some C code to gain access to the database. This will be classified as a C/XS driver. =head2 What code will you write? There are a number of files that need to be written for either a pure Perl driver or a C/XS driver. There are no extra files needed only by a pure Perl driver, but there are several extra files needed only by a C/XS driver. =head3 Files common to pure Perl and C/XS drivers Assuming that your driver is called B, these files are: =over 4 =item * F =item * F =item * F =item * F =item * F =item * F =item * F =item * F =back The first four files are mandatory. F is used to control how the driver is built and installed. The F file tells people who download the file about how to build the module and any prerequisite software that must be installed. The F file is used by the standard Perl module distribution mechanism. It lists all the source files that need to be distributed with your module. F is what is loaded by the B code; it contains the methods peculiar to your driver. Although the F file is not B you are advised to create one. Of particular importance are the I and I attributes which newer CPAN modules understand. You use these to tell the CPAN module (and CPANPLUS) that your build and configure mechanisms require DBI. The best reference for META.yml (at the time of writing) is L. You can find a reasonable example of a F in DBD::ODBC. The F file allows you to specify other Perl modules on which yours depends in a format that allows someone to type a simple command and ensure that all the pre-requisites are in place as well as building your driver. The F file contains (an updated version of) the information that was included - or that would have been included - in the appendices of the Cheetah book as a summary of the abilities of your driver and the associated database. The files in the F subdirectory are unit tests for your driver. You should write your tests as stringently as possible, while taking into account the diversity of installations that you can encounter: =over 4 =item * Your tests should not casually modify operational databases. =item * You should never damage existing tables in a database. =item * You should code your tests to use a constrained name space within the database. For example, the tables (and all other named objects) that are created could all begin with 'I'. =item * At the end of a test run, there should be no testing objects left behind in the database. =item * If you create any databases, you should remove them. =item * If your database supports temporary tables that are automatically removed at the end of a session, then exploit them as often as possible. =item * Try to make your tests independent of each other. If you have a test F that depends upon the successful running of F, people cannot run the single test case F. Further, running F twice in a row is likely to fail (at least, if F modifies the database at all) because the database at the start of the second run is not what you saw at the start of the first run. =item * Document in your F file what you do, and what privileges people need to do it. =item * You can, and probably should, sequence your tests by including a test number before an abbreviated version of the test name; the tests are run in the order in which the names are expanded by shell-style globbing. =item * It is in your interests to ensure that your tests work as widely as possible. =back Many drivers also install sub-modules B for any of a variety of different reasons, such as to support the metadata methods (see the discussion of L below). Such sub-modules are conventionally stored in the directory F. The module itself would usually be in a file F. All such sub-modules should themselves be version stamped (see the discussions far below). =head3 Extra files needed by C/XS drivers The software for a C/XS driver will typically contain at least four extra files that are not relevant to a pure Perl driver. =over 4 =item * F =item * F =item * F =item * F =back The F file is used to generate C code that Perl can call to gain access to the C functions you write that will, in turn, call down onto your database software. The F header is a stylized header that ensures you can access the necessary Perl and B macros, types, and function declarations. The F is used to specify which functions have been implemented by your driver. The F file is where you write the C code that does the real work of translating between Perl-ish data types and what the database expects to use and return. There are some (mainly small, but very important) differences between the contents of F and F for pure Perl and C/XS drivers, so those files are described both in the section on creating a pure Perl driver and in the section on creating a C/XS driver. Obviously, you can add extra source code files to the list. =head2 Requirements on a driver and driver writer To be remotely useful, your driver must be implemented in a format that allows it to be distributed via CPAN, the Comprehensive Perl Archive Network (L and L). Of course, it is easier if you do not have to meet this criterion, but you will not be able to ask for much help if you do not do so, and no-one is likely to want to install your module if they have to learn a new installation mechanism. =head1 CREATING A PURE PERL DRIVER Writing a pure Perl driver is surprisingly simple. However, there are some problems you should be aware of. The best option is of course picking up an existing driver and carefully modifying one method after the other. Also look carefully at B and B. As an example we take a look at the B driver, a driver for accessing plain files as tables, which is part of the B package. The minimal set of files we have to implement are F, F, F and F. =head2 Pure Perl version of Makefile.PL You typically start with writing F, a Makefile generator. The contents of this file are described in detail in the L man pages. It is definitely a good idea if you start reading them. At least you should know about the variables I, I, I, I, I, I, I, I, I, I, I, I, I, I, I, I from the L man page: these are used in almost any F. Additionally read the section on I and the descriptions of the I, I and I targets: They will definitely be useful for you. Of special importance for B drivers is the I method from the L man page. For Emacs users, I recommend the I method, which removes Emacs backup files (file names which end with a tilde '~') from lists of files. Now an example, I use the word C wherever you should insert your driver's name: # -*- perl -*- use ExtUtils::MakeMaker; WriteMakefile( dbd_edit_mm_attribs( { 'NAME' => 'DBD::Driver', 'VERSION_FROM' => 'Driver.pm', 'INC' => '', 'dist' => { 'SUFFIX' => '.gz', 'COMPRESS' => 'gzip -9f' }, 'realclean' => { FILES => '*.xsi' }, 'PREREQ_PM' => '1.03', 'CONFIGURE' => sub { eval {require DBI::DBD;}; if ($@) { warn $@; exit 0; } my $dbi_arch_dir = dbd_dbi_arch_dir(); if (exists($opts{INC})) { return {INC => "$opts{INC} -I$dbi_arch_dir"}; } else { return {INC => "-I$dbi_arch_dir"}; } } }, { create_pp_tests => 1}) ); package MY; sub postamble { return main::dbd_postamble(@_); } sub libscan { my ($self, $path) = @_; ($path =~ m/\~$/) ? undef : $path; } Note the calls to C and C. The second hash reference in the call to C (containing C) is optional; you should not use it unless your driver is a pure Perl driver (that is, it does not use C and XS code). Therefore, the call to C is not relevant for C/XS drivers and may be omitted; simply use the (single) hash reference containing NAME etc as the only argument to C. Note that the C code will fail if you do not have a F sub-directory containing at least one test case. I tells MakeMaker that DBI (version 1.03 in this case) is required for this module. This will issue a warning that DBI 1.03 is missing if someone attempts to install your DBD without DBI 1.03. See I below for why this does not work reliably in stopping cpan testers failing your module if DBI is not installed. I is a subroutine called by MakeMaker during C. By putting the C in this section we can attempt to load DBI::DBD but if it is missing we exit with success. As we exit successfully without creating a Makefile when DBI::DBD is missing cpan testers will not report a failure. This may seem at odds with I but I does not cause C to fail (unless you also specify PREREQ_FATAL which is strongly discouraged by MakeMaker) so C would continue to call C and fail. All drivers must use C or risk running into problems. Note the specification of I; the named file (F) will be scanned for the first line that looks like an assignment to I<$VERSION>, and the subsequent text will be used to determine the version number. Note the commentary in L on the subject of correctly formatted version numbers. If your driver depends upon external software (it usually will), you will need to add code to ensure that your environment is workable before the call to C. If you need to check for the existence of an external library and perhaps modify I to include the paths to where the external library header files are located and you cannot find the library or header files make sure you output a message saying they cannot be found but C (success) B calling C or CPAN testers will fail your module if the external library is not found. A full-fledged I can be quite large (for example, the files for B and B are both over 1000 lines long, and the Informix one uses - and creates - auxiliary modules too). See also L and L. Consider using L in place of I. =head2 README The L file should describe what the driver is for, the pre-requisites for the build process, the actual build process, how to report errors, and who to report them to. Users will find ways of breaking the driver build and test process which you would never even have dreamed to be possible in your worst nightmares. Therefore, you need to write this document defensively, precisely and concisely. As always, use the F from one of the established drivers as a basis for your own; the version in B is worth a look as it has been quite successful in heading off problems. =over 4 =item * Note that users will have versions of Perl and B that are both older and newer than you expected, but this will seldom cause much trouble. When it does, it will be because you are using features of B that are not supported in the version they are using. =item * Note that users will have versions of the database software that are both older and newer than you expected. You will save yourself time in the long run if you can identify the range of versions which have been tested and warn about versions which are not known to be OK. =item * Note that many people trying to install your driver will not be experts in the database software. =item * Note that many people trying to install your driver will not be experts in C or Perl. =back =head2 MANIFEST The F will be used by the Makefile's dist target to build the distribution tar file that is uploaded to CPAN. It should list every file that you want to include in your distribution, one per line. =head2 lib/Bundle/DBD/Driver.pm The CPAN module provides an extremely powerful bundle mechanism that allows you to specify pre-requisites for your driver. The primary pre-requisite is B; you may want or need to add some more. With the bundle set up correctly, the user can type: perl -MCPAN -e 'install Bundle::DBD::Driver' and Perl will download, compile, test and install all the Perl modules needed to build your driver. The prerequisite modules are listed in the C section, with the official name of the module followed by a dash and an informal name or description. =over 4 =item * Listing B as the main pre-requisite simplifies life. =item * Don't forget to list your driver. =item * Note that unless the DBMS is itself a Perl module, you cannot list it as a pre-requisite in this file. =item * You should keep the version of the bundle the same as the version of your driver. =item * You should add configuration management, copyright, and licencing information at the top. =back A suitable skeleton for this file is shown below. package Bundle::DBD::Driver; $VERSION = '0.01'; 1; __END__ =head1 NAME Bundle::DBD::Driver - A bundle to install all DBD::Driver related modules =head1 SYNOPSIS C =head1 CONTENTS Bundle::DBI - Bundle for DBI by TIMB (Tim Bunce) DBD::Driver - DBD::Driver by YOU (Your Name) =head1 DESCRIPTION This bundle includes all the modules used by the Perl Database Interface (DBI) driver for Driver (DBD::Driver), assuming the use of DBI version 1.13 or later, created by Tim Bunce. If you've not previously used the CPAN module to install any bundles, you will be interrogated during its setup phase. But when you've done it once, it remembers what you told it. You could start by running: C =head1 SEE ALSO Bundle::DBI =head1 AUTHOR Your Name EFE =head1 THANKS This bundle was created by ripping off Bundle::libnet created by Graham Barr EFE, and radically simplified with some information from Jochen Wiedmann EFE. The template was then included in the DBI::DBD documentation by Jonathan Leffler EFE. =cut =head2 lib/DBD/Driver/Summary.pm There is no substitute for taking the summary file from a driver that was documented in the Perl book (such as B or B or B, to name but three), and adapting it to describe the facilities available via B when accessing the Driver database. =head2 Pure Perl version of Driver.pm The F file defines the Perl module B for your driver. It will define a package B along with some version information, some variable definitions, and a function C which will have a more or less standard structure. It will also define three sub-packages of B: =over 4 =item DBD::Driver::dr with methods C, C and C; =item DBD::Driver::db with methods such as C; =item DBD::Driver::st with methods such as C and C. =back The F file will also contain the documentation specific to B in the format used by perldoc. In a pure Perl driver, the F file is the core of the implementation. You will need to provide all the key methods needed by B. Now let's take a closer look at an excerpt of F as an example. We ignore things that are common to any module (even non-DBI modules) or really specific to the B package. =head3 The DBD::Driver package =head4 The header package DBD::File; use strict; use vars qw($VERSION $drh); $VERSION = "1.23.00" # Version number of DBD::File This is where the version number of your driver is specified, and is where F looks for this information. Please ensure that any other modules added with your driver are also version stamped so that CPAN does not get confused. It is recommended that you use a two-part (1.23) or three-part (1.23.45) version number. Also consider the CPAN system, which gets confused and considers version 1.10 to precede version 1.9, so that using a raw CVS, RCS or SCCS version number is probably not appropriate (despite being very common). For Subversion you could use: $VERSION = "12.012346"; (use lots of leading zeros on the second portion so if you move the code to a shared repository like svn.perl.org the much larger revision numbers won't cause a problem, at least not for a few years). For RCS or CVS you can use: $VERSION = "11.22"; which pads out the fractional part with leading zeros so all is well (so long as you don't go past x.99) $drh = undef; # holds driver handle once initialized This is where the driver handle will be stored, once created. Note that you may assume there is only one handle for your driver. =head4 The driver constructor The C method is the driver handle constructor. Note that the C method is in the B package, not in one of the sub-packages B, B, or B. sub driver { return $drh if $drh; # already created - return same one my ($class, $attr) = @_; $class .= "::dr"; DBD::Driver::db->install_method('drv_example_dbh_method'); DBD::Driver::st->install_method('drv_example_sth_method'); # not a 'my' since we use it above to prevent multiple drivers $drh = DBI::_new_drh($class, { 'Name' => 'File', 'Version' => $VERSION, 'Attribution' => 'DBD::File by Jochen Wiedmann', }) or return undef; return $drh; } This is a reasonable example of how B implements its handles. There are three kinds: B (typically stored in I<$drh>; from now on called I or I<$drh>), B (from now on called I or I<$dbh>) and B (from now on called I or I<$sth>). The prototype of C is $drh = DBI::_new_drh($class, $public_attrs, $private_attrs); with the following arguments: =over 4 =item I<$class> is typically the class for your driver, (for example, "DBD::File::dr"), passed as the first argument to the C method. =item I<$public_attrs> is a hash ref to attributes like I, I, and I. These are processed and used by B. You had better not make any assumptions about them nor should you add private attributes here. =item I<$private_attrs> This is another (optional) hash ref with your private attributes. B will store them and otherwise leave them alone. =back The C method and the C method both return C for failure (in which case you must look at I<$DBI::err> and I<$DBI::errstr> for the failure information, because you have no driver handle to use). =head4 Using install_method() to expose driver-private methods DBD::Foo::db->install_method($method_name, \%attr); Installs the driver-private method named by $method_name into the DBI method dispatcher so it can be called directly, avoiding the need to use the func() method. It is called as a static method on the driver class to which the method belongs. The method name must begin with the corresponding registered driver-private prefix. For example, for DBD::Oracle $method_name must being with 'C', and for DBD::AnyData it must begin with 'C'. The C<\%attr> attributes can be used to provide fine control over how the DBI dispatcher handles the dispatching of the method. However it's undocumented at the moment. See the IMA_* #define's in DBI.xs and the O=>0x000x values in the initialization of %DBI::DBI_methods in DBI.pm. (Volunteers to polish up and document the interface are very welcome to get in touch via dbi-dev@perl.org). Methods installed using install_method default to the standard error handling behaviour for DBI methods: clearing err and errstr before calling the method, and checking for errors to trigger RaiseError etc. on return. This differs from the default behaviour of func(). Note for driver authors: The DBD::Foo::xx->install_method call won't work until the class-hierarchy has been setup. Normally the DBI looks after that just after the driver is loaded. This means install_method() can't be called at the time the driver is loaded unless the class-hierarchy is set up first. The way to do that is to call the setup_driver() method: DBI->setup_driver('DBD::Foo'); before using install_method(). =head4 The CLONE special subroutine Also needed here, in the B package, is a C method that will be called by perl when an interpreter is cloned. All your C method needs to do, currently, is clear the cached I<$drh> so the new interpreter won't start using the cached I<$drh> from the old interpreter: sub CLONE { undef $drh; } See L for details. =head3 The DBD::Driver::dr package The next lines of code look as follows: package DBD::Driver::dr; # ====== DRIVER ====== $DBD::Driver::dr::imp_data_size = 0; Note that no I<@ISA> is needed here, or for the other B classes, because the B takes care of that for you when the driver is loaded. *FIX ME* Explain what the imp_data_size is, so that implementors aren't practicing cargo-cult programming. =head4 The database handle constructor The database handle constructor is the driver's (hence the changed namespace) C method: sub connect { my ($drh, $dr_dsn, $user, $auth, $attr) = @_; # Some database specific verifications, default settings # and the like can go here. This should only include # syntax checks or similar stuff where it's legal to # 'die' in case of errors. # For example, many database packages requires specific # environment variables to be set; this could be where you # validate that they are set, or default them if they are not set. my $driver_prefix = "drv_"; # the assigned prefix for this driver # Process attributes from the DSN; we assume ODBC syntax # here, that is, the DSN looks like var1=val1;...;varN=valN foreach my $var ( split /;/, $dr_dsn ) { my ($attr_name, $attr_value) = split '=', $var, 2; return $drh->set_err($DBI::stderr, "Can't parse DSN part '$var'") unless defined $attr_value; # add driver prefix to attribute name if it doesn't have it already $attr_name = $driver_prefix.$attr_name unless $attr_name =~ /^$driver_prefix/o; # Store attribute into %$attr, replacing any existing value. # The DBI will STORE() these into $dbh after we've connected $attr->{$attr_name} = $attr_value; } # Get the attributes we'll use to connect. # We use delete here because these no need to STORE them my $db = delete $attr->{drv_database} || delete $attr->{drv_db} or return $drh->set_err($DBI::stderr, "No database name given in DSN '$dr_dsn'"); my $host = delete $attr->{drv_host} || 'localhost'; my $port = delete $attr->{drv_port} || 123456; # Assume you can attach to your database via drv_connect: my $connection = drv_connect($db, $host, $port, $user, $auth) or return $drh->set_err($DBI::stderr, "Can't connect to $dr_dsn: ..."); # create a 'blank' dbh (call superclass constructor) my ($outer, $dbh) = DBI::_new_dbh($drh, { Name => $dr_dsn }); $dbh->STORE('Active', 1 ); $dbh->{drv_connection} = $connection; return $outer; } This is mostly the same as in the I above. The arguments are described in L. The constructor C is called, returning a database handle. The constructor's prototype is: ($outer, $inner) = DBI::_new_dbh($drh, $public_attr, $private_attr); with similar arguments to those in the I, except that the I<$class> is replaced by I<$drh>. The I attribute is a standard B attribute (see L). In scalar context, only the outer handle is returned. Note the use of the C method for setting the I 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 users of your driver have. Because you have the inner handle, tie magic doesn't get invoked when you get or set values in the hash. This is often very handy for speed when you want to get or set simple non-special driver-specific attributes. However, some attribute values, such as those handled by the B like I, don't actually exist in the hash and must be read via C<$h-EFETCH($attrib)> and set via C<$h-ESTORE($attrib, $value)>. If in any doubt, use these methods. =head4 The data_sources() method The C method must populate and return a list of valid data sources, prefixed with the "I" incantation that allows them to be used in the first argument of the Cconnect()> method. An example of this might be scanning the F<$HOME/.odbcini> file on Unix for ODBC data sources (DSNs). As a trivial example, consider a fixed list of data sources: sub data_sources { my($drh, $attr) = @_; my(@list) = (); # You need more sophisticated code than this to set @list... push @list, "dbi:Driver:abc"; push @list, "dbi:Driver:def"; push @list, "dbi:Driver:ghi"; # End of code to set @list return @list; } =head4 The disconnect_all() method If you need to release any resources when the driver is unloaded, you can provide a disconnect_all method. =head4 Other driver handle methods If you need any other driver handle methods, they can follow here. =head4 Error handling It is quite likely that something fails in the connect method. With B for example, you might catch an error when setting the current directory to something not existent by using the (driver-specific) I attribute. To report an error, you use the C method: $h->set_err($err, $errmsg, $state); This will ensure that the error is recorded correctly and that I and I etc are handled correctly. Typically you'll always use the method instance, aka your method's first argument. As C always returns C your error handling code can usually be simplified to something like this: return $h->set_err($err, $errmsg, $state) if ...; =head3 The DBD::Driver::db package package DBD::Driver::db; # ====== DATABASE ====== $DBD::Driver::db::imp_data_size = 0; =head4 The statement handle constructor There's nothing much new in the statement handle constructor, which is the C method: sub prepare { my ($dbh, $statement, @attribs) = @_; # create a 'blank' sth my ($outer, $sth) = DBI::_new_sth($dbh, { Statement => $statement }); $sth->STORE('NUM_OF_PARAMS', ($statement =~ tr/?//)); $sth->{drv_params} = []; return $outer; } This is still the same -- check the arguments and call the super class constructor C. Again, in scalar context, only the outer handle is returned. The I attribute should be cached as shown. Note the prefix I in the attribute names: it is required that all your private attributes use a lowercase prefix unique to your driver. As mentioned earlier in this document, the B contains a registry of known driver prefixes and may one day warn about unknown attributes that don't have a registered prefix. Note that we parse the statement here in order to set the attribute I. The technique illustrated is not very reliable; it can be confused by question marks appearing in quoted strings, delimited identifiers or in SQL comments that are part of the SQL statement. We could set I in the C method instead because the B specification explicitly allows a driver to defer this, but then the user could not call C. =head4 Transaction handling Pure Perl drivers will rarely support transactions. Thus your C and C methods will typically be quite simple: sub commit { my ($dbh) = @_; if ($dbh->FETCH('Warn')) { warn("Commit ineffective while AutoCommit is on"); } 0; } sub rollback { my ($dbh) = @_; if ($dbh->FETCH('Warn')) { warn("Rollback ineffective while AutoCommit is on"); } 0; } Or even simpler, just use the default methods provided by the B that do nothing except return C. The B's default C method can be used by inheritance. =head4 The STORE() and FETCH() methods These methods (that we have already used, see above) are called for you, whenever the user does a: $dbh->{$attr} = $val; or, respectively, $val = $dbh->{$attr}; See L for details on tied hash refs to understand why these methods are required. The B will handle most attributes for you, in particular attributes like I or I. All you have to do is handle your driver's private attributes and any attributes, like I and I, that the B can't handle for you. A good example might look like this: sub STORE { my ($dbh, $attr, $val) = @_; if ($attr eq 'AutoCommit') { # AutoCommit is currently the only standard attribute we have # to consider. if (!$val) { die "Can't disable AutoCommit"; } return 1; } if ($attr =~ m/^drv_/) { # Handle only our private attributes here # Note that we could trigger arbitrary actions. # Ideally we should warn about unknown attributes. $dbh->{$attr} = $val; # Yes, we are allowed to do this, return 1; # but only for our private attributes } # Else pass up to DBI to handle for us $dbh->SUPER::STORE($attr, $val); } sub FETCH { my ($dbh, $attr) = @_; if ($attr eq 'AutoCommit') { return 1; } if ($attr =~ m/^drv_/) { # Handle only our private attributes here # Note that we could trigger arbitrary actions. return $dbh->{$attr}; # Yes, we are allowed to do this, # but only for our private attributes } # Else pass up to DBI to handle $dbh->SUPER::FETCH($attr); } The B will actually store and fetch driver-specific attributes (with all lowercase names) without warning or error, so there's actually no need to implement driver-specific any code in your C and C methods unless you need extra logic/checks, beyond getting or setting the value. Unless your driver documentation indicates otherwise, the return value of the C method is unspecified and the caller shouldn't use that value. =head4 Other database handle methods As with the driver package, other database handle methods may follow here. In particular you should consider a (possibly empty) C method and possibly a C method if B's default isn't correct for you. You may also need the C and C methods, as described elsewhere in this document. Where reasonable use C<$h-ESUPER::foo()> to call the B's method in some or all cases and just wrap your custom behavior around that. If you want to use private trace flags you'll probably want to be able to set them by name. To do that you'll need to define a C method (note that's "parse_trace_flag", singular, not "parse_trace_flags", plural). sub parse_trace_flag { my ($h, $name) = @_; return 0x01000000 if $name eq 'foo'; return 0x02000000 if $name eq 'bar'; return 0x04000000 if $name eq 'baz'; return 0x08000000 if $name eq 'boo'; return 0x10000000 if $name eq 'bop'; return $h->SUPER::parse_trace_flag($name); } All private flag names must be lowercase, and all private flags must be in the top 8 of the 32 bits. =head3 The DBD::Driver::st package This package follows the same pattern the others do: package DBD::Driver::st; $DBD::Driver::st::imp_data_size = 0; =head4 The execute() and bind_param() methods This is perhaps the most difficult method because we have to consider parameter bindings here. In addition to that, there are a number of statement attributes which must be set for inherited B methods to function correctly (see L below). We present a simplified implementation by using the I attribute from above: sub bind_param { my ($sth, $pNum, $val, $attr) = @_; my $type = (ref $attr) ? $attr->{TYPE} : $attr; if ($type) { my $dbh = $sth->{Database}; $val = $dbh->quote($sth, $type); } my $params = $sth->{drv_params}; $params->[$pNum-1] = $val; 1; } sub execute { my ($sth, @bind_values) = @_; # start of by finishing any previous execution if still active $sth->finish if $sth->FETCH('Active'); my $params = (@bind_values) ? \@bind_values : $sth->{drv_params}; my $numParam = $sth->FETCH('NUM_OF_PARAMS'); return $sth->set_err($DBI::stderr, "Wrong number of parameters") if @$params != $numParam; my $statement = $sth->{'Statement'}; for (my $i = 0; $i < $numParam; $i++) { $statement =~ s/?/$params->[$i]/; # XXX doesn't deal with quoting etc! } # Do anything ... we assume that an array ref of rows is # created and store it: $sth->{'drv_data'} = $data; $sth->{'drv_rows'} = @$data; # number of rows $sth->STORE('NUM_OF_FIELDS') = $numFields; $sth->{Active} = 1; @$data || '0E0'; } There are a number of things you should note here. We initialize the I and I attributes here, because they are essential for C to work. We use attribute C<$sth-E{Statement}> which we created within C. The attribute C<$sth-E{Database}>, which is nothing else than the I, was automatically created by B. Finally, note that (as specified in the B specification) we return the string C<'0E0'> instead of the number 0, so that the result tests true but equal to zero. $sth->execute() or die $sth->errstr; =head4 The execute_array(), execute_for_fetch() and bind_param_array() methods In general, DBD's only need to implement C and C. DBI's default C will invoke the DBD's C as needed. The following sequence describes the interaction between DBI C and a DBD's C: =over =item 1 App calls C<$sth-Eexecute_array(\%attrs, @array_of_arrays)> =item 2 If C<@array_of_arrays> was specified, DBI processes C<@array_of_arrays> by calling DBD's C. Alternately, App may have directly called C =item 3 DBD validates and binds each array =item 4 DBI retrieves the validated param arrays from DBD's ParamArray attribute =item 5 DBI calls DBD's C, where C<&$fetch_tuple_sub> is a closure to iterate over the returned ParamArray values, and C<\@tuple_status> is an array to receive the disposition status of each tuple. =item 6 DBD iteratively calls C<&$fetch_tuple_sub> to retrieve parameter tuples to be added to its bulk database operation/request. =item 7 when DBD reaches the limit of tuples it can handle in a single database operation/request, or the C<&$fetch_tuple_sub> indicates no more tuples by returning undef, the DBD executes the bulk operation, and reports the disposition of each tuple in \@tuple_status. =item 8 DBD repeats steps 6 and 7 until all tuples are processed. =back E.g., here's the essence of L's execute_for_fetch: while (1) { my @tuple_batch; for (my $i = 0; $i < $batch_size; $i++) { push @tuple_batch, [ @{$fetch_tuple_sub->() || last} ]; } last unless @tuple_batch; my $res = ora_execute_array($sth, \@tuple_batch, scalar(@tuple_batch), $tuple_batch_status); push @$tuple_status, @$tuple_batch_status; } Note that DBI's default execute_array()/execute_for_fetch() implementation requires the use of positional (i.e., '?') placeholders. Drivers which B named placeholders must either emulate positional placeholders (e.g., see L), or must implement their own execute_array()/execute_for_fetch() methods to properly sequence bound parameter arrays. =head4 Fetching data Only one method needs to be written for fetching data, C. The other methods, C, C, etc, as well as the database handle's C methods are part of B, and call C as necessary. sub fetchrow_arrayref { my ($sth) = @_; my $data = $sth->{drv_data}; my $row = shift @$data; if (!$row) { $sth->STORE(Active => 0); # mark as no longer active return undef; } if ($sth->FETCH('ChopBlanks')) { map { $_ =~ s/\s+$//; } @$row; } return $sth->_set_fbav($row); } *fetch = \&fetchrow_arrayref; # required alias for fetchrow_arrayref Note the use of the method C<_set_fbav()> -- this is required so that C and C work. If an error occurs which leaves the I<$sth> in a state where remaining rows can't be fetched then I should be turned off before the method returns. The C method for this driver can be implemented like this: sub rows { shift->{drv_rows} } because it knows in advance how many rows it has fetched. Alternatively you could delete that method and so fallback to the B's own method which does the right thing based on the number of calls to C<_set_fbav()>. =head4 The more_results method If your driver doesn't support multiple result sets, then don't even implement this method. Otherwise, this method needs to get the statement handle ready to fetch results from the next result set, if there is one. Typically you'd start with: $sth->finish; then you should delete all the attributes from the attribute cache that may no longer be relevant for the new result set: delete $sth->{$_} for qw(NAME TYPE PRECISION SCALE ...); for drivers written in C use: hv_delete((HV*)SvRV(sth), "NAME", 4, G_DISCARD); hv_delete((HV*)SvRV(sth), "NULLABLE", 8, G_DISCARD); hv_delete((HV*)SvRV(sth), "NUM_OF_FIELDS", 13, G_DISCARD); hv_delete((HV*)SvRV(sth), "PRECISION", 9, G_DISCARD); hv_delete((HV*)SvRV(sth), "SCALE", 5, G_DISCARD); hv_delete((HV*)SvRV(sth), "TYPE", 4, G_DISCARD); Don't forget to also delete, or update, any driver-private attributes that may not be correct for the next resultset. The NUM_OF_FIELDS attribute is a special case. It should be set using STORE: $sth->STORE(NUM_OF_FIELDS => 0); /* for DBI <= 1.53 */ $sth->STORE(NUM_OF_FIELDS => $new_value); for drivers written in C use this incantation: /* Adjust NUM_OF_FIELDS - which also adjusts the row buffer size */ DBIc_NUM_FIELDS(imp_sth) = 0; /* for DBI <= 1.53 */ DBIc_STATE(imp_xxh)->set_attr_k(sth, sv_2mortal(newSVpvn("NUM_OF_FIELDS",13)), 0, sv_2mortal(newSViv(mysql_num_fields(imp_sth->result))) ); For DBI versions prior to 1.54 you'll also need to explicitly adjust the number of elements in the row buffer array (C) to match the new result set. Fill any new values with newSV(0) not &sv_undef. Alternatively you could free DBIc_FIELDS_AV(imp_sth) and set it to null, but that would mean bind_columns() wouldn't work across result sets. =head4 Statement attributes The main difference between I and I attributes is, that you should implement a lot of attributes here that are required by the B, such as I, I, I, etc. See L for a complete list. Pay attention to attributes which are marked as read only, such as I. These attributes can only be set the first time a statement is executed. If a statement is prepared, then executed multiple times, warnings may be generated. You can protect against these warnings, and prevent the recalculation of attributes which might be expensive to calculate (such as the I and I attributes): my $storedNumParams = $sth->FETCH('NUM_OF_PARAMS'); if (!defined $storedNumParams or $storedNumFields < 0) { $sth->STORE('NUM_OF_PARAMS') = $numParams; # Set other useful attributes that only need to be set once # for a statement, like $sth->{NAME} and $sth->{TYPE} } One particularly important attribute to set correctly (mentioned in L is I. Many B methods, including C, depend on this attribute. Besides that the C and C methods are mainly the same as above for I's. =head4 Other statement methods A trivial C method to discard stored data, reset any attributes (such as I) and do C<$sth-ESUPER::finish()>. If you've defined a C method in B<::db> you'll also want it in B<::st>, so just alias it in: *parse_trace_flag = \&DBD::foo:db::parse_trace_flag; And perhaps some other methods that are not part of the B specification, in particular to make metadata available. Remember that they must have names that begin with your drivers registered prefix so they can be installed using C. If C is called on a statement handle that's still active (C<$sth-E{Active}> is true) then it should effectively call C. sub DESTROY { my $sth = shift; $sth->finish if $sth->FETCH('Active'); } =head2 Tests The test process should conform as closely as possibly to the Perl standard test harness. In particular, most (all) of the tests should be run in the F sub-directory, and should simply produce an C when run under C. For details on how this is done, see the Camel book and the section in Chapter 7, "The Standard Perl Library" on L. The tests may need to adapt to the type of database which is being used for testing, and to the privileges of the user testing the driver. For example, the B test code has to adapt in a number of places to the type of database to which it is connected as different Informix databases have different capabilities: some of the tests are for databases without transaction logs; others are for databases with a transaction log; some versions of the server have support for blobs, or stored procedures, or user-defined data types, and others do not. When a complete file of tests must be skipped, you can provide a reason in a pseudo-comment: if ($no_transactions_available) { print "1..0 # Skip: No transactions available\n"; exit 0; } Consider downloading the B code and look at the code in F which is used throughout the B tests in the F sub-directory. =head1 CREATING A C/XS DRIVER Please also see the section under L regarding the creation of the F. Creating a new C/XS driver from scratch will always be a daunting task. You can and should greatly simplify your task by taking a good reference driver implementation and modifying that to match the database product for which you are writing a driver. The de facto reference driver has been the one for B written by Tim Bunce, who is also the author of the B package. The B module is a good example of a driver implemented around a C-level API. Nowadays it it seems better to base on B, another driver maintained by Tim and Jeff Urlwin, because it offers a lot of metadata and seems to become the guideline for the future development. (Also as B digs deeper into the Oracle 8 OCI interface it'll get even more hairy than it is now.) The B driver is one driver implemented using embedded SQL instead of a function-based API. B may also be worth a look. =head2 C/XS version of Driver.pm A lot of the code in the F file is very similar to the code for pure Perl modules - see above. However, there are also some subtle (and not so subtle) differences, including: =over 8 =item * The variables I<$DBD::Driver::{dr|db|st}::imp_data_size> are not defined here, but in the XS code, because they declare the size of certain C structures. =item * Some methods are typically moved to the XS code, in particular C, C, C, C and the C and C methods. =item * Other methods are still part of F, but have callbacks to the XS code. =item * If the driver-specific parts of the I structure need to be formally initialized (which does not seem to be a common requirement), then you need to add a call to an appropriate XS function in the driver method of C, and you define the corresponding function in F, and you define the C code in F and the prototype in F. For example, B has such a requirement, and adds the following call after the call to C<_new_drh()> in F: DBD::Informix::dr::driver_init($drh); and the following code in F: # Initialize the DBD::Informix driver data structure void driver_init(drh) SV *drh CODE: ST(0) = dbd_ix_dr_driver_init(drh) ? &sv_yes : &sv_no; and the code in F declares: extern int dbd_ix_dr_driver_init(SV *drh); and the code in F (equivalent to F) defines: /* Formally initialize the DBD::Informix driver structure */ int dbd_ix_dr_driver(SV *drh) { D_imp_drh(drh); imp_drh->n_connections = 0; /* No active connections */ imp_drh->current_connection = 0; /* No current connection */ imp_drh->multipleconnections = (ESQLC_VERSION >= 600) ? True : False; dbd_ix_link_newhead(&imp_drh->head); /* Empty linked list of connections */ return 1; } B has a similar requirement but gets around it by checking whether the private data part of the driver handle is all zeroed out, rather than add extra functions. =back Now let's take a closer look at an excerpt from F (revised heavily to remove idiosyncrasies) as an example, ignoring things that were already discussed for pure Perl drivers. =head3 The connect method The connect method is the database handle constructor. You could write either of two versions of this method: either one which takes connection attributes (new code) and one which ignores them (old code only). If you ignore the connection attributes, then you omit all mention of the I<$auth> variable (which is a reference to a hash of attributes), and the XS system manages the differences for you. sub connect { my ($drh, $dbname, $user, $auth, $attr) = @_; # Some database specific verifications, default settings # and the like following here. This should only include # syntax checks or similar stuff where it's legal to # 'die' in case of errors. my $dbh = DBI::_new_dbh($drh, { 'Name' => $dbname, }) or return undef; # Call the driver-specific function _login in Driver.xs file which # calls the DBMS-specific function(s) to connect to the database, # and populate internal handle data. DBD::Driver::db::_login($dbh, $dbname, $user, $auth, $attr) or return undef; $dbh; } This is mostly the same as in the pure Perl case, the exception being the use of the private C<_login()> callback, which is the function that will really connect to the database. It is implemented in F (you should not implement it) and calls C or C from F. See below for details. If your driver has driver-specific attributes which may be passed in the connect method and hence end up in C<$attr> in C then it is best to delete any you process so DBI does not send them again via STORE after connect. You can do this in C like this: DBD_ATTRIB_DELETE(attr, "my_attribute_name", strlen("my_attribute_name")); However, prior to DBI subversion version 11605 (and fixed post 1.607) DBD_ATTRIB_DELETE segfaulted so if you cannot guarantee the DBI version will be post 1.607 you need to use: hv_delete((HV*)SvRV(attr), "my_attribute_name", strlen("my_attribute_name"), G_DISCARD); *FIX ME* Discuss removing attributes in Perl code. =head3 The disconnect_all method *FIX ME* T.B.S =head3 The data_sources method If your C method can be implemented in pure Perl, then do so because it is easier than doing it in XS code (see the section above for pure Perl drivers). If your C method must call onto compiled functions, then you will need to define I in your F file, which will trigger F (in B v1.33 or greater) to generate the XS code that calls your actual C function (see the discussion below for details) and you do not code anything in F to handle it. =head3 The prepare method The prepare method is the statement handle constructor, and most of it is not new. Like the C method, it now has a C callback: package DBD::Driver::db; # ====== DATABASE ====== use strict; sub prepare { my ($dbh, $statement, $attribs) = @_; # create a 'blank' sth my $sth = DBI::_new_sth($dbh, { 'Statement' => $statement, }) or return undef; # Call the driver-specific function _prepare in Driver.xs file # which calls the DBMS-specific function(s) to prepare a statement # and populate internal handle data. DBD::Driver::st::_prepare($sth, $statement, $attribs) or return undef; $sth; } =head3 The execute method *FIX ME* T.B.S =head3 The fetchrow_arrayref method *FIX ME* T.B.S =head3 Other methods? *FIX ME* T.B.S =head2 Driver.xs F should look something like this: #include "Driver.h" DBISTATE_DECLARE; INCLUDE: Driver.xsi MODULE = DBD::Driver PACKAGE = DBD::Driver::dr /* Non-standard drh XS methods following here, if any. */ /* If none (the usual case), omit the MODULE line above too. */ MODULE = DBD::Driver PACKAGE = DBD::Driver::db /* Non-standard dbh XS methods following here, if any. */ /* Currently this includes things like _list_tables from */ /* DBD::mSQL and DBD::mysql. */ MODULE = DBD::Driver PACKAGE = DBD::Driver::st /* Non-standard sth XS methods following here, if any. */ /* In particular this includes things like _list_fields from */ /* DBD::mSQL and DBD::mysql for accessing metadata. */ Note especially the include of F here: B inserts stub functions for almost all private methods here which will typically do much work for you. Wherever you really have to implement something, it will call a private function in F, and this is what you have to implement. You need to set up an extra routine if your driver needs to export constants of its own, analogous to the SQL types available when you say: use DBI qw(:sql_types); *FIX ME* T.B.S =head2 Driver.h F is very simple and the operational contents should look like this: #ifndef DRIVER_H_INCLUDED #define DRIVER_H_INCLUDED #define NEED_DBIXS_VERSION 93 /* 93 for DBI versions 1.00 to 1.51+ */ #define PERL_NO_GET_CONTEXT /* if used require DBI 1.51+ */ #include /* installed by the DBI module */ #include "dbdimp.h" #include "dbivport.h" /* see below */ #include /* installed by the DBI module */ #endif /* DRIVER_H_INCLUDED */ The F header defines most of the interesting information that the writer of a driver needs. The file F header provides prototype declarations for the C functions that you might decide to implement. Note that you should normally only define one of C, C or C unless you are intent on supporting really old versions of B (prior to B 1.06) as well as modern versions. The only standard, B-mandated functions that you need write are those specified in the F header. You might also add extra driver-specific functions in F. The F file should be I from the latest B release into your distribution each time you modify your driver. Its job is to allow you to enhance your code to work with the latest B API while still allowing your driver to be compiled and used with older versions of the B (for example, when the C macro was added to B 1.41, an emulation of it was added to F). This makes users happy and your life easier. Always read the notes in F to check for any limitations in the emulation that you should be aware of. With B v1.51 or better I recommend that the driver defines I before F is included. This can significantly improve efficiency when running under a thread enabled perl. (Remember that the standard perl in most Linux distributions is built with threads enabled. So is ActiveState perl for Windows, and perl built for Apache mod_perl2.) If you do this there are some things to keep in mind: =over 4 =item * If I is defined, then every function that calls the Perl API will need to start out with a C declaration. =item * You'll know which functions need this, because the C compiler will complain that the undeclared identifier C is used if I the perl you are using to develop and test your driver has threads enabled. =item * If you don't remember to test with a thread-enabled perl before making a release it's likely that you'll get failure reports from users who are. =item * For driver private functions it is possible to gain even more efficiency by replacing C with C prepended to the parameter list and then C prepended to the argument list where the function is called. =back See L for additional information about I. =head2 Implementation header dbdimp.h This header file has two jobs: First it defines data structures for your private part of the handles. Note that the DBI provides many common fields for you. For example the statement handle (imp_sth) already has a row_count field with an IV type that accessed via the DBIc_ROW_COUNT(imp_sth) macro. Using this is strongly recommended as it's built in to some DBI internals so the DBI can 'just work' in more cases and you'll have less driver-specific code to write. Study DBIXS.h to see what's included with each type of handle. Second it defines macros that rename the generic names like C to database specific names like C. This avoids name clashes and enables use of different drivers when you work with a statically linked perl. It also will have the important task of disabling XS methods that you don't want to implement. Finally, the macros will also be used to select alternate implementations of some functions. For example, the C function is not passed the attribute hash. Since B v1.06, if a C macro is defined (for a function with 6 arguments), it will be used instead with the attribute hash passed as the sixth argument. Since B post v1.607, if a C macro is defined (for a function like dbd_db_login6 but with scalar pointers for the dbname, username and password), it will be used instead. This will allow your login6 function to see if there are any Unicode characters in the dbname. Similarly defining dbd_db_do4_iv is preferred over dbd_db_do4, dbd_st_rows_iv over dbd_st_rows, and dbd_st_execute_iv over dbd_st_execute. The *_iv forms are declared to return the IV type instead of an int. People used to just pick Oracle's F and use the same names, structures and types. I strongly recommend against that. At first glance this saves time, but your implementation will be less readable. It was just hell when I had to separate B specific parts, Oracle specific parts, mSQL specific parts and mysql specific parts in B's I and I. (B was a port of B which was based on B.) [Seconded, based on the experience taking B apart, even though the version inherited in 1996 was only based on B.] This part of the driver is I. Rewrite it from scratch, so it will be clean and short: in other words, a better piece of code. (Of course keep an eye on other people's work.) struct imp_drh_st { dbih_drc_t com; /* MUST be first element in structure */ /* Insert your driver handle attributes here */ }; struct imp_dbh_st { dbih_dbc_t com; /* MUST be first element in structure */ /* Insert your database handle attributes here */ }; struct imp_sth_st { dbih_stc_t com; /* MUST be first element in structure */ /* Insert your statement handle attributes here */ }; /* Rename functions for avoiding name clashes; prototypes are */ /* in dbd_xsh.h */ #define dbd_init drv_dr_init #define dbd_db_login6_sv drv_db_login_sv #define dbd_db_do drv_db_do ... many more here ... These structures implement your private part of the handles. You I to use the name C and the first field I be of type I and I be called C. You should never access these fields directly, except by using the I macros below. =head2 Implementation source dbdimp.c Conventionally, F is the main implementation file (but B calls the file F). This section includes a short note on each function that is used in the F template and thus I to be implemented. Of course, you will probably also need to implement other support functions, which should usually be file static if they are placed in F. If they are placed in other files, you need to list those files in F (and F) to handle them correctly. It is wise to adhere to a namespace convention for your functions to avoid conflicts. For example, for a driver with prefix I, you might call externally visible functions I. You should also avoid non-constant global variables as much as possible to improve the support for threading. Since Perl requires support for function prototypes (ANSI or ISO or Standard C), you should write your code using function prototypes too. It is possible to use either the unmapped names such as C or the mapped names such as C in the F file. B uses the mapped names which makes it easier to identify where to look for linkage problems at runtime (which will report errors using the mapped names). Most other drivers, and in particular B, use the unmapped names in the source code which makes it a little easier to compare code between drivers and eases discussions on the I mailing list. The majority of the code fragments here will use the unmapped names. Ultimately, you should provide implementations for most of the functions listed in the F header. The exceptions are optional functions (such as C) and those functions with alternative signatures, such as C, C and I. Then you should only implement one of the alternatives, and generally the newer one of the alternatives. =head3 The dbd_init method #include "Driver.h" DBISTATE_DECLARE; void dbd_init(dbistate_t* dbistate) { DBISTATE_INIT; /* Initialize the DBI macros */ } The C function will be called when your driver is first loaded; the bootstrap command in C triggers this, and the call is generated in the I section of F. These statements are needed to allow your driver to use the B macros. They will include your private header file F in turn. Note that I requires the name of the argument to C to be called C. =head3 The dbd_drv_error method You need a function to record errors so B can access them properly. You can call it whatever you like, but we'll call it C here. The argument list depends on your database software; different systems provide different ways to get at error information. static void dbd_drv_error(SV *h, int rc, const char *what) { Note that I is a generic handle, may it be a driver handle, a database or a statement handle. D_imp_xxh(h); This macro will declare and initialize a variable I with a pointer to your private handle pointer. You may cast this to to I, I or I. To record the error correctly, equivalent to the C method, use one of the C or C macros, which were added in B 1.41: DBIh_SET_ERR_SV(h, imp_xxh, err, errstr, state, method); DBIh_SET_ERR_CHAR(h, imp_xxh, err_c, err_i, errstr, state, method); For C the I, I, I, and I parameters are C (use &sv_undef instead of NULL). For C the I, I, I, I parameters are C. The I parameter is an C that's used instead of I if I is C. The I parameter can be ignored. The C macro is usually the simplest to use when you just have an integer error code and an error message string: DBIh_SET_ERR_CHAR(h, imp_xxh, Nullch, rc, what, Nullch, Nullch); As you can see, any parameters that aren't relevant to you can be C. To make drivers compatible with B < 1.41 you should be using F as described in L above. The (obsolete) macros such as C should be removed from drivers. The names C and C, which were used in previous versions of this document, should be replaced with the C macro. The name C, which was also used in previous versions of this document, should be replaced by C. Your code should not call the C Cstdio.hE> I/O functions; you should use C as shown: if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) PerlIO_printf(DBIc_LOGPIO(imp_xxh), "foobar %s: %s\n", foo, neatsvpv(errstr,0)); That's the first time we see how tracing works within a B driver. Make use of this as often as you can, but don't output anything at a trace level less than 3. Levels 1 and 2 are reserved for the B. You can define up to 8 private trace flags using the top 8 bits of C, that is: C<0xFF000000>. See the C method elsewhere in this document. =head3 The dbd_dr_data_sources method This method is optional; the support for it was added in B v1.33. As noted in the discussion of F, if the data sources can be determined by pure Perl code, do it that way. If, as in B, the information is obtained by a C function call, then you need to define a function that matches the prototype: extern AV *dbd_dr_data_sources(SV *drh, imp_drh_t *imp_drh, SV *attrs); An outline implementation for B follows, assuming that the C function call shown will return up to 100 databases names, with the pointers to each name in the array dbsname and the name strings themselves being stores in dbsarea. AV *dbd_dr_data_sources(SV *drh, imp_drh_t *imp_drh, SV *attr) { int ndbs; int i; char *dbsname[100]; char dbsarea[10000]; AV *av = Nullav; if (sqgetdbs(&ndbs, dbsname, 100, dbsarea, sizeof(dbsarea)) == 0) { av = NewAV(); av_extend(av, (I32)ndbs); sv_2mortal((SV *)av); for (i = 0; i < ndbs; i++) av_store(av, i, newSVpvf("dbi:Informix:%s", dbsname[i])); } return(av); } The actual B implementation has a number of extra lines of code, logs function entry and exit, reports the error from C, and uses C<#define>'d constants for the array sizes. =head3 The dbd_db_login6 method int dbd_db_login6_sv(SV* dbh, imp_dbh_t* imp_dbh, SV* dbname, SV* user, SV* auth, SV *attr); or int dbd_db_login6(SV* dbh, imp_dbh_t* imp_dbh, char* dbname, char* user, char* auth, SV *attr); This function will really connect to the database. The argument I is the database handle. I is the pointer to the handles private data, as is I in C above. The arguments I, I, I and I correspond to the arguments of the driver handle's C method. You will quite often use database specific attributes here, that are specified in the DSN. I recommend you parse the DSN (using Perl) within the C method and pass the segments of the DSN via the attributes parameter through C<_login()> to C. Here's how you fetch them; as an example we use I attribute, which can be up to 12 characters long excluding null terminator: SV** svp; STRLEN len; char* hostname; if ( (svp = DBD_ATTRIB_GET_SVP(attr, "drv_hostname", 12)) && SvTRUE(*svp)) { hostname = SvPV(*svp, len); DBD_ATTRIB_DELETE(attr, "drv_hostname", 12); /* avoid later STORE */ } else { hostname = "localhost"; } If you handle any driver specific attributes in the dbd_db_login6 method you probably want to delete them from C (as above with DBD_ATTRIB_DELETE). If you don't delete your handled attributes DBI will call C for each attribute after the connect/login and this is at best redundant for attributes you have already processed. B hv_delete((HV*)SvRV(attr), key, key_len, G_DISCARD) Note that you can also obtain standard attributes such as I and I from the attributes parameter, using C for integer attributes. If, for example, your database does not support transactions but I is set off (requesting transaction support), then you can emulate a 'failure to connect'. Now you should really connect to the database. In general, if the connection fails, it is best to ensure that all allocated resources are released so that the handle does not need to be destroyed separately. If you are successful (and possibly even if you fail but you have allocated some resources), you should use the following macros: DBIc_IMPSET_on(imp_dbh); This indicates that the driver (implementor) has allocated resources in the I structure and that the implementors private C function should be called when the handle is destroyed. DBIc_ACTIVE_on(imp_dbh); This indicates that the handle has an active connection to the server and that the C function should be called before the handle is destroyed. Note that if you do need to fail, you should report errors via the I or I rather than via I or I because I will be destroyed by the failure, so errors recorded in that handle will not be visible to B, and hence not the user either. Note too, that the function is passed I and I, and there is a macro C which can recover the I from the I. However, there is no B macro to provide you with the I given either the I or the I or the I (and there's no way to recover the I given just the I). This suggests that, despite the above notes about C taking an C, it may be better to have two error routines, one taking I and one taking I instead. With care, you can factor most of the formatting code out so that these are small routines calling a common error formatter. See the code in B 1.05.00 for more information. The C function should return I for success, I otherwise. Drivers implemented long ago may define the five-argument function C instead of C. The missing argument is the attributes. There are ways to work around the missing attributes, but they are ungainly; it is much better to use the 6-argument form. Even later drivers will use C which provides the dbname, username and password as SVs. =head3 The dbd_db_commit and dbd_db_rollback methods int dbd_db_commit(SV *dbh, imp_dbh_t *imp_dbh); int dbd_db_rollback(SV* dbh, imp_dbh_t* imp_dbh); These are used for commit and rollback. They should return I for success, I for error. The arguments I and I are the same as for C above; I will omit describing them in what follows, as they appear always. These functions should return I for success, I otherwise. =head3 The dbd_db_disconnect method This is your private part of the C method. Any I with the I flag on must be disconnected. (Note that you have to set it in C above.) int dbd_db_disconnect(SV* dbh, imp_dbh_t* imp_dbh); The database handle will return I for success, I otherwise. In any case it should do a: DBIc_ACTIVE_off(imp_dbh); before returning so B knows that C was executed. Note that there's nothing to stop a I being I while it still have active children. If your database API reacts badly to trying to use an I in this situation then you'll need to add code like this to all I methods: if (!DBIc_ACTIVE(DBIc_PARENT_COM(imp_sth))) return 0; Alternatively, you can add code to your driver to keep explicit track of the statement handles that exist for each database handle and arrange to destroy those handles before disconnecting from the database. There is code to do this in B. Similar comments apply to the driver handle keeping track of all the database handles. Note that the code which destroys the subordinate handles should only release the associated database resources and mark the handles inactive; it does not attempt to free the actual handle structures. This function should return I for success, I otherwise, but it is not clear what anything can do about a failure. =head3 The dbd_db_discon_all method int dbd_discon_all (SV *drh, imp_drh_t *imp_drh); This function may be called at shutdown time. It should make best-efforts to disconnect all database handles - if possible. Some databases don't support that, in which case you can do nothing but return 'success'. This function should return I for success, I otherwise, but it is not clear what anything can do about a failure. =head3 The dbd_db_destroy method This is your private part of the database handle destructor. Any I with the I flag on must be destroyed, so that you can safely free resources. (Note that you have to set it in C above.) void dbd_db_destroy(SV* dbh, imp_dbh_t* imp_dbh) { DBIc_IMPSET_off(imp_dbh); } The B F code will have called C for you, if the handle is still 'active', before calling C. Before returning the function must switch I to off, so B knows that the destructor was called. A B handle doesn't keep references to its children. But children do keep references to their parents. So a database handle won't be C'd until all its children have been C'd. =head3 The dbd_db_STORE_attrib method This function handles $dbh->{$key} = $value; Its prototype is: int dbd_db_STORE_attrib(SV* dbh, imp_dbh_t* imp_dbh, SV* keysv, SV* valuesv); You do not handle all attributes; on the contrary, you should not handle B attributes here: leave this to B. (There are two exceptions, I and I, which you should care about.) The return value is I if you have handled the attribute or I otherwise. If you are handling an attribute and something fails, you should call C, so B can raise exceptions, if desired. If C returns, however, you have a problem: the user will never know about the error, because he typically will not check C<$dbh-Eerrstr()>. I cannot recommend a general way of going on, if C returns, but there are examples where even the B specification expects that you C. (See the I method in L.) If you have to store attributes, you should either use your private data structure I, the handle hash (via C<(HV*)SvRV(dbh)>), or use the private I. The first is best for internal C values like integers or pointers and where speed is important within the driver. The handle hash is best for values the user may want to get/set via driver-specific attributes. The private I is an additional C attached to the handle. You could think of it as an unnamed handle attribute. It's not normally used. =head3 The dbd_db_FETCH_attrib method This is the counterpart of C, needed for: $value = $dbh->{$key}; Its prototype is: SV* dbd_db_FETCH_attrib(SV* dbh, imp_dbh_t* imp_dbh, SV* keysv); Unlike all previous methods this returns an C with the value. Note that you should normally execute C, if you return a nonconstant value. (Constant values are C<&sv_undef>, C<&sv_no> and C<&sv_yes>.) Note, that B implements a caching algorithm for attribute values. If you think, that an attribute may be fetched, you store it in the I itself: if (cacheit) /* cache value for later DBI 'quick' fetch? */ hv_store((HV*)SvRV(dbh), key, kl, cachesv, 0); =head3 The dbd_st_prepare method This is the private part of the C method. Note that you B really execute the statement here. You may, however, preparse and validate the statement, or do similar things. int dbd_st_prepare(SV* sth, imp_sth_t* imp_sth, char* statement, SV* attribs); A typical, simple, possibility is to do nothing and rely on the perl C code that set the I attribute on the handle. This attribute can then be used by C. If the driver supports placeholders then the I attribute must be set correctly by C: DBIc_NUM_PARAMS(imp_sth) = ... If you can, you should also setup attributes like I, I, etc. here, but B doesn't require that - they can be deferred until execute() is called. However, if you do, document it. In any case you should set the I flag, as you did in C above: DBIc_IMPSET_on(imp_sth); =head3 The dbd_st_execute method This is where a statement will really be executed. int dbd_st_execute(SV* sth, imp_sth_t* imp_sth); C should return -2 for any error, -1 if the number of rows affected is unknown else it should be the number of affected (updated, inserted) rows. Note that you must be aware a statement may be executed repeatedly. Also, you should not expect that C will be called between two executions, so you might need code, like the following, near the start of the function: if (DBIc_ACTIVE(imp_sth)) dbd_st_finish(h, imp_sth); If your driver supports the binding of parameters (it should!), but the database doesn't, you must do it here. This can be done as follows: SV *svp; char* statement = DBD_ATTRIB_GET_PV(h, "Statement", 9, svp, ""); int numParam = DBIc_NUM_PARAMS(imp_sth); int i; for (i = 0; i < numParam; i++) { char* value = dbd_db_get_param(sth, imp_sth, i); /* It is your drivers task to implement dbd_db_get_param, */ /* it must be setup as a counterpart of dbd_bind_ph. */ /* Look for '?' and replace it with 'value'. Difficult */ /* task, note that you may have question marks inside */ /* quotes and comments the like ... :-( */ /* See DBD::mysql for an example. (Don't look too deep into */ /* the example, you will notice where I was lazy ...) */ } The next thing is to really execute the statement. Note that you must set the attributes I, I, etc when the statement is successfully executed if the driver has not already done so: they may be used even before a potential C. In particular you have to tell B the number of fields that the statement has, because it will be used by B internally. Thus the function will typically ends with: if (isSelectStatement) { DBIc_NUM_FIELDS(imp_sth) = numFields; DBIc_ACTIVE_on(imp_sth); } It is important that the I flag only be set for C