From: jenkins-bot Date: Mon, 25 Apr 2016 05:01:51 +0000 (+0000) Subject: Merge "Fix escaping for MSSQL LIKE queries." X-Git-Tag: 1.31.0-rc.0~7195 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dcompta/operations/modifier.php?a=commitdiff_plain;h=2f885ee6b797e5a176ce7b270b674a04b5945b06;hp=41e2a2486c562dba0dd22ceaf635a7d161718af8;p=lhc%2Fweb%2Fwiklou.git Merge "Fix escaping for MSSQL LIKE queries." --- diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index ce34537aee..5c46c1a91a 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -1131,6 +1131,35 @@ class DatabaseMssql extends Database { return strlen( $name ) && $name[0] == '[' && substr( $name, -1, 1 ) == ']'; } + /** + * MS SQL supports more pattern operators than other databases (ex: [,],^) + * + * @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 + * http://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 '\' "; + } + /** * @param string $db * @return bool