diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 01c8671f8ad..6feb5778063 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1361,6 +1361,7 @@ return array( 'OC\\DB\\ResultAdapter' => $baseDir . '/lib/private/DB/ResultAdapter.php', 'OC\\DB\\SQLiteMigrator' => $baseDir . '/lib/private/DB/SQLiteMigrator.php', 'OC\\DB\\SchemaWrapper' => $baseDir . '/lib/private/DB/SchemaWrapper.php', + 'OC\\DB\\TDoctrineParameterTypeMap' => $baseDir . '/lib/private/DB/TDoctrineParameterTypeMap.php', 'OC\\Dashboard\\Manager' => $baseDir . '/lib/private/Dashboard/Manager.php', 'OC\\DatabaseException' => $baseDir . '/lib/private/DatabaseException.php', 'OC\\DatabaseSetupException' => $baseDir . '/lib/private/DatabaseSetupException.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index fc271f585d7..f717c664d2e 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1394,6 +1394,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\DB\\ResultAdapter' => __DIR__ . '/../../..' . '/lib/private/DB/ResultAdapter.php', 'OC\\DB\\SQLiteMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/SQLiteMigrator.php', 'OC\\DB\\SchemaWrapper' => __DIR__ . '/../../..' . '/lib/private/DB/SchemaWrapper.php', + 'OC\\DB\\TDoctrineParameterTypeMap' => __DIR__ . '/../../..' . '/lib/private/DB/TDoctrineParameterTypeMap.php', 'OC\\Dashboard\\Manager' => __DIR__ . '/../../..' . '/lib/private/Dashboard/Manager.php', 'OC\\DatabaseException' => __DIR__ . '/../../..' . '/lib/private/DatabaseException.php', 'OC\\DatabaseSetupException' => __DIR__ . '/../../..' . '/lib/private/DatabaseSetupException.php', diff --git a/lib/private/DB/PreparedStatement.php b/lib/private/DB/PreparedStatement.php index 9f6872f1d2b..84669cc992f 100644 --- a/lib/private/DB/PreparedStatement.php +++ b/lib/private/DB/PreparedStatement.php @@ -8,8 +8,6 @@ declare(strict_types=1); */ namespace OC\DB; -use Doctrine\DBAL\Exception; -use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; use OCP\DB\IPreparedStatement; use OCP\DB\IResult; @@ -26,6 +24,8 @@ use PDO; * methods without much magic. */ class PreparedStatement implements IPreparedStatement { + use TDoctrineParameterTypeMap; + /** @var Statement */ private $statement; @@ -58,12 +58,12 @@ class PreparedStatement implements IPreparedStatement { return $this->getResult()->fetchOne(); } - public function bindValue($param, $value, $type = ParameterType::STRING): bool { - $this->statement->bindValue($param, $value, $type); + public function bindValue($param, $value, $type = IQueryBuilder::PARAM_STR): bool { + $this->statement->bindValue($param, $value, $this->convertParameterTypeToDoctrine($type)); return true; } - public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool { + public function bindParam($param, &$variable, $type = IQueryBuilder::PARAM_STR, $length = null): bool { if ($type !== IQueryBuilder::PARAM_STR) { \OC::$server->getLogger()->warning('PreparedStatement::bindParam() is no longer supported. Use bindValue() instead.', ['exception' => new \BadMethodCallException('bindParam() is no longer supported')]); } diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index 97f80baa244..e9b9fa467e1 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -22,6 +22,7 @@ use OC\DB\QueryBuilder\FunctionBuilder\OCIFunctionBuilder; use OC\DB\QueryBuilder\FunctionBuilder\PgSqlFunctionBuilder; use OC\DB\QueryBuilder\FunctionBuilder\SqliteFunctionBuilder; use OC\DB\ResultAdapter; +use OC\DB\TDoctrineParameterTypeMap; use OC\SystemConfig; use OCP\DB\IResult; use OCP\DB\QueryBuilder\ICompositeExpression; @@ -33,6 +34,8 @@ use OCP\IDBConnection; use Psr\Log\LoggerInterface; class QueryBuilder implements IQueryBuilder { + use TDoctrineParameterTypeMap; + /** @internal */ protected const SELECT = 0; @@ -350,7 +353,7 @@ class QueryBuilder implements IQueryBuilder { * @return $this This QueryBuilder instance. */ public function setParameter($key, $value, $type = null) { - $this->queryBuilder->setParameter($key, $value, $type); + $this->queryBuilder->setParameter($key, $value, $this->convertParameterTypeToDoctrine($type)); return $this; } @@ -375,6 +378,7 @@ class QueryBuilder implements IQueryBuilder { * @return $this This QueryBuilder instance. */ public function setParameters(array $params, array $types = []) { + $types = array_map($this->convertParameterTypeToDoctrine(...), $types); $this->queryBuilder->setParameters($params, $types); return $this; @@ -1223,7 +1227,7 @@ class QueryBuilder implements IQueryBuilder { * @return IParameter the placeholder name used. */ public function createNamedParameter($value, $type = IQueryBuilder::PARAM_STR, $placeHolder = null) { - return new Parameter($this->queryBuilder->createNamedParameter($value, $type, $placeHolder)); + return new Parameter($this->queryBuilder->createNamedParameter($value, $this->convertParameterTypeToDoctrine($type), $placeHolder)); } /** @@ -1249,7 +1253,7 @@ class QueryBuilder implements IQueryBuilder { * @return IParameter */ public function createPositionalParameter($value, $type = IQueryBuilder::PARAM_STR) { - return new Parameter($this->queryBuilder->createPositionalParameter($value, $type)); + return new Parameter($this->queryBuilder->createPositionalParameter($value, $this->convertParameterTypeToDoctrine($type))); } /** diff --git a/lib/private/DB/TDoctrineParameterTypeMap.php b/lib/private/DB/TDoctrineParameterTypeMap.php new file mode 100644 index 00000000000..f4e06fd9a0c --- /dev/null +++ b/lib/private/DB/TDoctrineParameterTypeMap.php @@ -0,0 +1,31 @@ + $type, + IQueryBuilder::PARAM_NULL => ParameterType::NULL, + IQueryBuilder::PARAM_BOOL => ParameterType::BOOLEAN, + IQueryBuilder::PARAM_INT => ParameterType::INTEGER, + null, + IQueryBuilder::PARAM_STR => ParameterType::STRING, + IQueryBuilder::PARAM_LOB => ParameterType::LARGE_OBJECT, + IQueryBuilder::PARAM_INT_ARRAY => ArrayParameterType::INTEGER, + IQueryBuilder::PARAM_STR_ARRAY => ArrayParameterType::STRING, + }; + } + +} diff --git a/lib/public/DB/IPreparedStatement.php b/lib/public/DB/IPreparedStatement.php index d77f677b719..e2a72bd4a27 100644 --- a/lib/public/DB/IPreparedStatement.php +++ b/lib/public/DB/IPreparedStatement.php @@ -9,7 +9,7 @@ declare(strict_types=1); namespace OCP\DB; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\ParameterType; +use OCP\DB\QueryBuilder\IQueryBuilder; use PDO; /** @@ -80,7 +80,7 @@ interface IPreparedStatement { * * @since 21.0.0 */ - public function bindValue($param, $value, $type = ParameterType::STRING): bool; + public function bindValue($param, $value, $type = IQueryBuilder::PARAM_STR): bool; /** * @param int|string $param @@ -95,7 +95,7 @@ interface IPreparedStatement { * @since 21.0.0 * @deprecated 30.0.0 Use {@see self::bindValue()} instead */ - public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool; + public function bindParam($param, &$variable, $type = IQueryBuilder::PARAM_STR, $length = null): bool; /** * @param mixed[]|null $params diff --git a/lib/public/DB/QueryBuilder/IQueryBuilder.php b/lib/public/DB/QueryBuilder/IQueryBuilder.php index 7d9d56a1f90..4d6ab1bd592 100644 --- a/lib/public/DB/QueryBuilder/IQueryBuilder.php +++ b/lib/public/DB/QueryBuilder/IQueryBuilder.php @@ -23,23 +23,23 @@ interface IQueryBuilder { /** * @since 9.0.0 */ - public const PARAM_NULL = ParameterType::NULL; + public const PARAM_NULL = 0; // Translates to ParameterType::NULL; /** * @since 9.0.0 */ - public const PARAM_BOOL = ParameterType::BOOLEAN; + public const PARAM_BOOL = 4; // Translates to ParameterType::BOOLEAN; /** * @since 9.0.0 */ - public const PARAM_INT = ParameterType::INTEGER; + public const PARAM_INT = 1; // Translates to ParameterType::INTEGER; /** * @since 9.0.0 */ - public const PARAM_STR = ParameterType::STRING; + public const PARAM_STR = 2; // Translates to ParameterType::STRING; /** * @since 9.0.0 */ - public const PARAM_LOB = ParameterType::LARGE_OBJECT; + public const PARAM_LOB = 3; // Translates to ParameterType::LARGE_OBJECT; /** * @since 9.0.0 */ @@ -53,11 +53,11 @@ interface IQueryBuilder { /** * @since 9.0.0 */ - public const PARAM_INT_ARRAY = ArrayParameterType::INTEGER; + public const PARAM_INT_ARRAY = 100; // Translates to ArrayParameterType::INTEGER; /** * @since 9.0.0 */ - public const PARAM_STR_ARRAY = ArrayParameterType::STRING; + public const PARAM_STR_ARRAY = 101; // Translates to ArrayParameterType::STRING; /** * @since 24.0.0 Indicates how many rows can be deleted at once with MySQL