rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
972 stars 559 forks source link

On INSERT stmt the table name with spaces is wrong #1203

Closed rpcolom closed 2 months ago

rpcolom commented 2 months ago

Issue

On a SELECT stmt the generate SQL string is correct. But on INSERT stmt dont get the INSERT SQL string correct with token table

Expected behavior

dbo.[2 - SOME$Contact]

Actual behavior

ActiveRecord::StatementInvalid: Table '[dbo].[2' doesn't exist

How to reproduce

require "bundler/inline"

gemfile(true) do source "https://rubygems.org" gem "tiny_tds" gem "activerecord", "7.1.3.4" gem "activerecord-sqlserver-adapter", "7.1.4" end

require "active_record" require "minitest/autorun" require "logger"

ActiveRecord::Base.establish_connection( adapter: "sqlserver", timeout: 5000, pool: 100, encoding: "utf8", database: "test_database", username: "SA", password: "StrongPassword!", host: "localhost", port: 1433 ) ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Schema.define do drop_table "[2 - SOME$TABLENAME]" rescue nil

create_table "[2 - SOME$TABLENAME]", force: true do |t| t.bigint :external_id, null: false end end

class BugTest < ActiveRecord::Base self.table_name = "[2 - SOME$TABLENAME]" end

class TestBugTest < Minitest::Test def setup @bug_test = BugTest.create!(external_id: 10) end

def test_count assert_equal 1, BugTest.count end end

Details

aidanharan commented 2 months ago

Could you create a test-case using the script in https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/How-to-report-a-bug#minimal-reproducible-script to reproduce the issue?

rpcolom commented 2 months ago

Hi Aidanharan!!

I've added the test to check the issue. For you notice, this tablename is tipical for Microsoft ERP Navision/BC.

Thanks!! Rafa

aidanharan commented 2 months ago

Issue fixed in Release v7.1.5.