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

tSQLt.ApplyConstraint fails when constraint's name must be quoted #163

Open
CodingForFunToo opened this issue Mar 25, 2022 · 0 comments
Open

Comments

@CodingForFunToo
Copy link

When a constraint needs quotes because it contains punctuations or spaces, tSQLt.ApplyConstraint fails because it passes parameters @SchemaName and @OriginalName without quotes to procedure tSQLt.Private_MarkObjectBeforeRename. Within this proc OBJECT_ID(@SchemaName + '.' + @OriginalName) evaluates to NULL.

T-SQL Code to reproduce:

create table dbo.MasterTbl(id int not null identity constraint [PK_Master] primary key clustered);

create table dbo.ChildTbl
(
  id int not null identity constraint [PK_Child] primary key clustered
, masterId int not null constraint [FK.with.dots and spaces] foreign key references dbo.MasterTbl(id)
);

EXEC tSQLt.NewTestClass @ClassName = N'ConstraintTests';

CREATE PROCEDURE ConstraintTests.[test that fails to execute]
as
begin
exec tSQLt.FakeTable @TableName       = N'dbo.MasterTbl';
exec tSQLt.FakeTable @TableName       = N'dbo.ChildTbl';
exec tSQLt.ApplyConstraint @TableName = N'dbo.ChildTbl', @ConstraintName = N'FK.with.dots and spaces';

exec tSQLt.Fail @Message0 = N'Will never be executed, because tSQLt.ApplyConstraint fails';
end
GO

exec tSQLt.Run @TestName = N'ConstraintTests';

exec tSQLt.DropClass @ClassName = N'ConstraintTests';
drop table dbo.ChildTbl;
drop table dbo.MasterTbl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants