[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[4170] branches/1.3/LedgerSMB/Database.pm



Revision: 4170
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4170&view=rev
Author:   tshvr
Date:     2011-12-08 21:17:04 +0000 (Thu, 08 Dec 2011)
Log Message:
-----------
try to make dbh available to upper level,leave disconnect to upper level,avoid fetchrow failed msg

Modified Paths:
--------------
    branches/1.3/LedgerSMB/Database.pm

Modified: branches/1.3/LedgerSMB/Database.pm
===================================================================
--- branches/1.3/LedgerSMB/Database.pm	2011-12-08 20:51:37 UTC (rev 4169)
+++ branches/1.3/LedgerSMB/Database.pm	2011-12-08 21:17:04 UTC (rev 4170)
@@ -264,6 +264,7 @@
     full_version => undef,
           status => undef,
     };
+    $logger->debug("\$self->{dbh}=$self->{dbh}");
     my $creds = LedgerSMB::Auth->get_credentials();
     my $dbh = DBI->connect(
         "dbi:Pg:dbname=$self->{company_name}", 
@@ -276,6 +277,8 @@
                    "$creds->{login}", "$creds->{password}", { AutoCommit => 0 }
             );
            return $retval unless $dbh;
+           $logger->debug("DBI->connect dbh=$dbh");
+           $self->{dbh}=$dbh;#make available to upper levels
            my $sth = $dbh->prepare(
                  "select count(*) = 1 from pg_database where datname = ?"
            );
@@ -292,20 +295,26 @@
            return $retval;
    } else { # Got a db handle... try to find the version and app by a few
             # different means
+       $logger->debug("DBI->connect dbh=$dbh");
+       $self->{dbh}=$dbh;#make it available to upper levels
        my $sth;
        $sth = $dbh->prepare("SELECT SESSION_USER");
        $sth->execute;
        $retval->{username} = $sth->fetchrow_array();
        # Legacy SL and LSMB
        $sth = $dbh->prepare('SELECT version FROM defaults');
-       $sth->execute();
-       if (my ($ref) = $sth->fetchrow_hashref('NAME_lc')){
+       #avoid DBD::Pg::st fetchrow_hashref failed: no statement executing
+       my $rv=$sth->execute();     
+       if(defined($rv))
+       {
+        if (my ($ref) = $sth->fetchrow_hashref('NAME_lc')){
            if ($ref->{version}){
                $retval->{appname} = 'ledgersmb';
                $retval->{version} = 'legacy';
                $retval->{full_version} = $ref->{version};
                return $retval;
            }
+        }
        }
        $dbh->rollback;
        # LedgerSMB 1.2 and above
@@ -337,7 +346,8 @@
        }
        $dbh->rollback;
    }
-   $dbh->disconnect;
+   #$logger->debug("DBI->disconnect dbh=$dbh");
+   #$dbh->disconnect;#leave disconnect to upper level
    return $retval;
 }
 

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.