[Jifty-commit] r1941 - in Jifty-DBI/trunk: . lib/Jifty/DBI lib/Jifty/DBI/Record t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Sep 8 17:05:45 EDT 2006


Author: jesse
Date: Fri Sep  8 17:05:44 2006
New Revision: 1941

Modified:
   Jifty-DBI/trunk/   (props changed)
   Jifty-DBI/trunk/lib/Jifty/DBI/Handle.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Informix.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Handle/ODBC.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm
   Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm
   Jifty-DBI/trunk/t/10schema.t

Log:
 r27287 at pinglin:  jesse | 2006-09-08 13:39:13 -0400
 * cleaned up DSN generation. 
 * Allowed arbitrary parameter specification in DSNs
 * Corrected the method name "DSN" to "dsn" throughout.
 


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	Fri Sep  8 17:05:44 2006
@@ -95,17 +95,17 @@
         }
     }
 
-    my $dsn = $self->DSN || '';
+    my $dsn = $self->dsn || '';
 
 # Setting this actually breaks old RT versions in subtle ways. So we need to explicitly call it
 
     $self->build_dsn(%args);
 
     # Only connect if we're not connected to this source already
-    if ( ( !$self->dbh ) || ( !$self->dbh->ping ) || ( $self->DSN ne $dsn ) )
+    if ( ( !$self->dbh ) || ( !$self->dbh->ping ) || ( $self->dsn ne $dsn ) )
     {
         my $handle
-            = DBI->connect( $self->DSN, $args{'user'}, $args{'password'} )
+            = DBI->connect( $self->dsn, $args{'user'}, $args{'password'} )
             || Carp::croak "Connect Failed $DBI::errstr\n";
 
 #databases do case conversion on the name of columns returned.
@@ -143,12 +143,33 @@
 
 =head2 build_dsn PARAMHASH
 
-Takes a bunch of parameters:  
+Builds a dsn suitable for handing to DBI->connect.
 
-Required: Driver, Database,
-Optional: Host, Port and RequireSSL
+Mandatory arguments:
 
-Builds a DSN suitable for a DBI connection
+=over
+
+=item driver
+
+=item database
+
+=back
+
+Optional arguments:
+
+=over 
+
+=item host
+
+=item port
+
+=item sid
+
+=item requiressl
+
+=item and anything else your DBD lets you pass in
+
+=back
 
 =cut
 
@@ -164,25 +185,21 @@
         @_
     );
 
-    my $dsn = "dbi:$args{'driver'}:dbname=$args{'database'}";
-    $dsn .= ";sid=$args{'sid'}" if ( defined $args{'sid'} && $args{'sid'} );
-    $dsn .= ";host=$args{'host'}"
-        if ( defined $args{'host'} && $args{'host'} );
-    $dsn .= ";port=$args{'port'}"
-        if ( defined $args{'port'} && $args{'port'} );
-    $dsn .= ";requiressl=1"
-        if ( defined $args{'requiressl'} && $args{'requiressl'} );
 
-    $self->{'dsn'} = $dsn;
+    my $driver = delete $args{'driver'};
+    $args{'dbname'} ||= delete $args{'database'};
+
+    $self->{'dsn'} =
+    "dbi:$driver:" . join(';', map { $_ ."=".$args{$_} } grep { defined $args{$_} } keys %args);
 }
 
-=head2 DSN
+=head2 dsn
 
-Returns the DSN for this database connection.
+Returns the dsn for this database connection.
 
 =cut
 
-sub DSN {
+sub dsn {
     my $self = shift;
     return ( $self->{'dsn'} );
 }

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Informix.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Informix.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Informix.pm	Fri Sep  8 17:05:44 2006
@@ -57,32 +57,6 @@
     return (1);
 }
 
-=head2 build_dsn
-
-Builder for Informix DSNs.
-
-=cut
-
-sub build_dsn {
-    my $self = shift;
-    my %args = (
-        Driver     => undef,
-        Database   => undef,
-        Host       => undef,
-        Port       => undef,
-        SID        => undef,
-        RequireSSL => undef,
-        @_
-    );
-
-    my $dsn = "dbi:$args{'Driver'}:";
-
-    $dsn .= "$args{'Database'}"
-        if ( defined $args{'Database'} && $args{'Database'} );
-
-    $self->{'dsn'} = $dsn;
-}
-
 =head2 apply_limits STATEMENTREF ROWS_PER_PAGE FIRST_ROW
 
 takes an SQL SELECT statement and massages it to return ROWS_PER_PAGE starting with FIRST_ROW;

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle/ODBC.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle/ODBC.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle/ODBC.pm	Fri Sep  8 17:05:44 2006
@@ -32,30 +32,7 @@
     return (undef);
 }
 
-=head2 BuildDSN
-
-=cut
-
-sub build_dsn {
-    my $self = shift;
-    my %args = (
-        Driver   => undef,
-        Database => undef,
-        Host     => undef,
-        Port     => undef,
-        @_
-    );
-
-    my $dsn = "dbi:$args{'Driver'}:$args{'Database'}";
-    $dsn .= ";host=$args{'Host'}"
-        if ( defined $args{'Host'} && $args{'Host'} );
-    $dsn .= ";port=$args{'Port'}"
-        if ( defined $args{'Port'} && $args{'Port'} );
-
-    $self->{'dsn'} = $dsn;
-}
-
-=head2 ApplyLimits
+=head2 apply_limits
 
 =cut
 

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Handle/Oracle.pm	Fri Sep  8 17:05:44 2006
@@ -112,7 +112,7 @@
 Required: Driver, Database or Host/SID,
 Optional: Port and RequireSSL
 
-Builds a DSN suitable for an Oracle DBI connection
+Builds a dsn suitable for an Oracle DBI connection
 
 =cut
 

Modified: Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm
==============================================================================
--- Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm	(original)
+++ Jifty-DBI/trunk/lib/Jifty/DBI/Record/Cachable.pm	Fri Sep  8 17:05:44 2006
@@ -53,7 +53,7 @@
 
 sub _key_cache {
     my $self  = shift;
-    my $cache = $self->_handle->DSN
+    my $cache = $self->_handle->dsn
         . "-KEYS--"
         . ( $self->{'_class'} ||= ref($self) );
     $self->_setup_cache($cache) unless exists( $_CACHES{$cache} );
@@ -69,7 +69,7 @@
 
 sub _flush_key_cache {
     my $self  = shift;
-    my $cache = $self->_handle->DSN
+    my $cache = $self->_handle->dsn
         . "-KEYS--"
         . ( $self->{'_class'} ||= ref($self) );
     $self->_setup_cache($cache);
@@ -78,7 +78,7 @@
 sub _record_cache {
     my $self = shift;
     my $cache
-        = $self->_handle->DSN . "--" . ( $self->{'_class'} ||= ref($self) );
+        = $self->_handle->dsn . "--" . ( $self->{'_class'} ||= ref($self) );
     $self->_setup_cache($cache) unless exists( $_CACHES{$cache} );
     return ( $_CACHES{$cache} );
 

Modified: Jifty-DBI/trunk/t/10schema.t
==============================================================================
--- Jifty-DBI/trunk/t/10schema.t	(original)
+++ Jifty-DBI/trunk/t/10schema.t	Fri Sep  8 17:05:44 2006
@@ -4,7 +4,7 @@
 use warnings;
 use Test::More;
 
-use constant TESTS_PER_DRIVER => 14;
+use constant TESTS_PER_DRIVER => 15;
 our @available_drivers;
 
 BEGIN {


More information about the Jifty-commit mailing list