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

Use existing #empty_insert_statement_value for an insert with no columns. #302

Closed
wants to merge 1 commit into from
Closed

Use existing #empty_insert_statement_value for an insert with no columns. #302

wants to merge 1 commit into from

Conversation

metaskills
Copy link
Contributor

Aaron, following up from our email exchange.
Arel has logic that does not include columns for an insert statement if they are empty. 

  def visit_Arel_Nodes_InsertStatement o
    [ "INSERT INTO #{visit o.relation}",
      ( "(#{o.columns.map { |x|
      quote_column_name x.name
    }.join ', '})" unless o.columns.empty?),
      (visit o.values if o.values),
    ].compact.join ' '
  end

The SQL Server adapter defines the older #empty_insert_statement_value method as such. This is because there is no such thing as "VALUES(DEFAULT)" that would work.

  def empty_insert_statement_value
    "DEFAULT VALUES"
  end

In the latest version of rails we are no longer using this but #null_insert_value instead and AR is hooking into it from ActiveRecord::Relation#insert like so.

  if values.empty? # empty insert
    im.values = im.create_values [connection.null_insert_value], []
  else
    im.insert substitutes
  end

This gives no one a chance to construct something like #empty_insert_statement_value for the SQLServerAdapter. We should utilize the existing #empty_insert_statement_value instead which seems more inline with Arel's InsertManager too.

@tenderlove
Copy link
Member

should be merged, so closing.

@tenderlove tenderlove closed this Apr 25, 2011
arunagw pushed a commit to arunagw/rails that referenced this pull request Apr 25, 2011
Use existing #empty_insert_statement_value for an insert with no columns.
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.

None yet

2 participants