aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/DB')
-rw-r--r--lib/private/DB/QueryBuilder/CompositeExpression.php10
-rw-r--r--lib/private/DB/QueryBuilder/QueryBuilder.php37
2 files changed, 42 insertions, 5 deletions
diff --git a/lib/private/DB/QueryBuilder/CompositeExpression.php b/lib/private/DB/QueryBuilder/CompositeExpression.php
index 512343662ad..ae9e654d5bb 100644
--- a/lib/private/DB/QueryBuilder/CompositeExpression.php
+++ b/lib/private/DB/QueryBuilder/CompositeExpression.php
@@ -45,7 +45,7 @@ class CompositeExpression implements ICompositeExpression, \Countable {
*
* @return \OCP\DB\QueryBuilder\ICompositeExpression
*/
- public function addMultiple(array $parts = []) {
+ public function addMultiple(array $parts = []): ICompositeExpression {
$this->compositeExpression->addMultiple($parts);
return $this;
@@ -58,7 +58,7 @@ class CompositeExpression implements ICompositeExpression, \Countable {
*
* @return \OCP\DB\QueryBuilder\ICompositeExpression
*/
- public function add($part) {
+ public function add($part): ICompositeExpression {
$this->compositeExpression->add($part);
return $this;
@@ -69,7 +69,7 @@ class CompositeExpression implements ICompositeExpression, \Countable {
*
* @return integer
*/
- public function count() {
+ public function count(): int {
return $this->compositeExpression->count();
}
@@ -78,7 +78,7 @@ class CompositeExpression implements ICompositeExpression, \Countable {
*
* @return string
*/
- public function getType() {
+ public function getType(): string {
return $this->compositeExpression->getType();
}
@@ -87,7 +87,7 @@ class CompositeExpression implements ICompositeExpression, \Countable {
*
* @return string
*/
- public function __toString() {
+ public function __toString(): string {
return (string) $this->compositeExpression;
}
}
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php
index 35b7240abfe..3549606c2db 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.
*