Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Fix enum definition not producing N-quoted string on Sql Server #28176

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 15 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,19 @@ public function wrapTable($table)

return parent::wrapTable($table);
}

/**
* Quote the given string literal.
*
* @param string|array $value
* @return string
*/
public function quoteString($value)
{
if (is_array($value)) {
return implode(', ', array_map([$this, __FUNCTION__], $value));
}

return "N'$value'";
}
}
12 changes: 11 additions & 1 deletion tests/Database/DatabaseSqlServerSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public function testAddingEnum()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('alter table "users" add "role" nvarchar(255) check ("role" in (\'member\', \'admin\')) not null', $statements[0]);
$this->assertEquals('alter table "users" add "role" nvarchar(255) check ("role" in (N\'member\', N\'admin\')) not null', $statements[0]);
driesvints marked this conversation as resolved.
Show resolved Hide resolved
}

public function testAddingJson()
Expand Down Expand Up @@ -793,6 +793,16 @@ public function testGrammarsAreMacroable()
$this->assertTrue($c);
}

public function testQuoteString()
{
$this->assertSame("N'中文測試'", $this->getGrammar()->quoteString('中文測試'));
}

public function testQuoteStringOnArray()
{
$this->assertSame("N'中文', N'測試'", $this->getGrammar()->quoteString(['中文', '測試']));
}

protected function getConnection()
{
return m::mock(Connection::class);
Expand Down