Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve query type detection
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Nov 6, 2020
commit 3d2f71cfa9a38a0db8be7dc6111e61b67b17695e
15 changes: 9 additions & 6 deletions lib/private/legacy/OC_DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public static function prepare($query , $limit = null, $offset = null, $isManipu
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);
}

/**
Expand All @@ -85,22 +84,26 @@ public static function prepare($query , $limit = null, $offset = null, $isManipu
* @return bool
*/
public static 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;
}

Expand Down