Skip to content

FakeFunction fails if function is used as a column default #162

Open
@TheAceMan

Description

@TheAceMan

Receive this error:

[DefaultColumnFunction].[Test fails] failed: (Error) Message: A .NET Framework error occurred during execution of user-defined routine or aggregate "SuppressOutput":
System.Data.SqlClient.SqlException: Object '[dbo].[GetDefaultValue]' cannot be renamed because the object participates in enforced dependencies.
System.Data.SqlClient.SqlException:
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnectionSmi.EventSink.DispatchMessages(Boolean ignoreNonFatalMessages)
   at System.Data.SqlClient.SqlDataReaderSmi.InternalNextResult(Boolean ignoreNonFatalMessages)
   at System.Data.SqlClient.SqlDataReaderSmi.NextResult()
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderSmi(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
   at tSQLtCLR.TestDatabaseFacade.executeCommand(SqlString Command)
   at tSQLtCLR.StoredProcedures.SuppressOutput(SqlString command)
. | Procedure: tSQLt.SuppressOutput (0) | Severity, State: 16, 1 | Number: 6522

Script that reproduces the issue:

CREATE FUNCTION dbo.GetDefaultValue()
RETURNS INT
AS
BEGIN
       RETURN 1;
END
GO
CREATE TABLE dbo.DefaultColumnTable (DefaultColumn int DEFAULT dbo.GetDefaultValue())
GO
EXEC tSQLt.NewTestClass 'DefaultColumnFunction';
GO
CREATE FUNCTION DefaultColumnFunction.Fake_GetDefaultValue()
RETURNS INT
AS
BEGIN
       RETURN 1;
END
GO
CREATE PROCEDURE DefaultColumnFunction.[Test fails]
AS
BEGIN
       EXEC tSQLt.FakeFunction @FunctionName = 'dbo.GetDefaultValue', @FakeFunctionName = '[DefaultColumnFunction].Fake_GetDefaultValue';
END;
GO
EXEC tSQLt.RunTestClass 'DefaultColumnFunction';
GO
EXEC tSQLt.DropClass 'DefaultColumnFunction';
GO
DROP TABLE dbo.DefaultColumnTable
GO
DROP FUNCTION dbo.GetDefaultValue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions