-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for SQL Variant fields #356
base: dev
Are you sure you want to change the base?
Conversation
sql_variant fields in databases causes the following error "ODBC SQL type -150 is not yet supported. column-index=0 type=-150', 'HY106'" This commit converts these fields into a string and returns
Hi @akilude, thank you for contributing. Could you provide a test case for this feature? |
Hi, Sure, will add it early next week. |
@dauinsight, could you please give me a couple of pointers on how to provide a test case for this. This feature will mainly be used with existing external databases. When we have an external mssql database with a field of type "sql_variant", this PR will convert the data to string and return it to django. I think there are only test cases for database created with django? |
Good question, we can use Django's RunSQL function to make a custom migration with a sql_variant type: https://docs.djangoproject.com/en/5.0/ref/migration-operations/#runsql |
Hi @akilude, an example test might look like:
|
Thanks @dauinsight, bit busy with work, will add it in a day or two. |
@dauinsight, apologies for the delay, have added the test case. Please let me know if any changes are needed. Thanks. |
@@ -83,6 +83,9 @@ def encode_value(v): | |||
return '{%s}' % (v.replace('}', '}}'),) | |||
return v | |||
|
|||
def handle_sql_variant_as_string(value): | |||
# SQL variant of type 150 is not supported, convert it to string and return | |||
return value.decode('utf-16le') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too familiar with the sql_variant type but it looks like this method of decoding is likely to result in incorrect data.
Since sql_variant can contain multiple types, unpacking the data in a reliable manner seems difficult... We might be better off doing an explicit CAST in sql.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dauinsight We can find the base type of the field https://learn.microsoft.com/en-us/sql/t-sql/functions/sql-variant-property-transact-sql?view=sql-server-ver16
in the converter function, shall we convert whatever type to string and return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dauinsight, please let me know the best way to proceed. Thanks.
Adds support for sql_variant field which causes the following error:
"ODBC SQL type -150 is not yet supported. column-index=0 type=-150', 'HY106'"
This commit converts these fields output to a string