reuse query builder

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-01-12 13:44:30 +01:00
parent aad01894e3
commit 42b3aa3a0a
No known key found for this signature in database
GPG Key ID: CBCA68FBAEBF98C9
4 changed files with 16 additions and 11 deletions

View File

@ -52,13 +52,14 @@ class ExpressionBuilder implements IExpressionBuilder {
/** /**
* Initializes a new <tt>ExpressionBuilder</tt>. * Initializes a new <tt>ExpressionBuilder</tt>.
* *
* @param \OCP\IDBConnection $connection * @param IDBConnection $connection
* @param IQueryBuilder $queryBuilder
*/ */
public function __construct(IDBConnection $connection) { public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder) {
$this->connection = $connection; $this->connection = $connection;
$this->helper = new QuoteHelper(); $this->helper = new QuoteHelper();
$this->expressionBuilder = new DoctrineExpressionBuilder($connection); $this->expressionBuilder = new DoctrineExpressionBuilder($connection);
$this->functionBuilder = $connection->getQueryBuilder()->func(); $this->functionBuilder = $queryBuilder->func();
} }
/** /**

View File

@ -25,6 +25,7 @@ namespace OC\DB\QueryBuilder\ExpressionBuilder;
use OC\DB\Connection; use OC\DB\Connection;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection; use OCP\IDBConnection;
class MySqlExpressionBuilder extends ExpressionBuilder { class MySqlExpressionBuilder extends ExpressionBuilder {
@ -34,9 +35,10 @@ class MySqlExpressionBuilder extends ExpressionBuilder {
/** /**
* @param \OCP\IDBConnection|Connection $connection * @param \OCP\IDBConnection|Connection $connection
* @param IQueryBuilder $queryBuilder
*/ */
public function __construct(IDBConnection $connection) { public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder) {
parent::__construct($connection); parent::__construct($connection, $queryBuilder);
$params = $connection->getParams(); $params = $connection->getParams();
$this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8';

View File

@ -112,15 +112,15 @@ class QueryBuilder implements IQueryBuilder {
*/ */
public function expr() { public function expr() {
if ($this->connection instanceof OracleConnection) { if ($this->connection instanceof OracleConnection) {
return new OCIExpressionBuilder($this->connection); return new OCIExpressionBuilder($this->connection, $this);
} else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { } else if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
return new PgSqlExpressionBuilder($this->connection); return new PgSqlExpressionBuilder($this->connection, $this);
} else if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) { } else if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
return new MySqlExpressionBuilder($this->connection); return new MySqlExpressionBuilder($this->connection, $this);
} else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { } else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
return new SqliteExpressionBuilder($this->connection); return new SqliteExpressionBuilder($this->connection, $this);
} else { } else {
return new ExpressionBuilder($this->connection); return new ExpressionBuilder($this->connection, $this);
} }
} }

View File

@ -48,7 +48,9 @@ class ExpressionBuilderTest extends TestCase {
$this->connection = \OC::$server->getDatabaseConnection(); $this->connection = \OC::$server->getDatabaseConnection();
$this->expressionBuilder = new ExpressionBuilder($this->connection); $queryBuilder = $this->createMock(IQueryBuilder::class);
$this->expressionBuilder = new ExpressionBuilder($this->connection, $queryBuilder);
$this->doctrineExpressionBuilder = new DoctrineExpressionBuilder($this->connection); $this->doctrineExpressionBuilder = new DoctrineExpressionBuilder($this->connection);
} }