From 70c4cfc66b4fb8094ac777a09ecf6e977fbf17e8 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Fri, 22 Nov 2024 11:21:58 +0000 Subject: [PATCH 1/6] Correct behaviour to match PHP 8.4 PDO calls --- src/ExtendedPdo.php | 33 +++++++++++++++++++++++++++++--- tests/ExtendedConnectPdoTest.php | 5 +++++ tests/ExtendedPdoTest.php | 5 +++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index bb6ff65..942abf7 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -21,6 +21,9 @@ */ class ExtendedPdo extends AbstractExtendedPdo { + public const string CONNECT_IMMEDIATELY = 'immediate'; + public const string DRIVER_SPECIFIC = 'driverSpecific'; + /** * * Constructor arguments for instantiating the PDO connection. @@ -30,6 +33,14 @@ class ExtendedPdo extends AbstractExtendedPdo */ protected array $args = []; + + /** + * + * Flag for how will construct the PDO object + * + * @var bool + */ + protected bool $driverSpecific = false; /** * * Constructor. @@ -64,6 +75,11 @@ public function __construct( $options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; } + // check option for driver specific construct and set flay for lazy loading later + if (isset($options[static::DRIVER_SPECIFIC])) { + $this->driverSpecific = (bool) $options[static::DRIVER_SPECIFIC]; + } + // retain the arguments for later $this->args = [ $dsn, @@ -83,17 +99,24 @@ public function __construct( // set quotes for identifier names $this->setQuoteName($parts[0]); + + // create a connection immediately + if (isset($options[static::CONNECT_IMMEDIATELY]) && $options[static::CONNECT_IMMEDIATELY]) { + $this->establishConnection(); + } } public static function connect( string $dsn, ?string $username = null, ?string $password = null, - ?array $options = [], + ?array $options = null, array $queries = [], ?ProfilerInterface $profiler = null ): static { - return new static($dsn, $username, $password, $options ?? [], $queries, $profiler); + $options ??= []; + $options[static::DRIVER_SPECIFIC] = true; + return new static($dsn, $username, $password, $options, $queries, $profiler); } /** @@ -111,7 +134,11 @@ public function establishConnection(): void // connect $this->profiler->start(__FUNCTION__); list($dsn, $username, $password, $options, $queries) = $this->args; - $this->pdo = PDO::connect($dsn, $username, $password, $options); + if ($this->driverSpecific) { + $this->pdo = PDO::connect($dsn, $username, $password, $options); + } else { + $this->pdo = new PDO($dsn, $username, $password, $options); + } $this->profiler->finish(); // connection-time queries diff --git a/tests/ExtendedConnectPdoTest.php b/tests/ExtendedConnectPdoTest.php index 25d5269..e159867 100644 --- a/tests/ExtendedConnectPdoTest.php +++ b/tests/ExtendedConnectPdoTest.php @@ -8,4 +8,9 @@ protected function newPdo() { return ExtendedPdo::connect('sqlite::memory:'); } + + public function testPdoType() + { + $this->assertInstanceOf(Pdo\Sqlite::class, $this->pdo); + } } \ No newline at end of file diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index c04a43b..3173262 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -71,6 +71,11 @@ protected function insert(array $data) $this->pdo->perform($stm, $data); } + public function testPdoType() + { + $this->assertNotInstanceOf(Pdo\Sqlite::class, $this->pdo); + } + public function testCall() { if (defined('HHVM_VERSION')) { From 411f2dbed855c58e6c6bd9ba4d4d9aec912d3813 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Fri, 22 Nov 2024 11:25:02 +0000 Subject: [PATCH 2/6] Correct behaviour to match PHP 8.4 PDO calls --- tests/ExtendedConnectPdoTest.php | 2 +- tests/ExtendedPdoTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ExtendedConnectPdoTest.php b/tests/ExtendedConnectPdoTest.php index e159867..61bdcb7 100644 --- a/tests/ExtendedConnectPdoTest.php +++ b/tests/ExtendedConnectPdoTest.php @@ -11,6 +11,6 @@ protected function newPdo() public function testPdoType() { - $this->assertInstanceOf(Pdo\Sqlite::class, $this->pdo); + $this->assertInstanceOf(Pdo\Sqlite::class, $this->pdo->getPdo()); } } \ No newline at end of file diff --git a/tests/ExtendedPdoTest.php b/tests/ExtendedPdoTest.php index 3173262..d48c06e 100644 --- a/tests/ExtendedPdoTest.php +++ b/tests/ExtendedPdoTest.php @@ -73,7 +73,7 @@ protected function insert(array $data) public function testPdoType() { - $this->assertNotInstanceOf(Pdo\Sqlite::class, $this->pdo); + $this->assertNotInstanceOf(Pdo\Sqlite::class, $this->pdo->getPdo()); } public function testCall() From db09b4fdb19d8d60ee5bec0a6093bdb7508743e4 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Fri, 22 Nov 2024 12:21:16 +0000 Subject: [PATCH 3/6] fix typo's --- src/ExtendedPdo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 942abf7..54b748e 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -36,7 +36,7 @@ class ExtendedPdo extends AbstractExtendedPdo /** * - * Flag for how will construct the PDO object + * Flag for how to construct the PDO object * * @var bool */ @@ -75,7 +75,7 @@ public function __construct( $options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; } - // check option for driver specific construct and set flay for lazy loading later + // check option for driver specific construct and set flag for lazy loading later if (isset($options[static::DRIVER_SPECIFIC])) { $this->driverSpecific = (bool) $options[static::DRIVER_SPECIFIC]; } From ac06acfc666df68c652717869dc29e74edd77c33 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 19 Dec 2024 10:06:01 +0000 Subject: [PATCH 4/6] Correct behaviour to match PHP 8.4 PDO calls --- src/ExtendedPdo.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 54b748e..05b446b 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -21,8 +21,8 @@ */ class ExtendedPdo extends AbstractExtendedPdo { - public const string CONNECT_IMMEDIATELY = 'immediate'; - public const string DRIVER_SPECIFIC = 'driverSpecific'; + public const string CONNECT_IMMEDIATELY = 'auraSqlImmediate'; + public const string DRIVER_SPECIFIC = 'auraSqlDriverSpecific'; /** * @@ -78,6 +78,7 @@ public function __construct( // check option for driver specific construct and set flag for lazy loading later if (isset($options[static::DRIVER_SPECIFIC])) { $this->driverSpecific = (bool) $options[static::DRIVER_SPECIFIC]; + unset($options[static::DRIVER_SPECIFIC]); } // retain the arguments for later @@ -101,8 +102,11 @@ public function __construct( $this->setQuoteName($parts[0]); // create a connection immediately - if (isset($options[static::CONNECT_IMMEDIATELY]) && $options[static::CONNECT_IMMEDIATELY]) { - $this->establishConnection(); + if (isset($options[static::CONNECT_IMMEDIATELY])) { + if($options[static::CONNECT_IMMEDIATELY]) { + $this->establishConnection(); + } + unset($options[static::CONNECT_IMMEDIATELY]); } } From 0740b1bf21ccf88c57be28119ed8c37aad9f7763 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 19 Dec 2024 10:12:47 +0000 Subject: [PATCH 5/6] Correct behaviour to match PHP 8.4 PDO calls --- src/ExtendedPdo.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 05b446b..142f2bf 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -104,9 +104,11 @@ public function __construct( // create a connection immediately if (isset($options[static::CONNECT_IMMEDIATELY])) { if($options[static::CONNECT_IMMEDIATELY]) { + unset($options[static::CONNECT_IMMEDIATELY]); $this->establishConnection(); + }else { + unset($options[static::CONNECT_IMMEDIATELY]); } - unset($options[static::CONNECT_IMMEDIATELY]); } } From d8f1ad562624887f25771f624836f86935658f30 Mon Sep 17 00:00:00 2001 From: "steven.lewis" Date: Thu, 19 Dec 2024 10:13:30 +0000 Subject: [PATCH 6/6] Correct behaviour to match PHP 8.4 PDO calls --- src/ExtendedPdo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExtendedPdo.php b/src/ExtendedPdo.php index 142f2bf..72f49b4 100644 --- a/src/ExtendedPdo.php +++ b/src/ExtendedPdo.php @@ -106,7 +106,7 @@ public function __construct( if($options[static::CONNECT_IMMEDIATELY]) { unset($options[static::CONNECT_IMMEDIATELY]); $this->establishConnection(); - }else { + } else { unset($options[static::CONNECT_IMMEDIATELY]); } }