mirror of
https://github.com/nextcloud/server.git
synced 2026-05-19 08:25:56 -04:00
Improve query type detection
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
49d61911b8
commit
92d8d339e3
1 changed files with 9 additions and 6 deletions
|
|
@ -72,8 +72,7 @@ class OC_DB {
|
|||
throw new \OC\DatabaseException($e->getMessage());
|
||||
}
|
||||
// differentiate between query and manipulation
|
||||
$result = new OC_DB_StatementWrapper($result, $isManipulation);
|
||||
return $result;
|
||||
return new OC_DB_StatementWrapper($result, $isManipulation);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,22 +83,26 @@ class OC_DB {
|
|||
* @return bool
|
||||
*/
|
||||
static public function isManipulation( $sql ) {
|
||||
$sql = trim($sql);
|
||||
$selectOccurrence = stripos($sql, 'SELECT');
|
||||
if ($selectOccurrence !== false && $selectOccurrence < 10) {
|
||||
if ($selectOccurrence === 0) {
|
||||
return false;
|
||||
}
|
||||
$insertOccurrence = stripos($sql, 'INSERT');
|
||||
if ($insertOccurrence !== false && $insertOccurrence < 10) {
|
||||
if ($insertOccurrence === 0) {
|
||||
return true;
|
||||
}
|
||||
$updateOccurrence = stripos($sql, 'UPDATE');
|
||||
if ($updateOccurrence !== false && $updateOccurrence < 10) {
|
||||
if ($updateOccurrence === 0) {
|
||||
return true;
|
||||
}
|
||||
$deleteOccurrence = stripos($sql, 'DELETE');
|
||||
if ($deleteOccurrence !== false && $deleteOccurrence < 10) {
|
||||
if ($deleteOccurrence === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
\OC::$server->getLogger()->logException(new \Exception('Can not detect if query is manipulating: ' . $sql));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue