create procedure "VAD"."DBA"."VAD_TEST_CREATE" (
  in arr any,
  in fname varchar,
  in sticker varchar,
  in iniarr any := null )
{
  declare ctx varchar;
  ctx := md5_init();
  declare ses any;
  ses := string_output ();
  declare pos integer;
  pos := 0;
  if (iniarr is null)
    iniarr := "VAD"."DBA"."VAD_READ_INI" (arr);
  declare data any;
  declare continue handler for sqlstate '39000' { goto error_nofile; };
  declare continue handler for sqlstate '42000' { goto error_nofile; };
  string_to_file (fname, '', -2);
  error_nofile:;
  declare _err_code, _err_message varchar;
  declare exit handler for sqlstate '39000' { _err_code := __SQL_STATE; _err_message := __SQL_MESSAGE; goto error_fin; };
  declare exit handler for sqlstate '42000' { _err_code := __SQL_STATE; _err_message := __SQL_MESSAGE; goto error_fin; };
  data := 'This file consists of binary data and should not be touched by hands!';
  "VAD"."DBA"."VAD_OUT_ROW" (fname, pos, 'VAD', data, ctx);
  "VAD"."DBA"."VAD_OUT_ROW" (fname, pos, 'STICKER', sticker, ctx);
  declare i,r integer;
  data := string_output ();
  r := rnd(100);
  while (i < 1000) 
  {
    http (sprintf('%09d ',i+r), data);
    i := i + 1;
  }
  declare tree, doc, items any;
  tree := xml_tree (sticker);
  doc := xml_tree_doc (tree); 
  declare j, n integer;
  declare s2, s3, s4, s5, s6 varchar;
  items := xpath_eval ('/sticker/resources/file', doc, 0);
  n := length (items);
  j := 0; 
  while (j<n)
  {
    s2 := cast (xpath_eval ('@type', aref (items, j)) as varchar);
    s6 := cast (xpath_eval ('@source', aref (items, j)) as varchar);
    s5 := cast (xpath_eval ('@source_uri', aref (items, j)) as varchar);
    s3 := cast (xpath_eval ('@target_uri', aref (items, j)) as varchar);
    s4 := get_keyword (s6, iniarr);
    if (s4 is null or length(s4)=0)
    {
      _err_message := sprintf ('Illegal resource type:%s for %s', s2,s3); 
      goto error_fin;
    }
    if (s5 is null or length(s5)=0)
    {
      s5 := sprintf ('%s/%s', s4, s3);
    }
    if (neq (s6, 'dav')) 
      "VAD"."DBA"."VAD_OUT_ROW_FILE" (fname, pos, s3, s5, ctx);
    else    
      "VAD"."DBA"."VAD_OUT_ROW_DAV" (fname, pos, s3, s5, ctx, iniarr);
    j := j + 1;
  }
  data := md5_final (ctx);
  "VAD"."DBA"."VAD_OUT_ROW" (fname, pos, 'MD5', data, ctx);
  return 1;
  error_fin:
  "VAD"."DBA"."VAD_FAIL_CHECK" (_err_message);
  return 0;
}
;
