問題描述
我正在閱讀這篇文章.它說:
I was reading this article. It says :
該字符以值 %uff1c 表示.如果將此值傳遞給 SQL 數據庫中的 varchar 字段,它將被轉換為真正的 <特點.我還沒有在 nvarchar 字段上看到過這項工作
That character is represented at the value %uff1c. If this value is passed to a varchar field in a SQL database, it will get converted to the real < character. I have not seen this work on a nvarchar field
好吧,我認為這是一個 SQL Server 錯誤,而不是 ValidateRequest hack!如果我寫%uff1c
,SQL Server 必須將它保存為%uff1c
.或者,至少,它應該通過管理員選擇的字符集再次"編碼 %uff1c
.
Well, I think this is a SQL Server bug, not a ValidateRequest hack! If I write %uff1c
, SQL Server must save it as %uff1c
. Or, at least, it should encode "again" %uff1c
by the charset choosed by admin.
我錯了嗎?
推薦答案
這不是一個錯誤,而是一個功能(但你不能使用它).
It's not a bug, but a feature (but you cannot use it).
文章的重點是:如果你想發布一個包含'<'的字符串,將每個<到 <(Unicode 代碼點 FF1C)以避免驗證錯誤.
The point of the article is: if you want to post a string containing a '<', convert each < to a < (Unicode codepoint FF1C) to avoid a validation error.
SQL Server 收到一個包含 < 的 Unicode 字符串并嘗試對其進行處理.如果表列或過程參數的數據類型支持 Unicode(NCHAR、NVARCHAR、每個字符 2 個字節),則不會發生轉換,SQL Server 存儲原始值.
SQL Server receives a Unicode character string containing < and tries to process it. If the data type of a table column or procedure parameter was Unicode-enabled (NCHAR, NVARCHAR, 2 bytes per character), no conversion would take place, and SQL Server stores the original value.
如果將值傳遞給 VARCHAR(每個字符 1 個字節)列或變量,則字符 <(2 字節代碼點)將轉換為 <.擴展 AakashM 的代碼來說明:
If the value is passed to a VARCHAR (1 byte per character) column or variable, however, the character < (2-byte codepoint) is transformed to a <. Extending AakashM's code to illustrate:
DECLARE @nv nvarchar, @v varchar
SET @nv = N'<'
SET @v = '<'
SELECT @nv, @v, CONVERT(varchar, @nv)
< < <
但是,由于現在是 21 世紀,數據庫應該能夠支持每一種標準化的語言、符號和字符,因此可以證明使用 VARCHAR 數據的情況很少.
But, since this is the 21st century, and databases should be able to support every standardized language and symbol and character, there are very few scenarios left that justify using VARCHAR data.
這篇關于ValidateRequest 錯誤或 SQL Server 錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!