<bdo id='ZBs0C'></bdo><ul id='ZBs0C'></ul>

  • <tfoot id='ZBs0C'></tfoot>
  • <small id='ZBs0C'></small><noframes id='ZBs0C'>

      <i id='ZBs0C'><tr id='ZBs0C'><dt id='ZBs0C'><q id='ZBs0C'><span id='ZBs0C'><b id='ZBs0C'><form id='ZBs0C'><ins id='ZBs0C'></ins><ul id='ZBs0C'></ul><sub id='ZBs0C'></sub></form><legend id='ZBs0C'></legend><bdo id='ZBs0C'><pre id='ZBs0C'><center id='ZBs0C'></center></pre></bdo></b><th id='ZBs0C'></th></span></q></dt></tr></i><div id='ZBs0C'><tfoot id='ZBs0C'></tfoot><dl id='ZBs0C'><fieldset id='ZBs0C'></fieldset></dl></div>

        <legend id='ZBs0C'><style id='ZBs0C'><dir id='ZBs0C'><q id='ZBs0C'></q></dir></style></legend>

        在 SQL Server XML 处理中为 modify() 参数化 XPath

        时间:2023-06-07
        <i id='QvIxg'><tr id='QvIxg'><dt id='QvIxg'><q id='QvIxg'><span id='QvIxg'><b id='QvIxg'><form id='QvIxg'><ins id='QvIxg'></ins><ul id='QvIxg'></ul><sub id='QvIxg'></sub></form><legend id='QvIxg'></legend><bdo id='QvIxg'><pre id='QvIxg'><center id='QvIxg'></center></pre></bdo></b><th id='QvIxg'></th></span></q></dt></tr></i><div id='QvIxg'><tfoot id='QvIxg'></tfoot><dl id='QvIxg'><fieldset id='QvIxg'></fieldset></dl></div>

          <bdo id='QvIxg'></bdo><ul id='QvIxg'></ul>
          <tfoot id='QvIxg'></tfoot>

                  <small id='QvIxg'></small><noframes id='QvIxg'>

                  <legend id='QvIxg'><style id='QvIxg'><dir id='QvIxg'><q id='QvIxg'></q></dir></style></legend>

                    <tbody id='QvIxg'></tbody>
                1. 本文介绍了在 SQL Server XML 处理中为 modify() 参数化 XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  正如标题所暗示的那样,我正在尝试为 SQL Server 中 XML 数据列的 modify() 方法参数化 XPath,但遇到了一些问题.

                  Just like the title suggests, I'm trying to parameterize the XPath for a modify() method for an XML data column in SQL Server, but running into some problems.

                  到目前为止我有:

                  DECLARE @newVal varchar(50)
                  DECLARE @xmlQuery varchar(50)
                  SELECT @newVal = 'features'
                  SELECT @xmlQuery = 'settings/resources/type/text()'
                  
                  UPDATE  [dbo].[Users]
                  SET     [SettingsXml].modify('
                      replace value of (sql:variable("@xmlQuery"))[1]
                      with sql:variable("@newVal")')
                  WHERE   UserId = 1
                  

                  具有以下 XML 结构:

                  with the following XML Structure:

                  <settings>
                      ...
                      <resources>
                          <type> ... </type>
                          ...
                      </resources>
                      ...
                  </settings>
                  

                  然后产生这个错误:

                  XQuery [dbo.Users.NewSettingsXml.modify()]:'replace'的目标最多只能是一个节点,找到'xs:string ?'

                  现在我意识到修改方法一定不能接受字符串作为路径,但是有没有办法不使用动态 SQL 来实现这一点?

                  Now I realize that the modify method must not be capable of accepting a string as a path, but is there a way to accomplish this short of using dynamic SQL?

                  哦,顺便说一下,我使用的是 64 位 SQL Server 2008 Standard,但我编写的任何查询都需要与 2005 Standard 兼容.

                  Oh, by the way, I'm using SQL Server 2008 Standard 64-bit, but any queries I write need to be compatible back to 2005 Standard.

                  谢谢!

                  推荐答案

                  如果有人感兴趣,我自己使用动态查询想出了一个相当不错的解决方案:

                  In case anyone was interested, I came up with a pretty decent solution myself using a dynamic query:

                  DECLARE @newVal nvarchar(max)
                  DECLARE @xmlQuery nvarchar(max)
                  DECLARE @id int
                  
                  SET @newVal = 'foo'
                  SET @xmlQuery = '/root/node/leaf/text()'
                  SET @id = 1
                  
                  DECLARE @query nvarchar(max)
                  
                  SET @query = '
                      UPDATE  [Table]
                      SET     [XmlColumn].modify(''
                          replace value of (' + @xmlQuery + '))[1]
                          with sql:variable("@newVal")'')
                      WHERE Id = @id'
                  
                  EXEC sp_executesql @query,
                                     N'@newVal nvarchar(max) @id int',
                                     @newVal, @id
                  

                  使用它,动态查询中唯一不安全的部分是 xPath,就我而言,它完全由我的代码控制,因此不应被利用.

                  Using this, the only unsafe part of the dynamic query is the xPath, which, in my case, is controlled entirely by my code and so shouldn't be exploitable.

                  这篇关于在 SQL Server XML 处理中为 modify() 参数化 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何处理 FOR XML PATH/AUTO - SQL Server 中的空白值? 下一篇:XML 数据类型方法“修改"的错误使用.在这种情

                  相关文章

                  最新文章

                  <i id='jLeBh'><tr id='jLeBh'><dt id='jLeBh'><q id='jLeBh'><span id='jLeBh'><b id='jLeBh'><form id='jLeBh'><ins id='jLeBh'></ins><ul id='jLeBh'></ul><sub id='jLeBh'></sub></form><legend id='jLeBh'></legend><bdo id='jLeBh'><pre id='jLeBh'><center id='jLeBh'></center></pre></bdo></b><th id='jLeBh'></th></span></q></dt></tr></i><div id='jLeBh'><tfoot id='jLeBh'></tfoot><dl id='jLeBh'><fieldset id='jLeBh'></fieldset></dl></div>
                2. <tfoot id='jLeBh'></tfoot>
                3. <legend id='jLeBh'><style id='jLeBh'><dir id='jLeBh'><q id='jLeBh'></q></dir></style></legend>

                  <small id='jLeBh'></small><noframes id='jLeBh'>

                    • <bdo id='jLeBh'></bdo><ul id='jLeBh'></ul>