cvsuser     04/11/18 20:36:11

  Modified:    App-Repository/lib/App/Repository DBI.pm MySQL.pm
  Log:
  allow direct setting of dsn, change dbidriver to dbdriver
  
  Revision  Changes    Path
  1.19      +29 -26    p5ee/App-Repository/lib/App/Repository/DBI.pm
  
  Index: DBI.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/DBI.pm,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- DBI.pm    2 Sep 2004 21:04:07 -0000       1.18
  +++ DBI.pm    19 Nov 2004 04:36:11 -0000      1.19
  @@ -1,13 +1,13 @@
   
   ######################################################################
  -## File: $Id: DBI.pm,v 1.18 2004/09/02 21:04:07 spadkins Exp $
  +## File: $Id: DBI.pm,v 1.19 2004/11/19 04:36:11 spadkins Exp $
   ######################################################################
   
   use App;
   use App::Repository;
   
   package App::Repository::DBI;
  -$VERSION = do { my @r=(q$Revision: 1.18 $=~/\d+/g); sprintf 
"%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.19 $=~/\d+/g); sprintf 
"%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository" );
   
  @@ -86,7 +86,7 @@
   ######################################################################
   
   # CONNECTION ATTRIBUTES
  -# $self->{dbidriver}  # standard DBI driver name ("mysql", "Oracle", etc.)
  +# $self->{dbdriver}   # standard DBI driver name ("mysql", "Oracle", etc.)
   # $self->{dbname}     # the name of the database
   # $self->{dbuser}     # database user name
   # $self->{dbpass}     # database password
  @@ -188,18 +188,21 @@
   sub _dsn {
       &App::sub_entry if ($App::trace);
       my ($self) = @_;
  -    my ($dbidriver, $dbname, $dbuser, $dbpass, $dbschema);
  +    my ($dbdriver, $dbname, $dbuser, $dbpass, $dbschema);
   
  -    $dbidriver  = $self->{dbidriver};
  -    $dbname     = $self->{dbname};
  -    $dbuser     = $self->{dbuser};
  -    $dbpass     = $self->{dbpass};
  -    $dbschema   = $self->{dbschema};
  +    my $dsn = $self->{dbdsn};
  +    if (!$dsn) {
  +        my $dbdriver   = $self->{dbdriver} || $self->{dbdriver};
  +        my $dbname     = $self->{dbname};
  +        my $dbuser     = $self->{dbuser};
  +        my $dbpass     = $self->{dbpass};
  +        my $dbschema   = $self->{dbschema};
   
  -    die "ERROR: missing DBI driver and/or db name [$dbidriver,$dbname] in 
configuration.\n"
  -        if (!$dbidriver || !$dbname);
  +        die "ERROR: missing DBI driver and/or db name [$dbdriver,$dbname] in 
configuration.\n"
  +            if (!$dbdriver || !$dbname);
   
  -    my $dsn = "dbi:${dbidriver}:database=${dbname}";
  +        $dsn = "dbi:${dbdriver}:database=${dbname}";
  +    }
   
       &App::sub_exit($dsn) if ($App::trace);
       return($dsn);
  @@ -307,7 +310,7 @@
       }
       else {
           my ($var, $capsvar);
  -        foreach $var qw(dbidriver dbname dbuser dbpass dbioptions dbschema) {
  +        foreach $var qw(dbdriver dbname dbuser dbpass dbioptions dbschema) {
               if (! defined $self->{$var}) {
                   $capsvar = uc($var);
                   if ($ENV{$capsvar}) {
  @@ -1932,8 +1935,8 @@
       &App::sub_entry if ($App::trace);
       my ($self) = @_;
   
  -    my ($dbidriver, $dbh);
  -    $dbidriver = $self->{dbidriver};
  +    my ($dbdriver, $dbh);
  +    $dbdriver = $self->{dbdriver};
       $dbh = $self->{dbh};
   
       #####################################################
  @@ -1952,7 +1955,7 @@
   
           # if the DBI method doesn't work, try the DBIx method...
           if ($#tables == -1) {
  -            $func = DBIx::Compat::GetItem($dbidriver, "ListTables");
  +            $func = DBIx::Compat::GetItem($dbdriver, "ListTables");
               @tables = &{$func}($dbh);
           }
   
  @@ -2110,13 +2113,13 @@
       #########################################################
       # DATABASE ATTRIBUTES
       #########################################################
  -    $self->{native}{support_join}           = 
DBIx::Compat::GetItem($dbidriver, "SupportJoin");
  -    $self->{native}{inner_join_syntax}      = 
DBIx::Compat::GetItem($dbidriver, "SupportSQLJoin");
  -    $self->{native}{inner_join_only2tables} = 
DBIx::Compat::GetItem($dbidriver, "SQLJoinOnly2Tabs");
  -    $self->{native}{have_types}             = 
DBIx::Compat::GetItem($dbidriver, "HaveTypes");
  -    $self->{native}{null_operator}          = 
DBIx::Compat::GetItem($dbidriver, "NullOperator");
  -    $self->{native}{need_null_in_create}    = 
DBIx::Compat::GetItem($dbidriver, "NeedNullInCreate");
  -    $self->{native}{empty_is_null}          = 
DBIx::Compat::GetItem($dbidriver, "EmptyIsNull");
  +    $self->{native}{support_join}           = 
DBIx::Compat::GetItem($dbdriver, "SupportJoin");
  +    $self->{native}{inner_join_syntax}      = 
DBIx::Compat::GetItem($dbdriver, "SupportSQLJoin");
  +    $self->{native}{inner_join_only2tables} = 
DBIx::Compat::GetItem($dbdriver, "SQLJoinOnly2Tabs");
  +    $self->{native}{have_types}             = 
DBIx::Compat::GetItem($dbdriver, "HaveTypes");
  +    $self->{native}{null_operator}          = 
DBIx::Compat::GetItem($dbdriver, "NullOperator");
  +    $self->{native}{need_null_in_create}    = 
DBIx::Compat::GetItem($dbdriver, "NeedNullInCreate");
  +    $self->{native}{empty_is_null}          = 
DBIx::Compat::GetItem($dbdriver, "EmptyIsNull");
   
       &App::sub_exit() if ($App::trace);
   }
  @@ -2127,10 +2130,10 @@
   
       return if (! $table);
   
  -    my ($dbidriver, $dbh, $sth, $native_table, $table_def);
  +    my ($dbdriver, $dbh, $sth, $native_table, $table_def);
       my (@tables, $column, $func, $tablealias);
   
  -    $dbidriver = $self->{dbidriver};
  +    $dbdriver = $self->{dbdriver};
       $dbh = $self->{dbh};
       $table_def = $self->{table}{$table};
       return if (!defined $table_def);
  @@ -2161,7 +2164,7 @@
       my ($colnum, $data_types, $columns, $column_def, $phys_columns);
       my ($native_type_num, $native_type_def, $phys_table);
   
  -    $func = DBIx::Compat::GetItem($dbidriver, "ListFields");
  +    $func = DBIx::Compat::GetItem($dbdriver, "ListFields");
       eval {
           $sth  = &{$func}($dbh, $table);
       };
  
  
  
  1.9       +29 -24    p5ee/App-Repository/lib/App/Repository/MySQL.pm
  
  Index: MySQL.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/MySQL.pm,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- MySQL.pm  2 Sep 2004 21:02:08 -0000       1.8
  +++ MySQL.pm  19 Nov 2004 04:36:11 -0000      1.9
  @@ -1,12 +1,12 @@
   
   ######################################################################
  -## File: $Id: MySQL.pm,v 1.8 2004/09/02 21:02:08 spadkins Exp $
  +## File: $Id: MySQL.pm,v 1.9 2004/11/19 04:36:11 spadkins Exp $
   ######################################################################
   
   use App::Repository::DBI;
   
   package App::Repository::MySQL;
  -$VERSION = do { my @r=(q$Revision: 1.8 $=~/\d+/g); sprintf 
"%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.9 $=~/\d+/g); sprintf 
"%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository::DBI" );
   
  @@ -36,28 +36,33 @@
       &App::sub_entry if ($App::trace);
       my ($self) = @_;
   
  -    my $dbidriver  = "mysql";
  -    my $dbname     = $self->{dbname};
  -    my $dbuser     = $self->{dbuser};
  -    my $dbpass     = $self->{dbpass};
  -    my $dbschema   = $self->{dbschema};
  -    my $dbhost     = $self->{dbhost};
  -    my $dbport     = $self->{dbport};
  -
  -    die "ERROR: missing DBI driver and/or db name [$dbidriver,$dbname] in 
configuration.\n"
  -        if (!$dbidriver || !$dbname);
  -
  -    # NOTE: mysql_client_found_rows=true is important for the following 
condition.
  -    # If an update is executed against a row that exists, but its values do 
not change,
  -    # MySQL does not ordinarily report this as a row that has been affected 
by the
  -    # statement.  However, we occasionally need to know if the update found 
the row.
  -    # We really don't care if the values were changed or not.  To get this 
behavior,
  -    # we need to set this option.
  -
  -    my $dsn = "dbi:${dbidriver}:database=${dbname}";
  -    $dsn .= ";host=$dbhost" if ($dbhost);
  -    $dsn .= ";port=$dbport" if ($dbport);  # if $dbhost not supplied, 
$dbport is path to Unix socket
  -    $dsn .= ";mysql_client_found_rows=true";
  +    my $dbdriver   = "mysql";
  +    $self->{dbdriver} = $dbdriver if (!$self->{dbdriver});
  +
  +    my $dsn = $self->{dbdsn};
  +    if (!$dsn) {
  +        my $dbname     = $self->{dbname};
  +        my $dbuser     = $self->{dbuser};
  +        my $dbpass     = $self->{dbpass};
  +        my $dbschema   = $self->{dbschema};
  +        my $dbhost     = $self->{dbhost};
  +        my $dbport     = $self->{dbport};
  +
  +        die "ERROR: missing DBI driver and/or db name [$dbdriver,$dbname] in 
configuration.\n"
  +            if (!$dbdriver || !$dbname);
  +
  +        # NOTE: mysql_client_found_rows=true is important for the following 
condition.
  +        # If an update is executed against a row that exists, but its values 
do not change,
  +        # MySQL does not ordinarily report this as a row that has been 
affected by the
  +        # statement.  However, we occasionally need to know if the update 
found the row.
  +        # We really don't care if the values were changed or not.  To get 
this behavior,
  +        # we need to set this option.
  +
  +        $dsn = "dbi:${dbdriver}:database=${dbname}";
  +        $dsn .= ";host=$dbhost" if ($dbhost);
  +        $dsn .= ";port=$dbport" if ($dbport);  # if $dbhost not supplied, 
$dbport is path to Unix socket
  +        $dsn .= ";mysql_client_found_rows=true";
  +    }
   
       &App::sub_exit($dsn) if ($App::trace);
       return($dsn);
  
  
  

Reply via email to