8000 [9.x] Address confusion between PostgreSQL concepts "schema" and "search_path" by cbj4074 · Pull Request #35463 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[9.x] Address confusion between PostgreSQL concepts "schema" and "search_path" #35463

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

Merged
merged 5 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added support for Comma separated search paths with added test
  • Loading branch information
poppabear8883 authored and cbj4074 committed Dec 4, 2020
commit b8e1aca17477f190063000e62b258bc98967d664
3 changes: 2 additions & 1 deletion src/Illuminate/Database/Connectors/PostgresConnector.php
< B244 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ protected function formatSearchPath($searchPath)
return '"'.implode('", "', $searchPath).'"';
}

return '"'.$searchPath.'"';
preg_match_all('/[a-zA-z0-9]{1,}/i', $searchPath, $matches);
return '"'.implode('", "', $matches[0]).'"';
}

/**
Expand Down
16 changes: 16 additions & 0 deletions tests/Database/DatabaseConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ public function testPostgresSearchPathArraySupported()
$this->assertSame($result, $connection);
}

public function testPostgresSearchPathCommaSeparatedValueSupported()
{
$dsn = 'pgsql:host=foo;dbname=bar';
$config = ['host' => 'foo', 'database' => 'bar', 'schema' => 'public, user', 'charset' => 'utf8'];
$connector = $this->getMockBuilder('Illuminate\Database\Connectors\PostgresConnector')->setMethods(['createConnection', 'getOptions'])->getMock();
$connection = m::mock('stdClass');
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
$connection->shouldReceive('prepare')->once()->with('set search_path to "public", "user"')->andReturn($connection);
$connection->shouldReceive('execute')->twice();
$result = $connector->connect($config);

$this->assertSame($result, $connection);
}

public function testPostgresApplicationNameIsSet()
{
$dsn = 'pgsql:host=foo;dbname=bar';
Expand Down
0