Skip to content

Commit

Permalink
Fixes for Quoter (#112)
Browse files Browse the repository at this point in the history
Fixes for Quoter.
  • Loading branch information
darkdef committed Sep 2, 2022
1 parent e888a23 commit 0917a84
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ConnectionPDO.php
Expand Up @@ -68,7 +68,7 @@ public function getQueryBuilder(): QueryBuilderInterface
public function getQuoter(): QuoterInterface
{
if ($this->quoter === null) {
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix());
$this->quoter = new Quoter(['[', ']'], ['[', ']'], $this->getTablePrefix(), $this->getActivePDO());
}

return $this->quoter;
Expand Down
9 changes: 5 additions & 4 deletions src/Quoter.php
Expand Up @@ -4,13 +4,13 @@

namespace Yiisoft\Db\Mssql;

use PDO;
use Yiisoft\Db\Schema\Quoter as BaseQuoter;
use Yiisoft\Db\Schema\QuoterInterface;

use function preg_match;
use function preg_match_all;

final class Quoter extends BaseQuoter implements QuoterInterface
final class Quoter extends BaseQuoter
{
/**
* @psalm-param string[] $columnQuoteCharacter
Expand All @@ -19,9 +19,10 @@ final class Quoter extends BaseQuoter implements QuoterInterface
public function __construct(
array $columnQuoteCharacter,
array $tableQuoteCharacter,
string $tablePrefix = ''
string $tablePrefix = '',
protected PDO|null $pdo = null,
) {
parent::__construct($columnQuoteCharacter, $tableQuoteCharacter, $tablePrefix);
parent::__construct($columnQuoteCharacter, $tableQuoteCharacter, $tablePrefix, $pdo);
}

public function quoteColumnName(string $name): string
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixture/mssql.sql
Expand Up @@ -7,6 +7,7 @@ IF OBJECT_ID('[dbo].[order_with_null_fk]', 'U') IS NOT NULL DROP TABLE [dbo].[or
IF OBJECT_ID('[dbo].[category]', 'U') IS NOT NULL DROP TABLE [dbo].[category];
IF OBJECT_ID('[dbo].[customer]', 'U') IS NOT NULL DROP TABLE [dbo].[customer];
IF OBJECT_ID('[dbo].[profile]', 'U') IS NOT NULL DROP TABLE [dbo].[profile];
IF OBJECT_ID('[dbo].[quoter]', 'U') IS NOT NULL DROP TABLE [dbo].[quoter];
IF OBJECT_ID('[dbo].[type]', 'U') IS NOT NULL DROP TABLE [dbo].[type];
IF OBJECT_ID('[dbo].[null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[null_values];
IF OBJECT_ID('[dbo].[test_trigger]', 'U') IS NOT NULL DROP TABLE [dbo].[test_trigger];
Expand Down Expand Up @@ -37,6 +38,11 @@ CREATE TABLE [dbo].[profile] (
) ON [PRIMARY]
);

CREATE TABLE [dbo].[quoter] (
[name] [varchar](16) NOT NULL,
[description] [nvarchar](256) NOT NULL,
);

CREATE TABLE [dbo].[customer] (
[id] [int] IDENTITY NOT NULL,
[email] [varchar](128) NOT NULL,
Expand Down

0 comments on commit 0917a84

Please sign in to comment.