summaryrefslogtreecommitdiffstats
path: root/lib/private/DB
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-10-24 11:51:32 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2021-03-04 14:03:31 +0100
commit76a6328d10ceaf6774d205a04338782e577512ee (patch)
tree1981e97e681b877c86bb2d2ebdda6b437316946a /lib/private/DB
parent9b573c6bd5df281833f455c9770826bc74283d5d (diff)
downloadnextcloud-server-76a6328d10ceaf6774d205a04338782e577512ee.tar.gz
nextcloud-server-76a6328d10ceaf6774d205a04338782e577512ee.zip
Add executeQuery and executeUpdate
Names shamelessly copied from Doctrine itself. Internally it is still using the same flow. But I added some checks around it. This should make static analysis a bit more happy. Which in turn makes me more happy. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/DB')
-rw-r--r--lib/private/DB/QueryBuilder/QueryBuilder.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php
index aa0327e89d9..83b233ac1b5 100644
--- a/lib/private/DB/QueryBuilder/QueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/QueryBuilder.php
@@ -291,6 +291,43 @@ class QueryBuilder implements IQueryBuilder {
return new ResultAdapter($result);
}
+ public function executeQuery(): IResult {
+ if ($this->getType() !== \Doctrine\DBAL\Query\QueryBuilder::SELECT) {
+ throw new \RuntimeException('Invalid query type, expected SELECT query');
+ }
+
+ try {
+ $result = $this->execute();
+ } catch (\Doctrine\DBAL\Exception $e) {
+ throw \OC\DB\Exceptions\DbalException::wrap($e);
+ }
+
+ if ($result instanceof IResult) {
+ return $result;
+ }
+
+ throw new \RuntimeException('Invalid return type for query');
+ }
+
+ public function executeUpdate(): int {
+ if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::SELECT) {
+ throw new \RuntimeException('Invalid query type, expected INSERT, DELETE or UPDATE query');
+ }
+
+ try {
+ $result = $this->execute();
+ } catch (\Doctrine\DBAL\Exception $e) {
+ throw \OC\DB\Exceptions\DbalException::wrap($e);
+ }
+
+ if (!is_int($result)) {
+ throw new \RuntimeException('Invalid return type for query');
+ }
+
+ return $result;
+ }
+
+
/**
* Gets the complete SQL string formed by the current specifications of this QueryBuilder.
*