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

Binary column type is being treated as a String type #476

Closed
jeremysenn opened this issue Jul 31, 2020 · 1 comment
Closed

Binary column type is being treated as a String type #476

jeremysenn opened this issue Jul 31, 2020 · 1 comment

Comments

@jeremysenn
Copy link

jeremysenn commented Jul 31, 2020

Environment

Operating System

ProductName: Mac OS X
ProductVersion: 10.15.5
BuildVersion: 19F101

Rails version: 6.0.3
SQL Server adapter version: 6.0.0
SQL Server: 2012

TinyTDS Version and Information

TinyTDS version: 2.1.2

Version: freetds v1.00.21
freetds.conf directory: /usr/local/Cellar/freetds/1.00.21/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 7.3
iODBC: no
unixodbc: no
SSPI "trusted" logins: no
Kerberos: no
OpenSSL: yes
GnuTLS: no
MARS: no

FreeTDS Version

freetds v1.00.21

Description

A table's image/binary type column is being treated as a string type column, which results in the following error when saving blob image data to that column:

ActiveRecord::StatementInvalid: ArgumentError: string contains null byte

The same exact image/binary column is correctly shown as a binary column in earlier versions (SQL Server adapter version 4.1.4 and TinyTDS version 1.0.5), allowing for successful saving of blob image data to the column.

@jeremysenn
Copy link
Author

Turns out this issue was similar to this one:

rails-sqlserver/activerecord-sqlserver-adapter#643

I created a custom attribute in an initializer (rails_sqlserver_types.rb):

ActiveRecord::Type.register(:var_binary_max, ActiveRecord::Type::SQLServer::VarbinaryMax)

And then applied the custom attribute in the model:

attribute :jpeg_image, :var_binary_max

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