From b7c6d4b4789e166b731eb4431994dc167cb802ee Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Fri, 9 Dec 2022 16:33:58 +0900 Subject: [PATCH] DB\IO add unescape bytea data --- www/lib/CoreLibs/DB/IO.php | 13 +++++++++---- www/lib/CoreLibs/DB/SQL/PgSQL.php | 19 +++++++++++++++---- .../DB/SQL/SqlInterface/SqlFunctions.php | 10 +++++++++- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 0144e691..af7f0dec 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -1488,12 +1488,17 @@ class IO /** * escape data for writing to bytea type column field - * @param string $bytea bytea to escape - * @return string escaped bytea + * @param string $data data to escape to bytea + * @return string escaped bytea */ - public function dbEscapeBytea($bytea) + public function dbEscapeBytea($data) { - return $this->db_functions->__dbEscapeBytea($bytea); + return $this->db_functions->__dbEscapeBytea($data); + } + + public function dbUnescapeBytea($bytea) + { + return $this->db_functions->__dbUnescapeBytea($bytea); } /** diff --git a/www/lib/CoreLibs/DB/SQL/PgSQL.php b/www/lib/CoreLibs/DB/SQL/PgSQL.php index d64ffc46..251148b6 100644 --- a/www/lib/CoreLibs/DB/SQL/PgSQL.php +++ b/www/lib/CoreLibs/DB/SQL/PgSQL.php @@ -559,15 +559,26 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions /** * wrapper for pg_escape_byte * - * @param string $bytea bytea data stream - * @return string escaped bytea string + * @param string $data data stream + * @return string escaped bytea string */ - public function __dbEscapeBytea(string $bytea): string + public function __dbEscapeBytea(string $data): string { if ($this->dbh === false || is_bool($this->dbh)) { return ''; } - return pg_escape_bytea($this->dbh, $bytea); + return pg_escape_bytea($this->dbh, $data); + } + + /** + * unescape bytea data from postgesql + * + * @param string $bytea Bytea data stream + * @return string Unescaped bytea data + */ + public function __dbUnescapeBytea(string $bytea): string + { + return pg_unescape_bytea($bytea); } /** diff --git a/www/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php b/www/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php index e55eae4a..99e42c47 100644 --- a/www/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php +++ b/www/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php @@ -217,7 +217,15 @@ interface SqlFunctions * @param string $bytea * @return string */ - public function __dbEscapeBytea(string $bytea): string; + public function __dbEscapeBytea(string $data): string; + + /** + * Undocumented function + * + * @param string $bytea + * @return string + */ + public function __dbUnescapeBytea(string $bytea): string; /** * Undocumented function