Changes

Jump to navigation Jump to search
20 bytes added ,  18:25, 18 July 2022
no edit summary
| '''Summary'''
|Adds documents specified by {{Code|$input}} to the database {{Code|$db}} with the specified {{Code|$path}}:
* A document with the same path may occur more than once in a database. If you want to enforce single instances, use [[#db:replaceupdate|db:replaceupdate]] instead.
* See [[#db:create|db:create]] for more details on the input and path arguments.
* The parsing behavior can be controlled via {{Code|$options}}:
|}
==db:replaceupdate== {{Announce|Updated with Version 10}}: renamed (before: {{Code|db:replace}}); function signature aligned with {{Function||db:add}} (second and third argument swapped).
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:replaceupdate|$db as xs:string, $input as item(), $path as xs:string, $input as item()|empty-sequence()}}<br/>{{Func|db:replaceupdate|$db as xs:string, $input as item(), $path as xs:string, $input as item(), $options as map(*)?|empty-sequence()|empty-sequence()}}
|-
| '''Summary'''
|Replaces a resource, specified by {{Code|$path}}, in the database {{Code|$db}} with the contents of {{Code|$input}}, or adds it as a new resource:
* The parsing behavior can be controlled via {{Code|$options}}:
** Allowed options are {{Option|ADDCACHE}} and the [[Options#Parsing|parsing]] and [[Options#XML Parsing|XML parsing]] options, all in lower case.
** Parsing options will only impact string input (URIs, XML strings), because nodes have already been parsed.
* See [[#db:create|db:create]] for more details on the input argument.
* The parsing behavior can be controlled via {{Code|$options}}:
** allowed options are {{Option|ADDCACHE}} and the [[Options#Parsing|parsing]] and [[Options#XML Parsing|XML parsing]] options, all in lower case
** parsing options will only impact string input (URIs, XML strings), because nodes have already been parsed
* For historical reasons, the order of the 2nd and 3rd argument is different to [[#db:add|db:add]] and [[#db:create|db:create]]
|-
| '''Errors'''
| '''Examples'''
|
* {{Code|db:replaceupdate("DB", "docs/home/dir/doc.xml", "/homedocs/dir/doc.xml")}} replaces the content of the document {{Code|docs/dir/doc.xml}} in the database {{Code|DB}} with the content of the file {{Code|/home/dir/doc.xml}}.* {{Code|db:replaceupdate("DB", "<a/>", "docs/dir/doc.xml", "<a/>")}} replaces the content of the document {{Code|docs/dir/doc.xml}} in the database {{Code|DB}} with {{Code|&lt;a/&gt;}}.* {{Code|db:replaceupdate("DB", document { <a/> }, "docs/dir/doc.xml", document { <a/> })}} replaces the content of the document {{Code|docs/dir/doc.xml}} in the database {{Code|DB}} with the specified document node.
The following query can be used to import files from a directory to a database:
<syntaxhighlight lang="xquery">
let $path := $source || $file
where not(file:is-dir($path))
return db:replace('db', $file, doc($path), $file)
</syntaxhighlight>
|}
;Version 8.4
* Updated: [[#db:create|db:create]], [[#db:add|db:add]], [[#db:replace{{Code|db:replace]]}}: support for {{Code|ADDCACHE}} option.
* Added: [[#db:token|db:token]]
;Version 7.9
* Updated: parsing options added to [[#db:create|db:create]], [[#db:add|db:add]] and [[#db:replace{{Code|db:replace]]}}.
* Updated: allow {{Option|UPDINDEX}} if {{Code|$all}} is {{Code|true}}.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu