@@ -278,16 +278,14 @@ class DatabaseWrapper(BaseDatabaseWrapper): # pylint: disable=abstract-method
278278 operators = {
279279 "exact" : "= %s" ,
280280 "iexact" : "LIKE %s" ,
281- "contains" : "LIKE BINARY %s " ,
281+ "contains" : "LIKE CAST(%s AS BINARY) " ,
282282 "icontains" : "LIKE %s" ,
283- "regex" : "REGEXP BINARY %s" ,
284- "iregex" : "REGEXP %s" ,
285283 "gt" : "> %s" ,
286284 "gte" : ">= %s" ,
287285 "lt" : "< %s" ,
288286 "lte" : "<= %s" ,
289- "startswith" : "LIKE BINARY %s " ,
290- "endswith" : "LIKE BINARY %s " ,
287+ "startswith" : "LIKE CAST(%s AS BINARY) " ,
288+ "endswith" : "LIKE CAST(%s AS BINARY) " ,
291289 "istartswith" : "LIKE %s" ,
292290 "iendswith" : "LIKE %s" ,
293291 }
@@ -302,11 +300,11 @@ class DatabaseWrapper(BaseDatabaseWrapper): # pylint: disable=abstract-method
302300 # the LIKE operator.
303301 pattern_esc = r"REPLACE(REPLACE(REPLACE({}, '\\', '\\\\'), '%%', '\%%'), '_', '\_')"
304302 pattern_ops = {
305- "contains" : "LIKE BINARY CONCAT('%%', {}, '%%')" ,
303+ "contains" : "LIKE CAST( CONCAT('%%', {}, '%%') AS BINARY )" ,
306304 "icontains" : "LIKE CONCAT('%%', {}, '%%')" ,
307- "startswith" : "LIKE BINARY CONCAT({}, '%%')" ,
305+ "startswith" : "LIKE CAST( CONCAT({}, '%%') AS BINARY )" ,
308306 "istartswith" : "LIKE CONCAT({}, '%%')" ,
309- "endswith" : "LIKE BINARY CONCAT('%%', {})" ,
307+ "endswith" : "LIKE CAST( CONCAT('%%', {}) AS BINARY )" ,
310308 "iendswith" : "LIKE CONCAT('%%', {})" ,
311309 }
312310
@@ -355,9 +353,6 @@ def __getattr__(self, attr: str) -> bool:
355353
356354 def get_connection_params (self ) -> Dict [str , Any ]:
357355 kwargs = {
358- "charset" : "utf8" ,
359- "use_unicode" : True ,
360- "buffered" : False ,
361356 "consume_results" : True ,
362357 }
363358
@@ -582,13 +577,17 @@ def mysql_server_data(self) -> Dict[str, Any]:
582577 @cached_property
583578 def mysql_server_info (self ) -> Any :
584579 """Return MySQL version."""
580+ if self .connection :
581+ return self .connection .server_info
585582 with self .temporary_connection () as cursor :
586583 cursor .execute ("SELECT VERSION()" )
587584 return cursor .fetchone ()[0 ]
588585
589586 @cached_property
590587 def mysql_version (self ) -> Tuple [int , ...]:
591588 """Return MySQL version."""
589+ if self .connection :
590+ return self .connection .server_version
592591 config = self .get_connection_params ()
593592 with mysql .connector .connect (** config ) as conn :
594593 server_version : Tuple [int , ...] = conn .server_version
@@ -597,6 +596,8 @@ def mysql_version(self) -> Tuple[int, ...]:
597596 @cached_property
598597 def sql_mode (self ) -> Set [str ]:
599598 """Return SQL mode."""
599+ if self .connection :
600+ return set (self .connection .sql_mode .split ("," ))
600601 with self .cursor () as cursor :
601602 cursor .execute ("SELECT @@sql_mode" )
602603 sql_mode = cursor .fetchone ()
0 commit comments