From c6659bd0f73419d3e2cf1bd59e52ef3858a14fe0 Mon Sep 17 00:00:00 2001 From: Andreas Sundqvist Date: Thu, 26 Oct 2017 08:31:33 +0200 Subject: [PATCH] Fix issue #163 Add getAttribute and setAttribute functions to make sure pdo is connected before calling the functions --- src/AbstractExtendedPdo.php | 27 +++++++++++++++++++++++++++ tests/ExtendedPdoTest.php | 12 ++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/AbstractExtendedPdo.php b/src/AbstractExtendedPdo.php index 8c44c1a6..483740bb 100644 --- a/src/AbstractExtendedPdo.php +++ b/src/AbstractExtendedPdo.php @@ -979,4 +979,31 @@ protected function setQuoteName($driver) return; } } + + /** + * + * Retrieve a database connection attribute + * + * @param int $attribute + * @return mixed + */ + public function getAttribute($attribute) + { + $this->connect(); + return $this->pdo->getAttribute($attribute); + } + + /** + * + * Set a database connection attribute + * + * @param int $attribute + * @param mixed $value + * @return bool + */ + public function setAttribute($attribute, $value) + { + $this->connect(); + return $this->pdo->setAttribute($attribute, $value); + } } diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index 0faa9b24..343ccb67 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -730,4 +730,16 @@ public function testQuoteName() $this->assertSame('[foo].[[bar][]', $pdo->quoteName('foo.[bar]')); } + + public function testGetAttribute() + { + $driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME); + $this->assertEquals('sqlite', $driver); + } + + public function testSetAttribute() + { + $result = $this->pdo->setAttribute(\PDO::ATTR_CASE, \PDO::CASE_NATURAL); + $this->assertTrue($result); + } }