Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- New #345: Add parameters `$ifExists` and `$cascade` to `CommandInterface::dropTable()` and
`DDLQueryBuilderInterface::dropTable()` methods (@vjik)
- Chg #348: Remove usage of `hasLimit()` and `hasOffset()` methods of `DQLQueryBuilder` class (@Tigrov)
- Enh #350: Refactor according changes in `db` package (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
2 changes: 1 addition & 1 deletion src/Builder/InConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function buildCompositeInCondition(
}

$quotedColumns[$i] = !str_contains($column, '(')
? $this->queryBuilder->quoter()->quoteColumnName($column) : $column;
? $this->queryBuilder->getQuoter()->quoteColumnName($column) : $column;
}

$vss = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Column/ColumnDefinitionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function buildCheck(ColumnInterface $column): string

return match ($column->getType()) {
ColumnType::ARRAY, ColumnType::STRUCTURED, ColumnType::JSON =>
' CHECK (isjson(' . $this->queryBuilder->quoter()->quoteSimpleColumnName($name) . ') > 0)',
' CHECK (isjson(' . $this->queryBuilder->getQuoter()->quoteSimpleColumnName($name) . ') > 0)',
default => '',
};
}
Expand Down
25 changes: 10 additions & 15 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection;
use Yiisoft\Db\Driver\Pdo\PdoCommandInterface;
use Yiisoft\Db\Mssql\Column\ColumnFactory;
use Yiisoft\Db\Query\BatchQueryResultInterface;
use Yiisoft\Db\Query\QueryInterface;
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;
use Yiisoft\Db\Transaction\TransactionInterface;
Expand Down Expand Up @@ -49,31 +51,24 @@ public function createTransaction(): TransactionInterface
return new Transaction($this);
}

public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}

public function getQueryBuilder(): QueryBuilderInterface
{
return $this->queryBuilder ??= new QueryBuilder(
$this->getQuoter(),
$this->getSchema(),
$this->getServerInfo(),
);
return $this->queryBuilder ??= new QueryBuilder($this);
}

public function getQuoter(): QuoterInterface
{
if ($this->quoter === null) {
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix());
}

return $this->quoter;
return $this->quoter ??= new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix());
}

public function getSchema(): SchemaInterface
{
if ($this->schema === null) {
$this->schema = new Schema($this, $this->schemaCache);
}

return $this->schema;
return $this->schema ??= new Schema($this, $this->schemaCache);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/DDLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin
$constraintBase = preg_replace('/\W/', '', $table . '_' . $column);

if (is_string($type)) {
$type = $this->schema->getColumnFactory()->fromDefinition($type);
$type = $this->queryBuilder->getColumnFactory()->fromDefinition($type);
}

$columnDefinitionBuilder = $this->queryBuilder->getColumnDefinitionBuilder();
Expand Down
13 changes: 6 additions & 7 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Yiisoft\Db\Mssql;

use Yiisoft\Db\Connection\ServerInfoInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Mssql\Column\ColumnDefinitionBuilder;
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder;
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

/**
* Implements the MSSQL Server specific query builder.
Expand All @@ -19,12 +17,13 @@ final class QueryBuilder extends AbstractQueryBuilder

protected const TRUE_VALUE = '1';

public function __construct(QuoterInterface $quoter, SchemaInterface $schema, ServerInfoInterface $serverInfo)
public function __construct(ConnectionInterface $db)
{
$quoter = $db->getQuoter();
$schema = $db->getSchema();

parent::__construct(
$quoter,
$schema,
$serverInfo,
$db,
new DDLQueryBuilder($this, $quoter, $schema),
new DMLQueryBuilder($this, $quoter, $schema),
new DQLQueryBuilder($this, $quoter),
Expand Down
9 changes: 1 addition & 8 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Mssql\Column\ColumnFactory;
use Yiisoft\Db\Schema\Column\ColumnFactoryInterface;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;

Expand Down Expand Up @@ -69,11 +67,6 @@ final class Schema extends AbstractPdoSchema
*/
protected string|null $defaultSchema = 'dbo';

public function getColumnFactory(): ColumnFactoryInterface
{
return new ColumnFactory();
}

/**
* Resolves the table name and schema name (if any).
*
Expand Down Expand Up @@ -358,7 +351,7 @@ protected function loadTableDefaultValues(string $tableName): array
*/
private function loadColumn(array $info): ColumnInterface
{
return $this->getColumnFactory()->fromDbType($info['data_type'], [
return $this->db->getColumnFactory()->fromDbType($info['data_type'], [
'autoIncrement' => $info['is_identity'] === '1',
'check' => $info['check'],
'comment' => $info['comment'],
Expand Down
8 changes: 8 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Mssql\Column\ColumnFactory;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Tests\Common\CommonConnectionTest;
use Yiisoft\Db\Transaction\TransactionInterface;
Expand Down Expand Up @@ -87,4 +88,11 @@ public function testSettingDefaultAttributes(): void

$this->assertSame(PDO::ERRMODE_EXCEPTION, $db->getActivePDO()?->getAttribute(PDO::ATTR_ERRMODE));
}

public function testGetColumnFactory(): void
{
$db = $this->getConnection();

$this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory());
}
}
8 changes: 0 additions & 8 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Mssql\Column\ColumnFactory;
use Yiisoft\Db\Mssql\Schema;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Schema\SchemaInterface;
Expand Down Expand Up @@ -186,11 +185,4 @@ public function testNegativeDefaultValues(): void

$db->close();
}

public function testGetColumnFactory(): void
{
$db = $this->getConnection();

$this->assertInstanceOf(ColumnFactory::class, $db->getSchema()->getColumnFactory());
}
}