@@ -278,16 +278,14 @@ class DatabaseWrapper(BaseDatabaseWrapper): # pylint: disable=abstract-method
278
278
operators = {
279
279
"exact" : "= %s" ,
280
280
"iexact" : "LIKE %s" ,
281
- "contains" : "LIKE BINARY %s " ,
281
+ "contains" : "LIKE CAST(%s AS BINARY) " ,
282
282
"icontains" : "LIKE %s" ,
283
- "regex" : "REGEXP BINARY %s" ,
284
- "iregex" : "REGEXP %s" ,
285
283
"gt" : "> %s" ,
286
284
"gte" : ">= %s" ,
287
285
"lt" : "< %s" ,
288
286
"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) " ,
291
289
"istartswith" : "LIKE %s" ,
292
290
"iendswith" : "LIKE %s" ,
293
291
}
@@ -302,11 +300,11 @@ class DatabaseWrapper(BaseDatabaseWrapper): # pylint: disable=abstract-method
302
300
# the LIKE operator.
303
301
pattern_esc = r"REPLACE(REPLACE(REPLACE({}, '\\', '\\\\'), '%%', '\%%'), '_', '\_')"
304
302
pattern_ops = {
305
- "contains" : "LIKE BINARY CONCAT('%%', {}, '%%')" ,
303
+ "contains" : "LIKE CAST( CONCAT('%%', {}, '%%') AS BINARY )" ,
306
304
"icontains" : "LIKE CONCAT('%%', {}, '%%')" ,
307
- "startswith" : "LIKE BINARY CONCAT({}, '%%')" ,
305
+ "startswith" : "LIKE CAST( CONCAT({}, '%%') AS BINARY )" ,
308
306
"istartswith" : "LIKE CONCAT({}, '%%')" ,
309
- "endswith" : "LIKE BINARY CONCAT('%%', {})" ,
307
+ "endswith" : "LIKE CAST( CONCAT('%%', {}) AS BINARY )" ,
310
308
"iendswith" : "LIKE CONCAT('%%', {})" ,
311
309
}
312
310
@@ -355,9 +353,6 @@ def __getattr__(self, attr: str) -> bool:
355
353
356
354
def get_connection_params (self ) -> Dict [str , Any ]:
357
355
kwargs = {
358
- "charset" : "utf8" ,
359
- "use_unicode" : True ,
360
- "buffered" : False ,
361
356
"consume_results" : True ,
362
357
}
363
358
@@ -582,13 +577,17 @@ def mysql_server_data(self) -> Dict[str, Any]:
582
577
@cached_property
583
578
def mysql_server_info (self ) -> Any :
584
579
"""Return MySQL version."""
580
+ if self .connection :
581
+ return self .connection .server_info
585
582
with self .temporary_connection () as cursor :
586
583
cursor .execute ("SELECT VERSION()" )
587
584
return cursor .fetchone ()[0 ]
588
585
589
586
@cached_property
590
587
def mysql_version (self ) -> Tuple [int , ...]:
591
588
"""Return MySQL version."""
589
+ if self .connection :
590
+ return self .connection .server_version
592
591
config = self .get_connection_params ()
593
592
with mysql .connector .connect (** config ) as conn :
594
593
server_version : Tuple [int , ...] = conn .server_version
@@ -597,6 +596,8 @@ def mysql_version(self) -> Tuple[int, ...]:
597
596
@cached_property
598
597
def sql_mode (self ) -> Set [str ]:
599
598
"""Return SQL mode."""
599
+ if self .connection :
600
+ return set (self .connection .sql_mode .split ("," ))
600
601
with self .cursor () as cursor :
601
602
cursor .execute ("SELECT @@sql_mode" )
602
603
sql_mode = cursor .fetchone ()
0 commit comments