Skip to content

Commit b825a3c

Browse files
committed
Enclose PostgreSQL schema name with double quotes
Schema names must be enclosed with double quotes to prevent PDOException while setting search path to a alphanumerical value. Following exception is from a production environment (v4.2.17). (Note that the first id is trimmed version of the second id) [PDOException] SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "d959d1fa9f6f2831c1d13ff05baed" LINE 1: set search_path to 397d959d1fa9f6f2831c1d13ff05baed
1 parent ffc9662 commit b825a3c

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/Illuminate/Database/Connectors/PostgresConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function connect(array $config)
5454
{
5555
$schema = $config['schema'];
5656

57-
$connection->prepare("set search_path to {$schema}")->execute();
57+
$connection->prepare("set search_path to \"{$schema}\"")->execute();
5858
}
5959

6060
return $connection;

tests/Database/DatabaseConnectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testPostgresSearchPathIsSet()
7171
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(array('options')));
7272
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(array('options')))->will($this->returnValue($connection));
7373
$connection->shouldReceive('prepare')->once()->with('set names \'utf8\'')->andReturn($connection);
74-
$connection->shouldReceive('prepare')->once()->with("set search_path to public")->andReturn($connection);
74+
$connection->shouldReceive('prepare')->once()->with('set search_path to "public"')->andReturn($connection);
7575
$connection->shouldReceive('execute')->twice();
7676
$result = $connector->connect($config);
7777

0 commit comments

Comments
 (0)