ValidateRequest error or SQL Server error?

I read this article. It says:

This symbol is present when the value is% uff1c. If this value is passed to a varchar field in a SQL database, it will be converted to a real <character. I have not seen this work in the nvarchar field

Well I think this is a SQL Server bug and not a ValidateRequest check! If I write %uff1c

, SQL Server has to save it as %uff1c

. Or at least it should encode "again" with the %uff1c

encoding chosen by the administrator.

I am wrong?

+3


source to share


2 answers


This is not a bug, but a function (but you cannot use it).

Article point: if you want to post a string containing '<', convert each <to <(FF1C Unicode encoding code) to avoid validation error.

SQL Server receives a Unicode character string containing <and tries to process it. If the datatype of the table column or procedure parameter was set to Unicode (NCHAR, NVARCHAR, 2 bytes per character), the conversion will not occur and SQL Server will retain the original value.



If the value is passed in a column or VARCHAR (1 byte per character), the character <(2-byte code) is converted to <. Extending AakashM code to illustrate:

DECLARE @nv nvarchar, @v varchar
SET @nv = N'<'
SET @v = '<'
SELECT @nv, @v, CONVERT(varchar, @nv)

<   <   <

      

But since this is the 21st century and databases must be able to support every standardized language and character and character, there are very few scenarios left that justify the use of VARCHAR data.

+2


source


SQL Server cannot store <in varchar

. What would you like in this situation:

DECLARE @v varchar(1)

SET @v = '<'

SELECT @v

      



(note that <is not a normal left parenthesis character, but rather a Unicode character with a code number FF1C

).

The result above would be <

(normal left angle bracket character). If you want to say that this is a mistake, you have to say what is your expected result.

+1


source







All Articles