Skip to content
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

Unexpected SQL_VARIANT casting #478

Open
pkuykendall opened this issue Aug 10, 2020 · 0 comments
Open

Unexpected SQL_VARIANT casting #478

pkuykendall opened this issue Aug 10, 2020 · 0 comments

Comments

@pkuykendall
Copy link

pkuykendall commented Aug 10, 2020

Environment

Operating System

AWS Lambda Ruby Docker container: lambci/lambda:build-ruby2.7

TinyTDS Version and Information

                           tiny_tds: 2.1.2
                            Version: freetds v1.1.20
             freetds.conf directory: /etc
     MS db-lib source compatibility: yes
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: auto
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: yes
                            OpenSSL: no
                             GnuTLS: yes
                               MARS: yes

FreeTDS Version

v1.1.20

Description

After updating tiny_tds to 2.1.2 I've noticed some weirdness with the sql_variant data type. I have an extended property with a value of true that is being converted into 1702195828. This doesn't seem to happen in v1.0.5 or in Azure Data Studio.

I believe it might be related to this logic: https://github.com/rails-sqlserver/tiny_tds/blob/master/ext/tiny_tds/result.c#L329, but I'm not completely positive. I don't know if I have a solution, but I did want to raise the issue.

I am able to work around this issue by casting the column as a VARCHAR(2000). Here is a little example:

EXEC sp_addextendedproperty @name='is_json', @value='true'
    ,@level0type = N'Schema', @level0name = 'dbo'  
    ,@level1type = N'Table',  @level1name =  'table_name'
    ,@level2type = N'Column', @level2name = 'column_name';
result = client.execute("SELECT *, cast(value as VARCHAR(2000)) cast_val FROM FN_LISTEXTENDEDPROPERTY(NULL, 'schema', 'dbo', 'table', 'table_name', 'column', DEFAULT)")

result.each { |row| puts row }

#=> {"objtype"=>"COLUMN", "objname"=>"column_name", "name"=>"is_json", "value"=>1702195828, "cast_val"=>"true"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant