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

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



Revision: 6347
          http://sourceforge.net/p/ledger-smb/code/6347
Author:   ehuelsmann
Date:     2014-01-02 13:24:32 +0000 (Thu, 02 Jan 2014)
Log Message:
-----------
In 1.3, reduce the number of warnings/errors in the logs
by checking the query has any chance of succeeding at all.

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

Modified: branches/1.3/LedgerSMB/Database.pm
===================================================================
--- branches/1.3/LedgerSMB/Database.pm	2014-01-02 11:46:07 UTC (rev 6346)
+++ branches/1.3/LedgerSMB/Database.pm	2014-01-02 13:24:32 UTC (rev 6347)
@@ -320,20 +320,42 @@
        $sth = $dbh->prepare("SELECT SESSION_USER");
        $sth->execute;
        $retval->{username} = $sth->fetchrow_array();
-       # Legacy SL and LSMB
-       $sth = $dbh->prepare('SELECT version FROM defaults');
-       #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;
-           }
-        }
+
+       # Is there a chance this is an SL or LSMB legacy version?
+       # (ie. is there a VERSION column to query in the DEFAULTS table?
+       $sth = $dbh->prepare(
+	   qq|select count(*)=1
+	        from pg_attribute attr
+	        join pg_class cls
+	          on cls.oid = attr.attrelid
+	        join pg_namespace nsp
+	          on nsp.oid = cls.relnamespace
+	       where cls.relname = 'defaults'
+	         and attr.attname='version'
+                 and nsp.nspname = 'public'
+             |
+	   );
+       $sth->execute();
+       my ($have_version_column) =
+	   $sth->fetchrow_array();
+       $sth->finish();
+
+       if ($have_version_column) {
+	   # Legacy SL and LSMB
+	   $sth = $dbh->prepare('SELECT version FROM defaults');
+	   #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

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


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits