summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-07-01 14:37:09 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-07-01 14:37:09 -0700
commitbf901eb52f80692eb945ef5608f0ed58bbce3e26 (patch)
tree73e791cc2577beeaad907a74e528577a1a7ef31c /lib
parent5fff4e0d087378984fe7124013acc6741903379f (diff)
parent372f261fe304463a67fc347b0e1c345653332ed3 (diff)
downloadnextcloud-server-bf901eb52f80692eb945ef5608f0ed58bbce3e26.tar.gz
nextcloud-server-bf901eb52f80692eb945ef5608f0ed58bbce3e26.zip
Merge pull request #3793 from owncloud/remove_unnecessary_exception_catch_block
remove unnecessary try catch blocks
Diffstat (limited to 'lib')
-rw-r--r--lib/db.php149
1 files changed, 64 insertions, 85 deletions
diff --git a/lib/db.php b/lib/db.php
index 4d6788f2bda..3e2e5bc2194 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -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);
@@ -803,9 +782,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 );
@@ -813,60 +792,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
@@ -1172,7 +1151,7 @@ class PDOStatementWrapper{
die ($entry);
}
}
-
+
/**
* provide numRows
*/