DB\IO add unescape bytea data

This commit is contained in:
Clemens Schwaighofer
2022-12-09 16:33:58 +09:00
parent 9936fc04da
commit b7c6d4b478
3 changed files with 33 additions and 9 deletions

View File

@@ -1488,12 +1488,17 @@ class IO
/** /**
* escape data for writing to bytea type column field * escape data for writing to bytea type column field
* @param string $bytea bytea to escape * @param string $data data to escape to bytea
* @return string escaped 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);
} }
/** /**

View File

@@ -559,15 +559,26 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
/** /**
* wrapper for pg_escape_byte * wrapper for pg_escape_byte
* *
* @param string $bytea bytea data stream * @param string $data data stream
* @return string escaped bytea string * @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)) { if ($this->dbh === false || is_bool($this->dbh)) {
return ''; 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);
} }
/** /**

View File

@@ -217,7 +217,15 @@ interface SqlFunctions
* @param string $bytea * @param string $bytea
* @return string * @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 * Undocumented function