Skip to content

Commit de8b3ef

Browse files
committed
Context: Added custom mode that avoids escaping when possible.
1 parent 38b10f5 commit de8b3ef

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Context.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ abstract class Context
190190
// https://dev.mysql.com/doc/refman/5.0/en/sql-mode.html#sqlmode_strict_trans_tables
191191
const STRICT_TRANS_TABLES = 1048576;
192192

193+
// Custom modes.
194+
195+
// The table and column names and any other field that must be escaped will
196+
// not be.
197+
// Reserved keywords are being escaped regardless this mode is used or not.
198+
const NO_ENCLOSING_QUOTES = 1073741824;
199+
193200
/*
194201
* Combination SQL Modes
195202
* 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 = '`')
520527
return $str;
521528
}
522529

530+
if ((static::$MODE & Context::NO_ENCLOSING_QUOTES)
531+
&& (!static::isKeyword($str, true))
532+
) {
533+
return $str;
534+
}
535+
523536
if (static::$MODE & Context::ANSI_QUOTES) {
524537
$quote = '"';
525538
}
539+
526540
return $quote . str_replace($quote, $quote . $quote, $str) . $quote;
527541
}
528542
}

0 commit comments

Comments
 (0)