From a106296ee1c142c0d743659d580f93d56dd7f2d8 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Fri, 8 Dec 2023 23:31:12 -0600 Subject: [PATCH] Rename string escaping methods --- src/Internal/AbstractHandle.php | 6 +++--- src/Internal/PgSqlHandle.php | 12 ++++++------ src/Internal/PostgresHandleConnection.php | 8 ++++---- src/Internal/PostgresTransactionDelegate.php | 8 ++++---- src/Internal/PqHandle.php | 4 ++-- src/PostgresConnectionPool.php | 8 ++++---- src/PostgresExecutor.php | 10 +++++----- test/AbstractQuoteTest.php | 4 ++-- 8 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/Internal/AbstractHandle.php b/src/Internal/AbstractHandle.php index a47a282..9576261 100644 --- a/src/Internal/AbstractHandle.php +++ b/src/Internal/AbstractHandle.php @@ -106,16 +106,16 @@ public function rollback(): void public function createSavepoint(string $identifier): void { - $this->query("SAVEPOINT " . $this->quoteName($identifier)); + $this->query("SAVEPOINT " . $this->quoteIdentifier($identifier)); } public function rollbackTo(string $identifier): void { - $this->query("ROLLBACK TO " . $this->quoteName($identifier)); + $this->query("ROLLBACK TO " . $this->quoteIdentifier($identifier)); } public function releaseSavepoint(string $identifier): void { - $this->query("RELEASE SAVEPOINT " . $this->quoteName($identifier)); + $this->query("RELEASE SAVEPOINT " . $this->quoteIdentifier($identifier)); } } diff --git a/src/Internal/PgSqlHandle.php b/src/Internal/PgSqlHandle.php index a148067..c565c65 100644 --- a/src/Internal/PgSqlHandle.php +++ b/src/Internal/PgSqlHandle.php @@ -456,10 +456,10 @@ public function prepare(string $sql): PostgresStatement public function notify(string $channel, string $payload = ""): PostgresResult { if ($payload === "") { - return $this->query(\sprintf("NOTIFY %s", $this->quoteName($channel))); + return $this->query(\sprintf("NOTIFY %s", $this->quoteIdentifier($channel))); } - return $this->query(\sprintf("NOTIFY %s, %s", $this->quoteName($channel), $this->quoteString($payload))); + return $this->query(\sprintf("NOTIFY %s, %s", $this->quoteIdentifier($channel), $this->quoteLiteral($payload))); } public function listen(string $channel): PostgresListener @@ -471,7 +471,7 @@ public function listen(string $channel): PostgresListener $this->listeners[$channel] = $source = new Queue(); try { - $this->query(\sprintf("LISTEN %s", $this->quoteName($channel))); + $this->query(\sprintf("LISTEN %s", $this->quoteIdentifier($channel))); } catch (\Throwable $exception) { unset($this->listeners[$channel]); throw $exception; @@ -499,14 +499,14 @@ private function unlisten(string $channel): void } try { - $this->query(\sprintf("UNLISTEN %s", $this->quoteName($channel))); + $this->query(\sprintf("UNLISTEN %s", $this->quoteIdentifier($channel))); $source->complete(); } catch (\Throwable $exception) { $source->error($exception); } } - public function quoteString(string $data): string + public function quoteLiteral(string $data): string { if ($this->handle === null) { throw new \Error("The connection to the database has been closed"); @@ -515,7 +515,7 @@ public function quoteString(string $data): string return \pg_escape_literal($this->handle, $data); } - public function quoteName(string $name): string + public function quoteIdentifier(string $name): string { if ($this->handle === null) { throw new \Error("The connection to the database has been closed"); diff --git a/src/Internal/PostgresHandleConnection.php b/src/Internal/PostgresHandleConnection.php index d0b849e..2653aa3 100644 --- a/src/Internal/PostgresHandleConnection.php +++ b/src/Internal/PostgresHandleConnection.php @@ -145,14 +145,14 @@ final public function setTransactionIsolation(TransactionIsolation $isolation): $this->transactionIsolation = $isolation; } - final public function quoteString(string $data): string + final public function quoteLiteral(string $data): string { - return $this->handle->quoteString($data); + return $this->handle->quoteLiteral($data); } - final public function quoteName(string $name): string + final public function quoteIdentifier(string $name): string { - return $this->handle->quoteName($name); + return $this->handle->quoteIdentifier($name); } final public function escapeByteA(string $data): string diff --git a/src/Internal/PostgresTransactionDelegate.php b/src/Internal/PostgresTransactionDelegate.php index a7874b6..fcaaa1e 100644 --- a/src/Internal/PostgresTransactionDelegate.php +++ b/src/Internal/PostgresTransactionDelegate.php @@ -75,14 +75,14 @@ public function notify(string $channel, string $payload = ""): PostgresResult return $this->getExecutor()->notify($channel, $payload); } - public function quoteString(string $data): string + public function quoteLiteral(string $data): string { - return $this->getExecutor()->quoteString($data); + return $this->getExecutor()->quoteLiteral($data); } - public function quoteName(string $name): string + public function quoteIdentifier(string $name): string { - return $this->getExecutor()->quoteName($name); + return $this->getExecutor()->quoteIdentifier($name); } public function escapeByteA(string $data): string diff --git a/src/Internal/PqHandle.php b/src/Internal/PqHandle.php index 252b4e4..29f76ff 100644 --- a/src/Internal/PqHandle.php +++ b/src/Internal/PqHandle.php @@ -483,7 +483,7 @@ private function unlisten(string $channel): void } } - public function quoteString(string $data): string + public function quoteLiteral(string $data): string { if (!$this->handle) { throw new \Error("The connection to the database has been closed"); @@ -492,7 +492,7 @@ public function quoteString(string $data): string return $this->handle->quote($data); } - public function quoteName(string $name): string + public function quoteIdentifier(string $name): string { if (!$this->handle) { throw new \Error("The connection to the database has been closed"); diff --git a/src/PostgresConnectionPool.php b/src/PostgresConnectionPool.php index 9f484a9..7a9296a 100644 --- a/src/PostgresConnectionPool.php +++ b/src/PostgresConnectionPool.php @@ -151,23 +151,23 @@ public function listen(string $channel): PostgresListener }); } - public function quoteString(string $data): string + public function quoteLiteral(string $data): string { $connection = $this->pop(); try { - return $connection->quoteString($data); + return $connection->quoteLiteral($data); } finally { $this->push($connection); } } - public function quoteName(string $name): string + public function quoteIdentifier(string $name): string { $connection = $this->pop(); try { - return $connection->quoteName($name); + return $connection->quoteIdentifier($name); } finally { $this->push($connection); } diff --git a/src/PostgresExecutor.php b/src/PostgresExecutor.php index 258c5cc..2d4f9af 100644 --- a/src/PostgresExecutor.php +++ b/src/PostgresExecutor.php @@ -36,19 +36,19 @@ public function execute(string $sql, array $params = []): PostgresResult; public function notify(string $channel, string $payload = ""): PostgresResult; /** - * Quotes (escapes) the given string for use as a string literal or identifier in a query. This method wraps the + * Quotes (escapes) the given string for use as a string literal in a query. This method wraps the * string in single quotes, so additional quotes should not be added in the query. * * @param string $data Unquoted data. * - * @return string Quoted string wrapped in single quotes. + * @return string Quoted string literal. * * @throws \Error If the connection to the database has been closed. */ - public function quoteString(string $data): string; + public function quoteLiteral(string $data): string; /** - * Quotes (escapes) the given string for use as a name or identifier in a query. + * Quotes (escapes) the given string for use as an identifier in a query. * * @param string $name Unquoted identifier. * @@ -56,7 +56,7 @@ public function quoteString(string $data): string; * * @throws \Error If the connection to the database has been closed. */ - public function quoteName(string $name): string; + public function quoteIdentifier(string $name): string; /** * Escapes a binary string to be used as BYTEA data. diff --git a/test/AbstractQuoteTest.php b/test/AbstractQuoteTest.php index 07a0566..386e706 100644 --- a/test/AbstractQuoteTest.php +++ b/test/AbstractQuoteTest.php @@ -28,11 +28,11 @@ public function testEscapeByteA(): void public function testQuoteString(): void { - $this->assertSame("'\"''test''\"'", $this->connection->quoteString("\"'test'\"")); + $this->assertSame("'\"''test''\"'", $this->connection->quoteLiteral("\"'test'\"")); } public function testQuoteName(): void { - $this->assertSame("\"\"\"'test'\"\"\"", $this->connection->quoteName("\"'test'\"")); + $this->assertSame("\"\"\"'test'\"\"\"", $this->connection->quoteIdentifier("\"'test'\"")); } }