From b825a3c197249f468f3525f5ffd4c2f0987e8a66 Mon Sep 17 00:00:00 2001 From: Efecan Date: Sun, 12 Apr 2015 04:12:15 +0300 Subject: [PATCH] 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 --- src/Illuminate/Database/Connectors/PostgresConnector.php | 2 +- tests/Database/DatabaseConnectorTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Connectors/PostgresConnector.php b/src/Illuminate/Database/Connectors/PostgresConnector.php index 14b0f441ec1a..d725d72be175 100755 --- a/src/Illuminate/Database/Connectors/PostgresConnector.php +++ b/src/Illuminate/Database/Connectors/PostgresConnector.php @@ -54,7 +54,7 @@ public function connect(array $config) { $schema = $config['schema']; - $connection->prepare("set search_path to {$schema}")->execute(); + $connection->prepare("set search_path to \"{$schema}\"")->execute(); } return $connection; diff --git a/tests/Database/DatabaseConnectorTest.php b/tests/Database/DatabaseConnectorTest.php index 8a8162e128a2..38b330a300c9 100755 --- a/tests/Database/DatabaseConnectorTest.php +++ b/tests/Database/DatabaseConnectorTest.php @@ -71,7 +71,7 @@ public function testPostgresSearchPathIsSet() $connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(array('options'))); $connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(array('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")->andReturn($connection); + $connection->shouldReceive('prepare')->once()->with('set search_path to "public"')->andReturn($connection); $connection->shouldReceive('execute')->twice(); $result = $connector->connect($config);