From 7f261daed8ca5ae3e2918a8d57935b5dcb649250 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 20 May 2006 18:07:14 +0000 Subject: [PATCH] - Adding TYPE_BIN and support for it in api.php - Escaping binary now works in db_mysql.php --- api.php | 6 +++++- db_mysql.php | 16 ++++++++++++++++ dev/changes.txt | 4 +++- kernel.php | 9 +++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/api.php b/api.php index a2c9c97..058f98b 100644 --- a/api.php +++ b/api.php @@ -593,12 +593,16 @@ class API if ($type == TYPE_NOCLEAN OR $type == TYPE_STR OR $type == TYPE_STRUN) { - return "'" . $this->registry->escape($this->values["$name"]) . "'"; + return "'" . $this->registry->db->escape_string($this->values["$name"]) . "'"; } else if ($type == TYPE_BOOL) { return ($this->values["$name"] == true ? "'1'" : "'0'"); } + else if ($type == TYPE_BIN) + { + return "'" . $this->registry->db->escape_binary($this->values["$name"]) . "'"; + } else { return $this->values["$name"]; diff --git a/db_mysql.php b/db_mysql.php index 2cee356..8d1b341 100644 --- a/db_mysql.php +++ b/db_mysql.php @@ -54,6 +54,7 @@ class DB_MySQL extends DB_Abstract 'error_num' => 'mysql_errno', 'error_str' => 'mysql_error', 'escape_string' => '$this->command_mysql_escape_string', + 'escape_binary' => '$this->escape_binary', 'fetch_assoc' => 'mysql_fetch_assoc', 'fetch_row' => 'mysql_fetch_row', 'fetch_object' => 'mysql_fetch_object', @@ -156,6 +157,21 @@ class DB_MySQL extends DB_Abstract return mysql_query($string, $link); } + // ################################################################### + /** + * Escapes a binary string for insertion into the database + * + * @access public + * + * @param string Unescaped data + * + * @return string Escaped binary data + */ + function escape_binary($binary) + { + return mysql_escape_string($binary); + } + // ################################################################### /** * Wrapper: mysql(_real)_escape_string diff --git a/dev/changes.txt b/dev/changes.txt index 2b2d9ba..cb8bd82 100644 --- a/dev/changes.txt +++ b/dev/changes.txt @@ -1,6 +1,8 @@ 2.0.1 =============== -- Add TYPE_NONE as an alias for TYPE_NOCLEAN +- Added TYPE_NONE as an alias for TYPE_NOCLEAN +- Added TYPE_BIN to create a macro in the API that will escape the string as binary, instead of a string +- DB_MySQL can now properly escape binary 2.0.0 =============== diff --git a/kernel.php b/kernel.php index 7202336..b5dc718 100644 --- a/kernel.php +++ b/kernel.php @@ -127,6 +127,11 @@ define('TYPE_NOCLEAN', 64); * Duplicate of TYPE_NOCLEAN, but shorter */ define('TYPE_NONE', TYPE_NOCLEAN); + +/** +* Macro for using DB->escape_binary() without cleaning - used in API +*/ +define('TYPE_BIN', 128); /**#@-*/ /** @@ -1128,6 +1133,10 @@ class ISSO $value = $value; } } + else if ($type == TYPE_BIN) + { + $value = $value; + } else { trigger_error('Invalid clean type `' . $type . '` specified', E_USER_ERROR); -- 2.43.5