From de8b3efbbca418f7c867909dbcb3fbe4b4a20497 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Thu, 11 Feb 2016 17:38:33 +0200 Subject: [PATCH] Context: Added custom mode that avoids escaping when possible. --- src/Context.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Context.php b/src/Context.php index 7637953ab..a62fa16b9 100644 --- a/src/Context.php +++ b/src/Context.php @@ -190,6 +190,13 @@ abstract class Context // https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_strict_trans_tables const STRICT_TRANS_TABLES = 1048576; + // Custom modes. + + // The table and column names and any other field that must be escaped will + // not be. + // Reserved keywords are being escaped regardless this mode is used or not. + const NO_ENCLOSING_QUOTES = 1073741824; + /* * Combination SQL Modes * https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sql-mode-combo @@ -520,9 +527,16 @@ public static function escape($str, $quote = '`') return $str; } + if ((static::$MODE & Context::NO_ENCLOSING_QUOTES) + && (!static::isKeyword($str, true)) + ) { + return $str; + } + if (static::$MODE & Context::ANSI_QUOTES) { $quote = '"'; } + return $quote . str_replace($quote, $quote . $quote, $str) . $quote; } }