From: Lukas Reschke Date: Wed, 25 Feb 2015 13:08:44 +0000 (+0100) Subject: Remove hacky Substring support for MSSQL X-Git-Tag: v7.0.6RC1~15^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=51017e43a010c79280d99c430c35ef86fd4eefcf;p=nextcloud-server.git Remove hacky Substring support for MSSQL Substring() is not required for the core functionality and this allows us to get rid of a huge hack... --- diff --git a/lib/private/db/statementwrapper.php b/lib/private/db/statementwrapper.php index 93fabc147ca..fb687f15437 100644 --- a/lib/private/db/statementwrapper.php +++ b/lib/private/db/statementwrapper.php @@ -51,15 +51,6 @@ class OC_DB_StatementWrapper { } $this->lastArguments = $input; if (count($input) > 0) { - - if (!isset($type)) { - $type = OC_Config::getValue( "dbtype", "sqlite" ); - } - - if ($type == 'mssql') { - $input = $this->tryFixSubstringLastArgumentDataForMSSQL($input); - } - $result = $this->statement->execute($input); } else { $result = $this->statement->execute(); @@ -74,96 +65,6 @@ class OC_DB_StatementWrapper { return $this; } } - - private function tryFixSubstringLastArgumentDataForMSSQL($input) { - $query = $this->statement->getWrappedStatement()->queryString; - $pos = stripos ($query, 'SUBSTRING'); - - if ( $pos === false) { - return $input; - } - - try { - $newQuery = ''; - - $cArg = 0; - - $inSubstring = false; - - // Create new query - for ($i = 0; $i < strlen ($query); $i++) { - if ($inSubstring == false) { - // Defines when we should start inserting values - if (substr ($query, $i, 9) == 'SUBSTRING') { - $inSubstring = true; - } - } else { - // Defines when we should stop inserting values - if (substr ($query, $i, 1) == ')') { - $inSubstring = false; - } - } - - if (substr ($query, $i, 1) == '?') { - // We found a question mark - if ($inSubstring) { - $newQuery .= $input[$cArg]; - - // - // Remove from input array - // - array_splice ($input, $cArg, 1); - } else { - $newQuery .= substr ($query, $i, 1); - $cArg++; - } - } else { - $newQuery .= substr ($query, $i, 1); - } - } - - // The global data we need - $name = OC_Config::getValue( "dbname", "owncloud" ); - $host = OC_Config::getValue( "dbhost", "" ); - $user = OC_Config::getValue( "dbuser", "" ); - $pass = OC_Config::getValue( "dbpassword", "" ); - if (strpos($host, ':')) { - list($host, $port) = explode(':', $host, 2); - } else { - $port = false; - } - $opts = array(); - - if ($port) { - $dsn = 'sqlsrv:Server='.$host.','.$port.';Database='.$name; - } else { - $dsn = 'sqlsrv:Server='.$host.';Database='.$name; - } - - $PDO = new PDO($dsn, $user, $pass, $opts); - $PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); - $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - - $this->statement = $PDO->prepare($newQuery); - - $this->lastArguments = $input; - - return $input; - } catch (PDOException $e){ - $entry = 'PDO DB Error: "'.$e->getMessage().'"
'; - $entry .= 'Offending command was: '.$this->statement->queryString .'
'; - $entry .= 'Input parameters: ' .print_r($input, true).'
'; - $entry .= 'Stack trace: ' .$e->getTraceAsString().'
'; - OC_Log::write('core', $entry, 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 ($entry); - } - } /** * provide an alias for fetch