reuse query builder
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
aad01894e3
commit
42b3aa3a0a
|
@ -52,13 +52,14 @@ class ExpressionBuilder implements IExpressionBuilder {
|
|||
/**
|
||||
* 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->helper = new QuoteHelper();
|
||||
$this->expressionBuilder = new DoctrineExpressionBuilder($connection);
|
||||
$this->functionBuilder = $connection->getQueryBuilder()->func();
|
||||
$this->functionBuilder = $queryBuilder->func();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace OC\DB\QueryBuilder\ExpressionBuilder;
|
|||
|
||||
|
||||
use OC\DB\Connection;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class MySqlExpressionBuilder extends ExpressionBuilder {
|
||||
|
@ -34,9 +35,10 @@ class MySqlExpressionBuilder extends ExpressionBuilder {
|
|||
|
||||
/**
|
||||
* @param \OCP\IDBConnection|Connection $connection
|
||||
* @param IQueryBuilder $queryBuilder
|
||||
*/
|
||||
public function __construct(IDBConnection $connection) {
|
||||
parent::__construct($connection);
|
||||
public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder) {
|
||||
parent::__construct($connection, $queryBuilder);
|
||||
|
||||
$params = $connection->getParams();
|
||||
$this->charset = isset($params['charset']) ? $params['charset'] : 'utf8';
|
||||
|
|
|
@ -112,15 +112,15 @@ class QueryBuilder implements IQueryBuilder {
|
|||
*/
|
||||
public function expr() {
|
||||
if ($this->connection instanceof OracleConnection) {
|
||||
return new OCIExpressionBuilder($this->connection);
|
||||
return new OCIExpressionBuilder($this->connection, $this);
|
||||
} 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) {
|
||||
return new MySqlExpressionBuilder($this->connection);
|
||||
return new MySqlExpressionBuilder($this->connection, $this);
|
||||
} else if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
|
||||
return new SqliteExpressionBuilder($this->connection);
|
||||
return new SqliteExpressionBuilder($this->connection, $this);
|
||||
} else {
|
||||
return new ExpressionBuilder($this->connection);
|
||||
return new ExpressionBuilder($this->connection, $this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,9 @@ class ExpressionBuilderTest extends TestCase {
|
|||
|
||||
$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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue