cfqueryparam将varchar转换为sql azure中的nvarchar

时间:2017-08-31 15:02:22

标签: sql-server jdbc coldfusion azure-sql-database coldfusion-2016

我在Azure中使用ColdFusion 2016中的数据库。我正在使用Sqljdbc41.jar(有关如何配置它的有用链接: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。

我认为这些是我的选择。您认为哪个更好?

  1. 尝试对您使用时的coldfusion进行逆向工程 cfqueryparam但指定了正确的数据类型(使用sp_prepexec?)
  2. 完全删除cfqueryparam的使用 在将其硬编码到查询中之前验证该字符串是否有效uuid (例如,[uuid] ='#attributes.uuid#')但是我担心在Azure SQL Performance Insight工具中将此查询的所有执行组合在一起时,我将失去可见性

1 个答案:

答案 0 :(得分:0)

非常感谢@BernhardDöbler对我需要的参数进行评论,以纠正数据源始终在Unicode中输出参数的问题。需要添加到JDBC URL的参数是sendStringParametersAsUnicode = false(具有讽刺意味的是,我首先将其从注释中复制并添加到设置中,但它不起作用b / c在几个字母之间嵌入了一些奇怪的字符。) DTU消耗的变化现在明显降低!请参阅下面的截图。 DTU consumption Performance Insight