Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Match 'int' as well as 'integer' when converting to SQL types for MSSQL #527

Closed
wants to merge 1 commit into from

2 participants

@seandmccarthy

(As described in Issue #526)

When doing a Rails migration that added a new column of type integer, e.g.

  change_table(:users) do |t| 
      t.integer  :sign_in_count, default: 0, null: false
      ...
  end

We were getting the following error:

cannot specify a column width on data type int

Examining the SQL output you could see that the alter table statement had appended a size parameter to the INT type, i.e. INT(10), which SQL Server does not support.

It seems to be because ArJdbc::MSSQL::type_to_sql was not matching the integer type and so not following the special case code needed for SQL Server. Instead it was delegating back up to the default implementation (which appends the size parameter to int).

This pull request makes a small change that has type_to_sql match int as well as integer. We are already using this in a monkey patch with success.

@kares
Collaborator

Thanks Sean, could we maybe add the change_table code you mentioned into a test-case ? THX

@seandmccarthy
@kares
Collaborator

Sean, would be great if you shared details on what exactly is difficult - or even better contributed a wiki page ... for now there's https://github.com/jruby/activerecord-jdbc-adapter/blob/master/RUNNING_TESTS.md maybe the test structure needs some documenting but it's not that difficult ... you can customize all the test database settings from the ENV, that means if (you're) on Windows simply setting environment variables before running rake test_mssql) ...
Please note that there are test failures since updates from users broke and no one yet cared to fix it up ... I've cleaned up the SQLServer tests once and it's quite time consuming esp. since I do not care/use MS's products that much.

@kares
Collaborator

on master as 223c3d8 thanks

@kares kares closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/arjdbc/mssql/adapter.rb
View
2  lib/arjdbc/mssql/adapter.rb
@@ -123,7 +123,7 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
'NVARCHAR(MAX)'
elsif NO_LIMIT_TYPES.include?(type_s)
super(type)
- elsif type_s == 'integer'
+ elsif type_s == 'integer' || type_s == 'int'
if limit.nil? || limit == 4
'int'
elsif limit == 2
Something went wrong with that request. Please try again.