mirror of
https://github.com/nextcloud/server.git
synced 2026-02-11 14:54:02 -05:00
- Fixed indentations.
- Fixed a bug in legacy.php: there was an error that was not checked for if the table 'fscache' did not exist in the database.
This commit is contained in:
parent
41ec976fd7
commit
4e5a3fbcaf
2 changed files with 78 additions and 72 deletions
144
lib/db.php
144
lib/db.php
|
|
@ -943,95 +943,95 @@ class PDOStatementWrapper{
|
|||
}
|
||||
}
|
||||
|
||||
private function tryFixSubstringLastArgumentDataForMSSQL($input) {
|
||||
$query = $this->statement->queryString;
|
||||
$pos = stripos ($query, 'SUBSTRING');
|
||||
|
||||
if ( $pos === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$newQuery = '';
|
||||
private function tryFixSubstringLastArgumentDataForMSSQL($input) {
|
||||
$query = $this->statement->queryString;
|
||||
$pos = stripos ($query, 'SUBSTRING');
|
||||
|
||||
$cArg = 0;
|
||||
if ( $pos === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$inSubstring = false;
|
||||
try {
|
||||
$newQuery = '';
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
$cArg = 0;
|
||||
|
||||
if (substr ($query, $i, 1) == '?') {
|
||||
// We found a question mark
|
||||
if ($inSubstring) {
|
||||
$newQuery .= $input[$cArg];
|
||||
$inSubstring = false;
|
||||
|
||||
//
|
||||
// Remove from input array
|
||||
//
|
||||
array_splice ($input, $cArg, 1);
|
||||
} else {
|
||||
$newQuery .= substr ($query, $i, 1);
|
||||
$cArg++;
|
||||
}
|
||||
} else {
|
||||
$newQuery .= substr ($query, $i, 1);
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (substr ($query, $i, 1) == '?') {
|
||||
// We found a question mark
|
||||
if ($inSubstring) {
|
||||
$newQuery .= $input[$cArg];
|
||||
|
||||
if ($port) {
|
||||
$dsn = 'sqlsrv:Server='.$host.','.$port.';Database='.$name;
|
||||
} else {
|
||||
$dsn = 'sqlsrv:Server='.$host.';Database='.$name;
|
||||
}
|
||||
//
|
||||
// Remove from input array
|
||||
//
|
||||
array_splice ($input, $cArg, 1);
|
||||
} else {
|
||||
$newQuery .= substr ($query, $i, 1);
|
||||
$cArg++;
|
||||
}
|
||||
} else {
|
||||
$newQuery .= substr ($query, $i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
$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);
|
||||
// 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();
|
||||
|
||||
$this->statement = $PDO->prepare($newQuery);
|
||||
if ($port) {
|
||||
$dsn = 'sqlsrv:Server='.$host.','.$port.';Database='.$name;
|
||||
} else {
|
||||
$dsn = 'sqlsrv:Server='.$host.';Database='.$name;
|
||||
}
|
||||
|
||||
$this->lastArguments = $input;
|
||||
|
||||
return $input;
|
||||
} catch (PDOException $e){
|
||||
$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().'"<br />';
|
||||
$entry .= 'Offending command was: '.$this->statement->queryString .'<br />';
|
||||
$entry .= 'Input parameters: ' .print_r($input, true).'<br />';
|
||||
$entry .= 'Stack trace: ' .$e->getTraceAsString().'<br />';
|
||||
OC_Log::write('core', $entry, OC_Log::FATAL);
|
||||
OC_User::setUserId(null);
|
||||
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);
|
||||
// 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 numRows
|
||||
|
|
|
|||
6
lib/files/cache/legacy.php
vendored
6
lib/files/cache/legacy.php
vendored
|
|
@ -51,6 +51,12 @@ class Legacy {
|
|||
$this->cacheHasItems = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($result === false || property_exists($result, 'error_message_prefix')) {
|
||||
$this->cacheHasItems = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->cacheHasItems = (bool)$result->fetchRow();
|
||||
return $this->cacheHasItems;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue