Skip to content

Commit

Permalink
Context: Added custom mode that avoids escaping when possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ungureanu committed Feb 11, 2016
1 parent 38b10f5 commit de8b3ef
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit de8b3ef

Please sign in to comment.