@@ -276,10 +276,14 @@ def _cursor(self):
276
276
self .features .supports_mixed_date_datetime_comparisons = True
277
277
278
278
ms_drv_names = re .compile ('^((LIB)?SQLN?CLI|LIBMSODBCSQL)' )
279
+
279
280
if self .driver_needs_utf8 is None :
280
281
self .driver_needs_utf8 = False
281
- if self .drv_name == 'SQLSRV32.DLL' or ms_drv_names .match (self .drv_name ):
282
+ if self .drv_name in ( 'SQLSRV32.DLL' ,) or ms_drv_names .match (self .drv_name ):
282
283
self .driver_needs_utf8 = False
284
+ if self .drv_name in ("LIBTDSODBC.SO" ,):
285
+ self .driver_needs_utf8 = True
286
+
283
287
284
288
# http://msdn.microsoft.com/en-us/library/ms131686.aspx
285
289
if self .MARS_Connection and ms_drv_names .match (self .drv_name ):
@@ -350,6 +354,7 @@ def format_sql(self, sql, n_params=None):
350
354
# yet, so we need to encode the SQL clause itself in utf-8
351
355
sql = sql .encode ('utf-8' )
352
356
357
+
353
358
# pyodbc uses '?' instead of '%s' as parameter placeholder.
354
359
if n_params is not None and n_params > 0 :
355
360
sql = sql % tuple ('?' * n_params )
@@ -361,25 +366,35 @@ def format_sql(self, sql, n_params=None):
361
366
def format_params (self , params ):
362
367
fp = []
363
368
for p in params :
364
- if isinstance (p , text_type ):
365
- if self .driver_needs_utf8 :
366
- # FreeTDS (and other ODBC drivers?) doesn't support Unicode
367
- # yet, so we need to encode parameters in utf-8
368
- fp .append (p .encode ('utf-8' ))
369
- else :
369
+ if self .connection .drv_name in ("LIBTDSODBC.SO" ,):
370
+ if isinstance (p , text_type ):
371
+ if self .driver_needs_utf8 :
372
+ # FreeTDS (and other ODBC drivers?) doesn't support Unicode
373
+ # yet, so we need to encode parameters in utf-8
374
+ fp .append (p .encode ('utf-8' ))
375
+ else :
376
+ fp .append (p )
377
+
378
+ elif isinstance (p , binary_type ):
370
379
fp .append (p )
371
380
372
- elif isinstance (p , binary_type ):
373
- fp .append (p )
381
+ elif isinstance (p , type (True )):
382
+ if p :
383
+ fp .append (1 )
384
+ else :
385
+ fp .append (0 )
374
386
375
- elif isinstance (p , type (True )):
376
- if p :
377
- fp .append (1 )
378
387
else :
379
- fp .append (0 )
380
-
388
+ fp .append (p )
381
389
else :
382
- fp .append (p )
390
+ if isinstance (p , type (True )):
391
+ if p :
392
+ fp .append (1 )
393
+ else :
394
+ fp .append (0 )
395
+
396
+ else :
397
+ fp .append (p )
383
398
384
399
return tuple (fp )
385
400
0 commit comments