diff --git a/mssql/base.py b/mssql/base.py index 4d83a2e..c69046a 100644 --- a/mssql/base.py +++ b/mssql/base.py @@ -597,6 +597,8 @@ def _as_sql_type(self, typ, value): return 'TIME' elif isinstance(value, UUID): return 'uniqueidentifier' + elif isinstance(value, bytes): + return 'VARBINARY' else: raise NotImplementedError('Not supported type %s (%s)' % (type(value), repr(value))) diff --git a/testapp/tests/test_queries.py b/testapp/tests/test_queries.py index 785db02..5426723 100644 --- a/testapp/tests/test_queries.py +++ b/testapp/tests/test_queries.py @@ -1,8 +1,8 @@ import django.db.utils -from django.db import connections -from django.test import TransactionTestCase +from django.db import connections, connection +from django.test import TransactionTestCase, TestCase -from ..models import Author +from ..models import Author, BinaryData class TestTableWithTrigger(TransactionTestCase): def test_insert_into_table_with_trigger(self): @@ -27,4 +27,9 @@ def test_insert_into_table_with_trigger(self): finally: with connection.schema_editor() as cursor: cursor.execute("DROP TRIGGER TestTrigger") - connection.features_class.can_return_rows_from_bulk_insert = old_return_rows_flag \ No newline at end of file + connection.features_class.can_return_rows_from_bulk_insert = old_return_rows_flag + +class TestBinaryfieldGroupby(TestCase): + def test_varbinary(self): + with connection.cursor() as cursor: + cursor.execute(f"SELECT binary FROM {BinaryData._meta.db_table} WHERE binary = %s GROUP BY binary", [bytes("ABC", 'utf-8')])