cfqueryparam 在 sql azure 中将 varchar 转换为 nvarchar
cfqueryparam converting varchar to nvarchar in sql azure
我正在使用 Azure 中的数据库和 ColdFusion 2016。我正在使用 Sqljdbc41.jar from (helpful links on how to configure it: link1 link2) 这是我的查询。 [uuid] 有一个索引,它是 varchar(36) 并且 pkIdentity 是一个主键 int。
select pkIdentity
from tbl1
where [uuid] = <cfqueryparam cfsqltype="cf_sql_varchar" value="#attributes.uuid#" maxlength="36">
此查询消耗了 Azure 中最多的 DTU。 Coldfusion 将其作为
发送到 Azure
(@P0 nvarchar(4000))select pkIdentity
from tbl1
where [uuid]= @P0
我读到 jdbc 驱动程序上的设置在传递给 Azure SQL 时可能是 casting the varchar datatype as varchar。但是,我在 CF 数据库设置屏幕中没有禁用到 nvarchar 的转换的选项。
我认为这些是我的选择。你觉得哪个更好?
- 当你使用
cfqueryparam 但指定正确的数据类型(使用 sp_prepexec ?)
- 完全且仅删除 cfqueryparam 的使用
在将字符串硬编码到查询之前验证该字符串是否有效 uuid
(例如 where [uuid] = '#attributes.uuid#')但是我担心我会失去对在 Azure SQL Performance Insight 工具中组合在一起的此查询的所有执行的可见性
非常感谢@BernhardDöbler 对参数的评论,我需要更正数据源总是在 Unicode 中转换参数的问题。需要添加到 JDBC URL 的参数是 sendStringParametersAsUnicode=false (具有讽刺意味的是,我首先从他的评论中复制了它并将其添加到设置中但它不起作用 b/c 有一些几个字母之间嵌入了奇怪的字符。)
现在 DTU 消耗的变化明显降低了!请参阅下面的屏幕截图。
我正在使用 Azure 中的数据库和 ColdFusion 2016。我正在使用 Sqljdbc41.jar from (helpful links on how to configure it: link1 link2) 这是我的查询。 [uuid] 有一个索引,它是 varchar(36) 并且 pkIdentity 是一个主键 int。
select pkIdentity
from tbl1
where [uuid] = <cfqueryparam cfsqltype="cf_sql_varchar" value="#attributes.uuid#" maxlength="36">
此查询消耗了 Azure 中最多的 DTU。 Coldfusion 将其作为
发送到 Azure(@P0 nvarchar(4000))select pkIdentity
from tbl1
where [uuid]= @P0
我读到 jdbc 驱动程序上的设置在传递给 Azure SQL 时可能是 casting the varchar datatype as varchar。但是,我在 CF 数据库设置屏幕中没有禁用到 nvarchar 的转换的选项。
我认为这些是我的选择。你觉得哪个更好?
- 当你使用 cfqueryparam 但指定正确的数据类型(使用 sp_prepexec ?)
- 完全且仅删除 cfqueryparam 的使用 在将字符串硬编码到查询之前验证该字符串是否有效 uuid (例如 where [uuid] = '#attributes.uuid#')但是我担心我会失去对在 Azure SQL Performance Insight 工具中组合在一起的此查询的所有执行的可见性
非常感谢@BernhardDöbler 对参数的评论,我需要更正数据源总是在 Unicode 中转换参数的问题。需要添加到 JDBC URL 的参数是 sendStringParametersAsUnicode=false (具有讽刺意味的是,我首先从他的评论中复制了它并将其添加到设置中但它不起作用 b/c 有一些几个字母之间嵌入了奇怪的字符。)
现在 DTU 消耗的变化明显降低了!请参阅下面的屏幕截图。