It's time for me to pick this project up now that the work week has
passed.

I'm attempting to implement Michael Blakeley's recommendation to move the
SQL blob content into it's own document as part of this initial load/chunk
phase.  Here's how I see the strategy.  As I iterate through each record in
a table, when there is an element with the attribute
xsi:type="xs:hexBinary", I want to extract this data, generate a new
document. replace the original element with a reference to this new
document, and then spawn two 'document-insert.xqy' operations, one for the
original document and one for the binary document.

These are my current issues.   I haven't figured out how to convert the
hexBinary into binary so that when I fetch the document I get the correct
format.  I probably need to be setting mime type.  The @xsi:type attribute
isn't part of the table_data, so I can't trigger blob processing based upon
this attribute. I'm currently only processing elements called file_blob.

My current working copy now looks like:

(: query console :)
xquery version "1.0-ml";
for $table in
xdmp:document-get('C:\Users\servicelogix\slx\us_co_slx.xml')/*/*/table_data
  let $table-name := $table/@name/string()
  let $database-name := $table/../@name/string()
  for $row in $table/row
    let $record-uri :=
concat('/',$database-name,'/',$table-name,'/id-',$row/field[@name='id'])
    let $file-uri :=
concat('/',$database-name,'/',$table-name,'/file-',$row/field[@name='id'])
    let $blob := if($row/field[@name='file_blob'][1]) then binary
{xs:hexBinary($row/field[@name='file_blob'][1])} else ()
    let $record := element { $table-name } {
      $row/field[text() and not(@name='file_blob')]/element
      { if(number(substring(@name,1,1))=number(substring(@name,1,1))) then
concat('_',@name) else @name } { text() },
      if($blob) then element file_uri { $file-uri } else ()
    }
    return (
       if($record) then xdmp:spawn('document-insert.xqy', (xs:QName('URI'),
$record-uri, xs:QName('NEW'), $record)) else (),
       if($blob) then xdmp:spawn('document-insert.xqy', (xs:QName('URI'),
$file-uri, xs:QName('NEW'), $blob)) else ()
    )
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to