简体   繁体   English

htmlEncode方法是否代替了对nvarchar sql数据类型的需要?

[英]does the htmlEncode method replace the need for an nvarchar sql datatype?

If i use the htmlEncode method on all strings before i write them to my database, will that remove the need to store string data as the nvarchar datatype? 如果在将所有字符串写到数据库之前对所有字符串都使用htmlEncode方法,这是否将不再需要将字符串数据存储为nvarchar数据类型?

ie. 即。 do all characters which do not exist in the varchar datatype have an encoding value that can be stored within the varchar datatype? varchar数据类型中不存在的所有字符都具有可以存储在varchar数据类型中的编码值吗?

Most likely your SQL server is using Windows-1252 encoding for char and varchar. 您的SQL Server最有可能对char和varchar使用Windows-1252编码。
If the character is not in Windows-1252 then it is stored as ? 如果该字符不在Windows-1252中,则将其存储为? mark in char and varchar. 在char和varchar中标记。

Windows-1252 Windows的1252

test by inserting 通过插入进行测试

values (nchar(10000)), ('?')

HtmlEncode(nchar(1000)) is nchar(1000) and if you store it in varchar it will be stored as ?. HtmlEncode(nchar(1000))是nchar(1000),如果将其存储在varchar中,它将存储为?。

So the direct answer to your question is yes there is an varchar encoded value for every Unicode (nvarchar). 因此,对您问题的直接答案是,每个Unicode(nvarchar)都有一个varchar编码值。
But that does not mean that it will decode back to the original value. 但这并不意味着它将解码回原始值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM