File: admin_xquery_main.vsp

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (365 lines) | stat: -rw-r--r-- 10,776 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?vsp 
--  
--  $Id$
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2012 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  
 adm_pre_page(lines);

  declare _stmt varchar;
  declare _maxres integer;
  declare _docontext varchar;
  declare m_dta, m_dta_col, result, exp_result any;
  declare inx, jnx, n_cols integer;
  declare col_names varchar;
  declare col_types varchar;
  declare res_row varchar;
  declare res_col varchar;
  declare res_cols, pos integer;
  declare err_sqlstate, err_msg, fpath, url, tbl, kcol, dcol varchar;


  declare _current_uri, _show_browser, _disp_result, _sys, _mod, _file, _sty varchar;
  declare _dav_result any;

  if (not adm_check_auth (lines)) {adm_tell_unauth(lines); return (0);}

  _show_browser := null;
  _dav_result := null;
  _current_uri := 'admin_xquery_main.vsp';
  _disp_result := 'yes';

  if ('' <> get_keyword ('dav_resource', params, ''))
    {
      _show_browser := 'yes';
      _disp_result := 'no';
    }

?>

<?include admin_dav/admin_dav_browse.vsp?>

<?vsp
  if (_show_browser is null)
    {

-- dbg_obj_print ('params =', params);
--
-- Reset initializes fields to default values
--

  fpath := get_keyword ('fpath', params, 'xqdemo/nosuchfile.xml');
  _stmt := get_keyword   ('stmt', params, '');
  tbl := get_keyword   ('tbl', params, 'XQ.XQ.TEST_FILES');
  kcol := get_keyword  ('tbkey', params, '');
  dcol := get_keyword  ('tbdt', params, '');
  url := get_keyword   ('url', params, '');

  if (_dav_result is not null)
    fpath := _dav_result;

  if (tbl = 'Use the URI')
    fpath := '';

 if (tbl = 'XQ.XQ.TEST_FILES' and fpath = '')
   fpath := 'xqdemo/nosuchfile.xml';


  if (tbl <> '' and tbl <> 'Use the URI')
    url := '';

  if (not is_empty_or_null (get_keyword ('reset', params)))
    {
      _maxres := 100;
      _stmt := '';
      _docontext := '';
--    _docontext := 'virt://XQ.XQ.TEST_FILES.NAME.TEXT:xqdemo/nosuchfile.xml';
    }
  else

    {
      _maxres := get_keyword ('maxres', params);
      _stmt := get_keyword ('stmt', params);
      -- _docontext := coalesce (get_keyword ('docontext', params), 'virt://XQ.XQ.TEST_FILES.NAME.TEXT:xqdemo/nosuchfile.xml');
      if ({?'stmt_id'} is not null)
	{
	   for select cast  (p as varchar ) as stmt1
	     from ws..sys_dav_res where RES_ID = atoi ({?'stmt_id'}) and xpath_contains (res_content, '//xquery' , p) do
	       {
		 _stmt := stmt1;
	       }


	}
    _docontext := {?'docontext'};
      if (_docontext is not NULL)
	{
	    _docontext := trim (_docontext);
	    if ("LEFT" (_docontext, 5) <> 'virt:')
	      {
                tbl := 'Use the URI';
		url := _docontext;
		fpath := '';
	      }
	    else
	      {
                _docontext := subseq (_docontext, 7);
	        pos := strstr (_docontext, ':');
		if (pos is not NULL)
		  {
                     fpath := subseq (_docontext, pos + 1);
	             _docontext := "LEFT" (_docontext, pos);
                     _docontext := split_and_decode (_docontext, 0, '\0\0.');
		     tbl := sprintf ('%s.%s.%s', _docontext[0], _docontext[1], _docontext[2]);
		     kcol := _docontext[3];
                     dcol := _docontext[4];
 		     url := '';
		  }
		_docontext := trim ({?'docontext'});
	      }
	}
    }
	if ({?'docontext'} is null)
	{
	      if (url <> '' or tbl = 'Use the URI')
		{
		   _docontext := get_keyword ('url', params);
		}
	      else
		{
		  _docontext := sprintf ('virt://%s.%s.%s:%s', tbl, kcol, dcol, fpath);
		}
	}
?>
<SCRIPT LANGUAGE="JavaScript">
<!--
function savetemplate (what)
{
  document.forms[0].action = '/admin/admin_dav/admin_xml_template.vsp';
  document.forms[0].load_template.value = what;
  if (document.forms[0].tbl.value == 'Use the URI')
    {
      document.forms[0].q_scope.value = document.forms[0].url.value;
    }
  else
    {
      var tbl, kcol, dcol, fpath;
      tbl = document.forms[0].tbl.value;
      kcol = document.forms[0].tbkey.value;
      dcol = document.forms[0].tbdt.value;
      fpath = document.forms[0].fpath.value;
      document.forms[0].q_scope.value = 'virt://'+tbl+'.'+kcol+'.'+dcol+':'+fpath;
    }
  //alert (document.forms[0].q_scope.value);
  document.forms[0].submit;
}
// -->
</SCRIPT>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="<?=adm_what_css()?>">
    <meta name="AUTHOR" content="OpenLink Software">
    <meta name="DESCRIPTION" content="Interactive XQuery using Virtuoso VSP">
    <title>Interactive XQuery</title>
  </head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function tbls_get ()
{
  document.xqform.submit();
}
// -->
</SCRIPT>
<?vsp adm_page_header('Interactive XQuery', NULL); ?>
<?include adm_js_check.vsp ?>

    <form method="POST" action="admin_xquery_main.vsp" name="xqform">
  <TABLE CLASS="genlist" BORDER="0" CELLPADDING="0" CELLSPACING="2">
      <tr><td ALIGN="right">
        <table BORDER="0" CELLPADDING="0" CELLSPACING="2">
	<input type="hidden" name="maxres" value="<?= coalesce(_maxres,100) ?>">
	<tr><td class="genlisthead" colspan="2" ><b>Document Context</b></td></tr>
        <tr>
	   <td class="genlisthead">Table</td>
	   <td>
             <select name="tbl" onChange="tbls_get();">
	     <option>Use the URI</option>
<?vsp
        declare kcol, tbls, ch any;
        kcol := NULL;
        tbls := get_keyword ('tbl', params, NULL);
	if (tbl <> '') tbls := tbl;
        for select distinct \TABLE as TBL, COL_CHECK from SYS_COLS where COL_CHECK like '% U %' do
	    {
	      if (tbls is null)
	        tbls := 'XQ.XQ.TEST_FILES';
	      ch := '';
	      if (TBL = tbls)
	        ch := 'SELECTED';

?>
	     <option <?=ch?>><?=TBL?></option>
<?vsp
	    }
?>
            </option>
	   </td>
	   </tr>


        <tr>
	   <td class="genlisthead">Key column</td>
	   <td>
	    <select name="tbkey">
<?vsp
        for select distinct COL_CHECK from SYS_COLS where \TABLE = tbls and COL_CHECK like '% U %' do
	   {
             kcol := get_keyword ('U', split_and_decode (trim(COL_CHECK), 0, '\0\0 '), '** NOT AVAILABLE *');
?>
	     <option><?=kcol?></option>

<?vsp
	   }
?>
            </select>
	   </td></tr>
        <tr>
	   <td class="genlisthead">Data column</td>
	   <td>
	    <select name="tbdt">
<?vsp
        for select distinct \COLUMN as COL from SYS_COLS where \TABLE = tbls and COL_CHECK like '% U %' do
	   {
?>

	     <option><?=COL?></option>
<?vsp
	   }
?>

            </select>
	   </td></tr>
        <tr>
	   <td class="genlisthead">Path</td>
	   <td><input type="text" name="fpath" value="<?=fpath?>">
<?vsp
          if (tbls = 'WS.WS.SYS_DAV_RES')
            {
	      http('<input type=submit name="dav_resource" value="Browse"/>');
	    }
?>
	   </td></tr>
	<tr>
	<td class="genlisthead">*Base URL<small>(optional)</small></td>
        <td><input type="text" name="url" value="<?= url ?>"></td>
      </tr>
      </table></tr><tr>
        <td class="genlistheadt">XQuery Statment</td>
      </tr><tr>
        <td><textarea name="stmt" rows="10" cols="80"><?= coalesce(_stmt, '') ?></textarea></td>
      </tr>
      <tr><td ALIGN="right">
        <input type=hidden name="caller_uri" value="/admin/admin_xquery_main.vsp?qtype=xquery">
	<input type="hidden" name="q_scope" value="<?=_docontext?>">
	<input type="hidden" name="qtype" value="xquery">
	<input type="hidden" name="load_template" value="">
        <input type="hidden" name="saved_file" value="<?= get_keyword ('saved_file', params, '') ?>">
        <input type="submit" name="execute" value="Execute">
	<input type="submit" name="save" value="Save" onClick="savetemplate('');">
	<input type="submit" name="load" value="Load" onClick="savetemplate('xquery');">
        <input type="submit" name="reset" value="Reset">
        </td></tr>
  </table>

<?vsp adm_page_break(); ?>

<?vsp

  if (not is_empty_or_null (get_keyword ('execute', params)))
    {


      if (not is_empty_or_null (_stmt))
      {
	declare err_sqlstate1, err_msg1 varchar;
	  err_sqlstate := '00000';
	  err_msg := 'none';
          err_sqlstate1 := '00000';
          err_msg1 := 'none';
--
--        a fresh transaction, right out of the oven...
--
	  commit work;
	  _stmt := sprintf ('select xquery_eval (%s, xper_doc (\'<blank/>\',0, \'%s\'), 0)', WS.WS.STR_SQL_APOS(_stmt), _docontext);

          exec (_stmt, err_sqlstate, err_msg, vector(),
                atoi (_maxres), m_dta, result);

	  exec ('commit work', err_sqlstate1, err_msg1);
	  if ('00000' <> err_sqlstate)
	    {
              http ('<TABLE class="genlist" BORDER="0" CELLPADDING="0">');
              http ('<TR><TD class="errorhead" COLSPAN="2">Execution Error</TD></TR>');
	      http (sprintf ('<TR><TD class="genlisthead">SQL State</TD><TD class="gendata">%V</TD></TR>',
		    err_sqlstate));
	      http (sprintf ('<TR><TD class="genlisthead">Error Message</TD><TD class="gendata">%V</TD></TR>',
		    err_msg));
	      if ('00000' <> err_sqlstate1)
		{
		  http (sprintf ('<TR><TD class="genlisthead">Txn SQL State</TD><TD class="gendata">%V</TD></TR>',
			err_sqlstate1));
		  http (sprintf ('<TR><TD class="genlisthead">Txn Error Message</TD><TD class="gendata">%V</TD></TR>',
			err_msg1));
		}
	      http('</TABLE>');
	    }
	  else
	    {
	      http ('<table class="restable" border="0" cellpadding="0" cellspacing="2">');
	      declare cnt, num integer;
	      if (result is null or length(result)=0 or length(aref(result,0))=0)
		{
		  http('<tr><td class="resdata">The statement execution did not return a result set.</td></tr></table>');
		}
	      else
		{
		  http ('<tr><td class="restitle">XQuery result:</td></tr>');
		  result := aref( result, 0);
		  num := length (result);
		  while (cnt < num and cnt < _maxres)
		    {
		      http ('<tr>');
		      http ('<td class="resdata">');
		      http  (ADM_INDENT_XML (aref(aref(result,0), cnt)));
		      http ('</td></tr>\n');
		      cnt := cnt + 1;
		    }
		}
--	      adm_result_to_table(aref(result,0), vector(vector(vector('XQresult', 212))));
	      http ('</table>');
	    }
	  }
    }
?>
&nbsp;<?vsp adm_page_break(); ?>&nbsp;
<?vsp adm_page_footer(); ?>
</html>

<?vsp } ?>