Skip to content

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

@rpcolom

Description

@rpcolom

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

  • Rails version: 7.1.3.4

  • SQL Server adapter version: 7.1.4

  • TinyTDS version: 2.1.7

  • FreeTDS details: 1.4.17

Compile-time settings (established with the "configure" script)
Version: freetds v1.4.17
freetds.conf directory: /opt/homebrew/etc
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 7.3
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: yes
GnuTLS: no
MARS: yes


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions