]> source.dussan.org Git - nextcloud-server.git/commitdiff
remove unnecessary exception handling
authorJörn Friedrich Dreyer <jfd@butonic.de>
Thu, 20 Jun 2013 08:27:02 +0000 (10:27 +0200)
committerJörn Friedrich Dreyer <jfd@butonic.de>
Thu, 20 Jun 2013 08:50:53 +0000 (10:50 +0200)
lib/db.php

index a6b81aaba69afd943091274ce2fe72390eefe808..66900f46be966285d32e6e79abde93a09d8fc54e 100644 (file)
@@ -180,28 +180,18 @@ class OC_DB {
                                                        $dsn = 'oci:dbname=//' . $host . '/' . $name;
                                        }
                                        break;
-                case 'mssql':
+                               case 'mssql':
                                        if ($port) {
                                                        $dsn='sqlsrv:Server='.$host.','.$port.';Database='.$name;
                                        } else {
                                                        $dsn='sqlsrv:Server='.$host.';Database='.$name;
                                        }
-                                       break;                    
+                                       break;
                                default:
                                        return false;
                        }
-                       try{
-                               self::$PDO=new PDO($dsn, $user, $pass, $opts);
-                       }catch(PDOException $e) {
-                               OC_Log::write('core', $e->getMessage(), OC_Log::FATAL);
-                               OC_User::setUserId(null);
-
-                               // send http status 503
-                               header('HTTP/1.1 503 Service Temporarily Unavailable');
-                               header('Status: 503 Service Temporarily Unavailable');
-                               OC_Template::printErrorPage('Failed to connect to database');
-                               die();
-                       }
+                       self::$PDO=new PDO($dsn, $user, $pass, $opts);
+                       
                        // We always, really always want associative arrays
                        self::$PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
                        self::$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@@ -299,19 +289,8 @@ class OC_DB {
 
                        // Try to establish connection
                        self::$MDB2 = MDB2::factory( $dsn, $options );
-
-                       // Die if we could not connect
-                       if( PEAR::isError( self::$MDB2 )) {
-                               OC_Log::write('core', self::$MDB2->getUserInfo(), OC_Log::FATAL);
-                               OC_Log::write('core', self::$MDB2->getMessage(), OC_Log::FATAL);
-                               OC_User::setUserId(null);
-
-                               // send http status 503
-                               header('HTTP/1.1 503 Service Temporarily Unavailable');
-                               header('Status: 503 Service Temporarily Unavailable');
-                               OC_Template::printErrorPage('Failed to connect to database');
-                               die();
-                       }
+                       
+                       self::raiseExceptionOnError( self::$MDB2 );
 
                        // We always, really always want associative arrays
                        self::$MDB2->setFetchMode(MDB2_FETCHMODE_ASSOC);
@@ -760,9 +739,9 @@ class OC_DB {
                        $query = str_replace( 'now()', 'CURRENT_TIMESTAMP', $query );
                        $query = str_replace( 'LENGTH(', 'LEN(', $query );
                        $query = str_replace( 'SUBSTR(', 'SUBSTRING(', $query );
-            
-            $query = self::fixLimitClauseForMSSQL($query);
-        }
+
+                       $query = self::fixLimitClauseForMSSQL($query);
+               }
 
                // replace table name prefix
                $query = str_replace( '*PREFIX*', $prefix, $query );
@@ -770,60 +749,60 @@ class OC_DB {
                return $query;
        }
 
-    private static function fixLimitClauseForMSSQL($query) {
-        $limitLocation = stripos ($query, "LIMIT");
-        
-        if ( $limitLocation === false ) {
-            return $query;
-        } 
-        
-        // total == 0 means all results - not zero results
-        //
-        // First number is either total or offset, locate it by first space
-        //
-        $offset = substr ($query, $limitLocation + 5);
-        $offset = substr ($offset, 0, stripos ($offset, ' '));
-        $offset = trim ($offset);
-
-        // check for another parameter
-        if (stripos ($offset, ',') === false) {
-            // no more parameters
-            $offset = 0;
-            $total = intval ($offset);
-        } else {
-            // found another parameter
-            $offset = intval ($offset);
-
-            $total = substr ($query, $limitLocation + 5);
-            $total = substr ($total, stripos ($total, ','));
-
-            $total = substr ($total, 0, stripos ($total, ' '));
-            $total = intval ($total);
-        }
-
-        $query = trim (substr ($query, 0, $limitLocation));
-
-        if ($offset == 0 && $total !== 0) {
-            if (strpos($query, "SELECT") === false) {
-                $query = "TOP {$total} " . $query;
-            } else {
-                $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query);
-            }
-        } else if ($offset > 0) {
-            $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query);
-            $query = 'SELECT *
-                    FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3
-                    FROM (SELECT 1 AS line2, sub1.* FROM (' . $query . ') AS sub1) as sub2) AS sub3';
-
-            if ($total > 0) {
-                $query .= ' WHERE line3 BETWEEN ' . ($offset + 1) . ' AND ' . ($offset + $total);
-            } else {
-                $query .= ' WHERE line3 > ' . $offset;
-            }
-        }
-        return $query;
-    }
-    
+       private static function fixLimitClauseForMSSQL($query) {
+               $limitLocation = stripos ($query, "LIMIT");
+
+               if ( $limitLocation === false ) {
+                       return $query;
+               
+
+               // total == 0 means all results - not zero results
+               //
+               // First number is either total or offset, locate it by first space
+               //
+               $offset = substr ($query, $limitLocation + 5);
+               $offset = substr ($offset, 0, stripos ($offset, ' '));
+               $offset = trim ($offset);
+
+               // check for another parameter
+               if (stripos ($offset, ',') === false) {
+                       // no more parameters
+                       $offset = 0;
+                       $total = intval ($offset);
+               } else {
+                       // found another parameter
+                       $offset = intval ($offset);
+
+                       $total = substr ($query, $limitLocation + 5);
+                       $total = substr ($total, stripos ($total, ','));
+
+                       $total = substr ($total, 0, stripos ($total, ' '));
+                       $total = intval ($total);
+               }
+
+               $query = trim (substr ($query, 0, $limitLocation));
+
+               if ($offset == 0 && $total !== 0) {
+                       if (strpos($query, "SELECT") === false) {
+                               $query = "TOP {$total} " . $query;
+                       } else {
+                               $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP '.$total, $query);
+                       }
+               } else if ($offset > 0) {
+                       $query = preg_replace('/SELECT(\s*DISTINCT)?/Dsi', 'SELECT$1 TOP(10000000) ', $query);
+                       $query = 'SELECT *
+                                       FROM (SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3
+                                       FROM (SELECT 1 AS line2, sub1.* FROM (' . $query . ') AS sub1) as sub2) AS sub3';
+
+                       if ($total > 0) {
+                               $query .= ' WHERE line3 BETWEEN ' . ($offset + 1) . ' AND ' . ($offset + $total);
+                       } else {
+                               $query .= ' WHERE line3 > ' . $offset;
+                       }
+               }
+               return $query;
+       }
+
        /**
         * @brief drop a table
         * @param string $tableName the table to drop
@@ -1124,7 +1103,7 @@ class PDOStatementWrapper{
                        die ($entry);
                }
        }
-    
+
        /**
         * provide numRows
         */