Merge "New maintenance script to clean up rows with invalid DB keys"
[lhc/web/wiklou.git] / includes / libs / rdbms / database / DatabaseMssql.php
index c736cc7..782727a 100644 (file)
@@ -1110,27 +1110,11 @@ class DatabaseMssql extends Database {
         * @param string $s
         * @return string
         */
-       protected function escapeLikeInternal( $s ) {
-               return addcslashes( $s, '\%_[]^' );
-       }
-
-       /**
-        * MS SQL requires specifying the escape character used in a LIKE query
-        * or using Square brackets to surround characters that are to be escaped
-        * https://msdn.microsoft.com/en-us/library/ms179859.aspx
-        * Here we take the Specify-Escape-Character approach since it's less
-        * invasive, renders a query that is closer to other DB's and better at
-        * handling square bracket escaping
-        *
-        * @return string Fully built LIKE statement
-        */
-       public function buildLike() {
-               $params = func_get_args();
-               if ( count( $params ) > 0 && is_array( $params[0] ) ) {
-                       $params = $params[0];
-               }
-
-               return parent::buildLike( $params ) . " ESCAPE '\' ";
+       protected function escapeLikeInternal( $s, $escapeChar = '`' ) {
+               return str_replace( [ $escapeChar, '%', '_', '[', ']', '^' ],
+                       [ "{$escapeChar}{$escapeChar}", "{$escapeChar}%", "{$escapeChar}_",
+                               "{$escapeChar}[", "{$escapeChar}]", "{$escapeChar}^" ],
+                       $s );
        }
 
        /**