Skip to content

Commit

Permalink
Rename string escaping methods
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 9, 2023
1 parent 5e4dbbe commit a106296
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/Internal/AbstractHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
12 changes: 6 additions & 6 deletions src/Internal/PgSqlHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/PostgresHandleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Internal/PostgresTransactionDelegate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Internal/PqHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/PostgresConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/PostgresExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@ 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.
*
* @return string Quoted identifier.
*
* @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.
Expand Down
4 changes: 2 additions & 2 deletions test/AbstractQuoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'\""));
}
}

0 comments on commit a106296

Please sign in to comment.