aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-01-04 08:50:10 +0100
committerJoas Schilling <coding@schilljs.com>2022-01-04 09:15:17 +0100
commit46ad6fa3c7ff8a2c6ab0d7ff583cab19ba04b146 (patch)
treedaea2f7b774846d187bd8f255851c7dcec96f1cb /lib/private
parente3e73a12ef42b45f773da7e18090938ed3ff1ef3 (diff)
downloadnextcloud-server-46ad6fa3c7ff8a2c6ab0d7ff583cab19ba04b146.tar.gz
nextcloud-server-46ad6fa3c7ff8a2c6ab0d7ff583cab19ba04b146.zip
Add a test with integer
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php18
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php6
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php8
-rw-r--r--lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php2
-rw-r--r--lib/private/DB/QueryBuilder/QueryBuilder.php8
5 files changed, 26 insertions, 16 deletions
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
index 6b5fb751fbd..37518bda3ec 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
@@ -26,23 +26,23 @@ namespace OC\DB\QueryBuilder\FunctionBuilder;
use OC\DB\QueryBuilder\QueryFunction;
use OC\DB\QueryBuilder\QuoteHelper;
use OCP\DB\QueryBuilder\IFunctionBuilder;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
class FunctionBuilder implements IFunctionBuilder {
- /** @var QuoteHelper */
- protected $helper;
-
/** @var IDBConnection */
protected $connection;
- /**
- * ExpressionBuilder constructor.
- *
- * @param QuoteHelper $helper
- */
- public function __construct(IDBConnection $connection, QuoteHelper $helper) {
+ /** @var IQueryBuilder */
+ protected $queryBuilder;
+
+ /** @var QuoteHelper */
+ protected $helper;
+
+ public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder, QuoteHelper $helper) {
$this->connection = $connection;
+ $this->queryBuilder = $queryBuilder;
$this->helper = $helper;
}
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php
index 45a1e1c1ff6..a3e62e6d330 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php
@@ -26,6 +26,7 @@ namespace OC\DB\QueryBuilder\FunctionBuilder;
use OC\DB\QueryBuilder\QueryFunction;
use OCP\DB\QueryBuilder\ILiteral;
use OCP\DB\QueryBuilder\IParameter;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
class OCIFunctionBuilder extends FunctionBuilder {
@@ -78,6 +79,11 @@ class OCIFunctionBuilder extends FunctionBuilder {
if (is_null($separator)) {
return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr) . ')' . $orderByClause);
}
+
+ if ($separator === '\'') {
+ $separator = '\\\'';
+ }
+
return new QueryFunction('LISTAGG(' . $this->helper->quoteColumnName($expr) . ", '$separator')$orderByClause");
}
}
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php
index f4c1364fab1..0b22775acc8 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/PgSqlFunctionBuilder.php
@@ -24,6 +24,7 @@
namespace OC\DB\QueryBuilder\FunctionBuilder;
use OC\DB\QueryBuilder\QueryFunction;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
class PgSqlFunctionBuilder extends FunctionBuilder {
@@ -32,10 +33,13 @@ class PgSqlFunctionBuilder extends FunctionBuilder {
}
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
+ $castedExpression = $this->queryBuilder->expr()->castColumn($expr, IQueryBuilder::PARAM_STR);
+
if (is_null($separator)) {
- return new QueryFunction('string_agg(cast(' . $this->helper->quoteColumnName($expr) . ' AS varchar)');
+ return new QueryFunction('string_agg(' . $castedExpression . ')');
}
+
$separator = $this->connection->quote($separator);
- return new QueryFunction('string_agg(cast(' . $this->helper->quoteColumnName($expr) . " AS varchar), $separator)");
+ return new QueryFunction('string_agg(' . $castedExpression . ', ' . $separator . ')');
}
}
diff --git a/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php b/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php
index 74e4e30e7ff..1067f8f0925 100644
--- a/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php
+++ b/lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php
@@ -33,7 +33,7 @@ class SqliteFunctionBuilder extends FunctionBuilder {
public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
$separator = $this->connection->quote($separator);
- return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ", $separator)");
+ return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ', ' . $separator . ')');
}
public function greatest($x, $y): IQueryFunction {
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php
index e247d1a8c00..a362ff8016e 100644
--- a/lib/private/DB/QueryBuilder/QueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/QueryBuilder.php
@@ -155,16 +155,16 @@ class QueryBuilder implements IQueryBuilder {
*/
public function func() {
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
- return new OCIFunctionBuilder($this->connection, $this->helper);
+ return new OCIFunctionBuilder($this->connection, $this, $this->helper);
}
if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
- return new SqliteFunctionBuilder($this->connection, $this->helper);
+ return new SqliteFunctionBuilder($this->connection, $this, $this->helper);
}
if ($this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) {
- return new PgSqlFunctionBuilder($this->connection, $this->helper);
+ return new PgSqlFunctionBuilder($this->connection, $this, $this->helper);
}
- return new FunctionBuilder($this->connection, $this->helper);
+ return new FunctionBuilder($this->connection, $this, $this->helper);
}
/**