Home

Unexpected behaviour in Premium editing grid - possible bug?

Using v4.47.02(Any CPU). When adding a new row in a SQL Server table using the editing grid, I noticed that if a non-nullable char(1) field has a default value of 'N' then the editing grid will automatically insert a single space value if a specific value is not entered for that field. I would have expected it to either pop a message about requiring an explicit value in a non-nullable field or perhaps inserting the default value automatically?

Steps to reproduce:
CREATE TABLE dbo._TestMe
(
TestID int NOT NULL IDENTITY (1, 1),
TestName nvarchar(50) NOT NULL,
TestFlag char(1) NOT NULL
)
GO
ALTER TABLE dbo._TestMe
ADD CONSTRAINT DF__TestMe_TestFlag
DEFAULT 'N' FOR TestFlag
GO
ALTER TABLE dbo._TestMe
ADD CONSTRAINT PK__TestMe
PRIMARY KEY CLUSTERED (TESTID)

Now add a new row in the grid and add just a value for TestName, e.g 'bbb' and save.

The TSQL produced is this:
-- Region Parameters
DECLARE @p0 NVarChar(1000) = 'bbb'
DECLARE @p1 Char(1) = N' '
-- EndRegion
INSERT INTO [_TestMe]([TestName], [TestFlag])
VALUES (@p0, @p1)
SELECT CONVERT(Int,SCOPE_IDENTITY()) AS [value]

The unexpected line is: DECLARE @p1 Char(1) = N' '

Why insert a space?

Interestingly, this whole chunk of SQL cannot be copied/pasted from the SQL pane in LINQPad - the copy operation fails immediately after the N', suggesting a string escaping bug somewhere?

Regards,
Bob
Sign In or Register to comment.