xquery version "0.9-ml"
(:
 : SharePoint Connector request main module
 :
 : Copyright (c) 2002-2009 Mark Logic Corporation. All Rights Reserved.
 :)
import module namespace mlsp="http://marklogic.com/sharepoint" at "sharepoint.xqy"

declare namespace qm = "http://marklogic.com/xdmp/query-meters"
       
define variable $COMMAND as xs:integer external (: See command constants in sharepoint.xqy :)
define variable $PATH as xs:string external     (: SharePoint full document path :)
define variable $METADATA as xs:string external (: Subset of SharePoint document metadata in XML :)

let $md := 
  if (exists($METADATA) and string-length($METADATA)) then
    xdmp:unquote($METADATA)
  else
    <mlsp:item/>
let $r := mlsp:mlc-request($COMMAND, $PATH, $md/*)
let $ts := concat("server=", xdmp:server-name(xdmp:server()), 
    " cmd=", $COMMAND, " path=", $PATH, 
    " $METADATA=", $METADATA, " code=", $r[1], " msg=", $r[2])
return
(
  $r,
  if (xs:integer($r[1]) ge 300) then
    xdmp:trace("SPC errors", $ts)
  else
    xdmp:trace("SPC requests", $ts)
)
,
xdmp:trace("SPC perf", concat("cmd=", $COMMAND, " ", xdmp:query-meters()/qm:elapsed-time))
  