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

Fix image columns #10

Open
wants to merge 2 commits into
base: 52-release
Choose a base branch
from

Conversation

gerhardgruber
Copy link

When using MSSQL::Type::Image columns updates to this column always bring an error like "The conversion from UNKNOWN to UNKNOWN is unsupported."

I have a JRuby on Rails application which ran very long with Rails 4.2 (quite well) and now we are upgrading it to 5.2.
Every time when we do an update on a "binary" column (which has the "image" type in the database), we get the error:

[10] pry(main)> Draft.columns_hash[ "data" ]
=> #<ActiveRecord::ConnectionAdapters::MSSQLColumn:0x4ffa078d
 @collation=nil,
 @comment=nil,
 @default=nil,
 @default_function=nil,
 @name="data",
 @null=true,
 @sql_type_metadata=#<ActiveRecord::ConnectionAdapters::SqlTypeMetadata:0x42238078 @limit=2147483647, @precision=nil, @scale=nil, @sql_type="image", @type=:image>,
 @table_name="drafts">
[11] pry(main)> d.data = "test"
=> "test"
[12] pry(main)> d.save!
DEBUG - 2019-10-17 09:44:35 (:83629:2026):    (1.4ms)  BEGIN TRANSACTION
DEBUG - 2019-10-17 09:44:35 (:83629:2026):   Draft Update (2.1ms)  UPDATE [drafts] SET [data] = ?, [updated_at] = ?, [lock_version] = ? WHERE [drafts].[id] = ? AND [drafts].[lock_version] = ?  [["data", "<4 bytes of binary data>"], ["updated_at", 2019-10-17 07:44:35 UTC], ["lock_version", 11], ["id", 192], ["lock_version", 10]]
DEBUG - 2019-10-17 09:44:35 (:83629:2026):    (2.2ms)  ROLLBACK TRANSACTION
ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: com.microsoft.sqlserver.jdbc.SQLServerException: Die Konvertierung von "UNKNOWN" in "UNKNOWN" wird nicht unterstützt.: UPDATE [drafts] SET [data] = ?, [updated_at] = ?, [lock_version] = ? WHERE [drafts].[id] = ? AND [drafts].[lock_version] = ?
from arjdbc/jdbc/RubyJdbcConnection.java:983:in `execute_prepared_update'
Caused by ActiveRecord::JDBCError: com.microsoft.sqlserver.jdbc.SQLServerException: Die Konvertierung von "UNKNOWN" in "UNKNOWN" wird nicht unterstützt.
from arjdbc/jdbc/RubyJdbcConnection.java:983:in `execute_prepared_update'
Caused by Java::ComMicrosoftSqlserverJdbc::SQLServerException: Die Konvertierung von "UNKNOWN" in "UNKNOWN" wird nicht unterstützt.
from com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:234)

After changing the type map, the code runs:

[2] pry(main)> Draft.columns_hash["data"]
=> #<ActiveRecord::ConnectionAdapters::MSSQLColumn:0x63eea8c4
 @collation=nil,
 @comment=nil,
 @default=nil,
 @default_function=nil,
 @name="data",
 @null=true,
 @sql_type_metadata=#<ActiveRecord::ConnectionAdapters::SqlTypeMetadata:0x19924f15 @limit=2147483647, @precision=nil, @scale=nil, @sql_type="image", @type=:binary>,
 @table_name="drafts">
[3] pry(main)> d.data = "test"
=> "test"
[4] pry(main)> d.save!
DEBUG - 2019-10-17 09:48:17 (:84219:2026):    (2.5ms)  BEGIN TRANSACTION
DEBUG - 2019-10-17 09:48:17 (:84219:2026):   Draft Update (8.2ms)  UPDATE [drafts] SET [updated_at] = ?, [data] = ?, [lock_version] = ? WHERE [drafts].[id] = ? AND [drafts].[lock_version] = ?  [["updated_at", 2019-10-17 07:48:17 UTC], ["data", "<4 bytes of binary data>"], ["lock_version", 11], ["id", 192], ["lock_version", 10]]
DEBUG - 2019-10-17 09:48:17 (:84219:2026):    (10.1ms)  COMMIT TRANSACTION
=> true

When using MSSQL::Type::Image columns updates to this column always bring an error like "The conversion from UNKNOWN to UNKNOWN is unsupported."
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

Successfully merging this pull request may close these issues.

1 participant