[Rt-commit] r3886 - in Jifty-DBI/trunk: . lib/Jifty/DBI
ruz at bestpractical.com
ruz at bestpractical.com
Sun Sep 25 04:59:12 EDT 2005
Author: ruz
Date: Sun Sep 25 04:59:11 2005
New Revision: 3886
Modified:
Jifty-DBI/trunk/ (props changed)
Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
Log:
r2505 at cubic-pc: cubic | 2005-09-24 13:29:59 +0400
* classes shouldn't import from util modules
* Handle now inherits from HasFilter
* drop @ISA from 'use vars'
* print_error and raise_serror methods no more enables fatures
by default, instead use ->method( 0 | 1 );
* log_sql_statements returns current value
* database_version now support 'short' argument(by default true)
Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm (original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm Sun Sep 25 04:59:11 2005
@@ -1,11 +1,13 @@
package Jifty::DBI::Handle;
use strict;
-use Carp;
-use DBI;
-use Class::ReturnValue;
-use Encode;
+use Carp ();
+use DBI ();
+use Class::ReturnValue ();
+use Encode ();
-use vars qw($VERSION @ISA %DBIHandle $PrevHandle $DEBUG $TRANSDEPTH);
+use base qw/Jifty::DBI::HasFilters/;
+
+use vars qw($VERSION %DBIHandle $PrevHandle $DEBUG $TRANSDEPTH);
$TRANSDEPTH = 0;
@@ -94,7 +96,7 @@
{
my $handle
= DBI->connect( $self->DSN, $args{'user'}, $args{'password'} )
- || croak "Connect Failed $DBI::errstr\n";
+ || Carp::croak "Connect Failed $DBI::errstr\n";
#databases do case conversion on the name of columns returned.
#actually, some databases just ignore case. this smashes it to something consistent
@@ -183,11 +185,8 @@
sub raise_error {
my $self = shift;
-
- my $mode = 1;
- $mode = shift if (@_);
-
- $self->dbh->{RaiseError} = $mode;
+ $self->dbh->{RaiseError} = shift if (@_);
+ return $self->dbh->{RaiseError};
}
=head2 print_error [MODE]
@@ -198,11 +197,8 @@
sub print_error {
my $self = shift;
-
- my $mode = 1;
- $mode = shift if (@_);
-
- $self->dbh->{PrintError} = $mode;
+ $self->dbh->{PrintError} = shift if (@_);
+ return $self->dbh->{PrintError};
}
=head2 log_sql_statements BOOL
@@ -219,8 +215,8 @@
if (@_) {
require Time::HiRes;
$self->{'_dologsql'} = shift;
- return ( $self->{'_dologsql'} );
}
+ return ( $self->{'_dologsql'} );
}
=head2 _log_sql_statement STATEMENT DURATION
@@ -242,7 +238,6 @@
Clears out the SQL statement log.
-
=cut
sub clear_sql_statement_log {
@@ -553,19 +548,41 @@
=head2 database_version
-Returns the database's version. The base implementation uses a "SELECT VERSION"
+Returns the database's version.
+
+If argument C<short> is true returns short variant, in other
+case returns whatever database handle/driver returns. By default
+returns short version, e.g. '4.1.23' or '8.0-rc4'.
+
+Returns empty string on error or if database couldn't return version.
+
+The base implementation uses a C<SELECT VERSION()>
=cut
sub database_version {
my $self = shift;
+ my %args = ( short => 1, @_ );
+
+ unless( defined $self->{'database_version'} ) {
+ # turn off error handling, store old values to restore later
+ my $re = $self->raise_error; $self->raise_error(0);
+ my $pe = $self->print_error; $self->print_error(0);
- unless ( $self->{'database_version'} ) {
my $statement = "SELECT VERSION()";
- my $sth = $self->simple_query($statement);
- my @vals = $sth->fetchrow();
- $self->{'database_version'} = $vals[0];
+ my $sth = $self->simple_query($statement);
+
+ my $ver = '';
+ $ver = ($sth->fetchrow_arrayref->[0] || '') if $sth;
+ $ver =~ /(\d+(?:\.\d+)*(?:-[a-z0-9]+)?)/i;
+ $self->{'database_version'} = $ver;
+ $self->{'database_version_short'} = $1 || $ver;
+
+ $self->raise_error($re); $self->print_error($pe);
}
+
+ return $self->{'database_version_short'} if $args{'short'};
+ return $self->{'database_version'};
}
=head2 case_sensitive
More information about the Rt-commit
mailing list