Skip to content

Error on query table with default column as a SQL default #412

@andretf

Description

@andretf

I get this error after upgrade to 4.2.4 from 4.1.0.
I cannot query tables with column defaulted by a SQL default constraint - which has a getdate() function.
Error is occurring at lib/active_record/connection_adapters/sqlserver/schema_statements.rb : line 319 - (at code below - it gets 320 due to line added for byebug).
I think that I showing the byebug output will explain better:

[311, 320] in /home/vagrant/.rvm/gems/ruby-2.2.2/gems/activerecord-sqlserver-adapter-4.2.4/lib/active_record/connection_adapters/sqlserver/schema_statements.rb
   311:                 [nil, default_function]
   312:               when /\A\(N'(.*)'\)\Z/m
   313:                 string_literal = SQLServer::Utils.unquote_string(Regexp.last_match[1])
   314:                 [string_literal, nil]
   315:               else
=> 316:                 type = case ci[:type]
   317:                        when /smallint|int|bigint/ then ci[:_type]
   318:                        else ci[:type]
   319:                        end
   320:                 value = default.match(/\A\((.*)\)\Z/m)[1]
(byebug)  default.match(/\A\((.*)\)\Z/m)[1]
*** NoMethodError Exception: undefined method `[]' for nil:NilClass

nil
(byebug) ci
{:table_name=>"ED_Snapshot", :name=>"esna_create_date", :type=>"datetime", :default_value=>"\r\nCREATE DEFAULT dbo.RS_d_datetime_stamp AS getdate()\r\n", :numeric_scale=>nil, :numeric_precision=>nil, :datetime_precision=>3, :ordinal_position=>2, :length=>8, :is_nullable=>nil, :is_primary=>nil, :is_identity=>false, :_type=>"datetime"}
(byebug)  ci[:default_value]
"\r\nCREATE DEFAULT dbo.RS_d_datetime_stamp AS getdate()\r\n"

I think that code should has one more case option to match SQL defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions