From 0d321c89a42c6f44519391f6ae346342e4e375ae Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Vares Date: Sat, 1 Mar 2025 11:15:06 +0100 Subject: [PATCH] #2340 - Remove trailing semicolon from query (Currently writing an OCI Adapter) OCI doesn't allow a trailing semicolon. There can be a problem Still output the semicolon, so that output can be easily copy/pasted --- .github/workflows/ci.yml | 2 +- src/Phinx/Db/Adapter/PdoAdapter.php | 4 ++-- tests/Phinx/Db/Adapter/PdoAdapterTest.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc9a625d5..a464aaa8b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,7 +83,7 @@ jobs: n=$((n+1)) sleep 2 done - mysql -h 127.0.0.1 -u root -proot -D phinx -e 'SELECT 1;' + mysql -h 127.0.0.1 -u root -proot -D phinx -e 'SELECT 1' fi if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then psql -c 'CREATE DATABASE phinx;' postgresql://postgres:postgres@127.0.0.1; fi diff --git a/src/Phinx/Db/Adapter/PdoAdapter.php b/src/Phinx/Db/Adapter/PdoAdapter.php index 73e98a666..99298b755 100644 --- a/src/Phinx/Db/Adapter/PdoAdapter.php +++ b/src/Phinx/Db/Adapter/PdoAdapter.php @@ -181,8 +181,8 @@ abstract public function disconnect(): void; */ public function execute(string $sql, array $params = []): int { - $sql = rtrim($sql, "; \t\n\r\0\x0B") . ';'; - $this->verboseLog($sql); + $sql = rtrim($sql, "; \t\n\r\0\x0B"); + $this->verboseLog($sql . ';'); if ($this->isDryRunEnabled()) { return 0; diff --git a/tests/Phinx/Db/Adapter/PdoAdapterTest.php b/tests/Phinx/Db/Adapter/PdoAdapterTest.php index 623201b04..4ecae6f2b 100644 --- a/tests/Phinx/Db/Adapter/PdoAdapterTest.php +++ b/tests/Phinx/Db/Adapter/PdoAdapterTest.php @@ -182,7 +182,7 @@ public function testExecuteCanBeCalled() { /** @var \PDO&\PHPUnit\Framework\MockObject\MockObject $pdo */ $pdo = $this->getMockBuilder(PDO::class)->disableOriginalConstructor()->onlyMethods(['exec'])->getMock(); - $pdo->expects($this->once())->method('exec')->with('SELECT 1;')->will($this->returnValue(1)); + $pdo->expects($this->once())->method('exec')->with('SELECT 1')->will($this->returnValue(1)); $this->adapter->setConnection($pdo); $this->adapter->execute('SELECT 1'); @@ -192,7 +192,7 @@ public function testExecuteRightTrimsSemiColons() { /** @var \PDO&\PHPUnit\Framework\MockObject\MockObject $pdo */ $pdo = $this->getMockBuilder(PDO::class)->disableOriginalConstructor()->onlyMethods(['exec'])->getMock(); - $pdo->expects($this->once())->method('exec')->with('SELECT 1;')->will($this->returnValue(1)); + $pdo->expects($this->once())->method('exec')->with('SELECT 1')->will($this->returnValue(1)); $this->adapter->setConnection($pdo); $this->adapter->execute('SELECT 1;;');