我也被这个“问题”“抓住”了。事实上,这不是问题:
问题(示例)
在 SQL 语句中使用布尔数据时,我遇到了同样的问题。在我的法语服务器上,我的 SQL 语句如下:
<%
'Set my boolean value
Dim myBoolean
myBoolean = True
'Set my SQL Statement
Dim MySQLStatement
MySQLStatement = "SELECT * FROM MyTable WHERE MyBooleanField = " & myBoolean
'=> Here, as MySQLStatement is a STRING, the boolean data was "converted/rendered" as a localized string. So that leads to this output :
'=> SELECT * FROM MyTable WHERE MyBooleanField = Vrai
'Obviously, that SQL Statement is incorrect, because the SQL Engine does NOT understand what is the "Vrai" word - It should be "True" instead.
%>
解释:
- 在您的 Windows 系统上设置哪些区域设置并不重要:基础数据不会发生任何事情。布尔数据类型仍然是BOOLEAN,使用英语、法语、德语、俄语、泰语、..或任何您想要的语言。
- 事实是数据只是被呈现为本地化字符串(如日期)。
解决方案
经过大量阅读论坛主题后,解决方案不是更改Windows系统上的区域设置,也不是更改注册表项,也不是更改Session.LCID,......绝对和纯代码的解决方案是转换布尔值( True|False) 到整数 (0|1)。然后,这个整数将在字符串中安全使用,并将保持 (0|1)。
这是以非本地化形式使用/转换/呈现布尔值的安全方法:使用整数值。
<%
'Set my boolean value
Dim myBoolean
myBoolean = True
'Set my SQL Statement
Dim MySQLStatement
MySQLStatement = "SELECT * FROM MyTable WHERE MyBooleanField = " & BoolToInt(myBoolean)
'=> Here, as MySQLStatement is a STRING, and as the boolean data was previously "converted/rendered" as an integer, we got this correct SQL Statement :
'=> SELECT * FROM MyTable WHERE MyBooleanField = 1
'This SQL Statement is correct, as the SQL Engine DOES understand that 1 is a boolean.
'This Function Returns an INTEGER value based on a BOOLEAN value
Function BoolToInt(v)
'INPUT:
'v Boolean value
'OUTPUT:
'Integer (0|1)
Dim b_OUT
b_OUT = v
'If the Input value is a "True" boolean value (in any language)
if (b_OUT = True) then
BoolToInt = cint(1)
'If the Input value is a "False" boolean value (in any language)
elseif (b_OUT = False) then
BoolToInt = cint(0)
end if
End Function 'BoolToInt
%>
我真的希望它能拯救你的一天!