File: admin_link_proc_1.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 (536 lines) | stat: -rw-r--r-- 16,955 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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<?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 _dsn, _user, _pass varchar;
   declare ses, type1, type2, link_errors any;
   declare _deni integer;
   _deni := 0; link_errors := '';
   _dsn := _user := _pass := '';
  --dbg_obj_print ('params : ', params);
  if (not adm_check_auth (lines)) { adm_tell_unauth (lines); return (0); }

  type1 := vector ('INTEGER',
	            'NUMERIC',
		    'DECIMAL',
		    'DOUBLE PRECISION',
		    'REAL',
		    'CHAR',
		    'CHARACTER',
 	            'VARCHAR',
		    'NVARCHAR',
		    'ANY',
		    'NCHAR',
		    'SMALLINT',
		    'FLOAT',
		    'DATETIME',
		    'DATE',
		    'TIME',
		    'BINARY');

  type2 := vector ('*Default*', '',
	           'xsd:string', 'http://www.w3.org/2001/XMLSchema:string',
		   'xsd:int', 'http://www.w3.org/2001/XMLSchema:int',
		   'xsd:float','http://www.w3.org/2001/XMLSchema:float',
		   'xsd:double','http://www.w3.org/2001/XMLSchema:double',
		   'xsd:decimal','http://www.w3.org/2001/XMLSchema:decimal',
		   'xsd:dateTime', 'http://www.w3.org/2001/XMLSchema:dateTime',
		   'void', '__VOID__'
	     );

  for select SDT_NAME from SYS_SOAP_DATATYPES do
     {
       type2 := vector_concat (type2, vector(SDT_NAME, concat ('services.wsdl:', SDT_NAME)));
     }

  _dsn := get_keyword ('dsn', params , '');
  _user := get_keyword ('user', params , '');
  _pass := get_keyword ('pass', params , '');

  declare infos, dbms, driv any;
  infos := vector ();
  if (_dsn <> '')
    {
      whenever not found goto nfnd;
      select deserialize (DS_CONN_STR) into infos from DB.DBA.SYS_DATA_SOURCE where DS_DSN = _dsn;
nfnd:;
    }
  dbms := upper (get_keyword (17, infos, ''));
  driv := upper (get_keyword (6, infos, ''));
--  dbg_obj_print (dbms,driv);

  ses := string_output();

  if ({?'link1'} is not null)
    {
      declare i, l, j integer;
      declare pro, stmt, st, msg varchar;
      j := 0;
      while (pro := adm_next_checkbox ('PR_', params, j))
	{
	  declare pars any;
	  declare q,o,n, par, typ varchar;
	  declare q1,o1,n1, cmn1 varchar;
	  declare meta any;
          meta := vector ();
          q := get_keyword (sprintf ('Q_%s',pro), params, '');
          o := get_keyword (sprintf ('O_%s',pro), params, '');
          n := get_keyword (sprintf ('N_%s',pro), params, '');
          if (__proc_exists (sprintf ('%s.%s.%s',q,o,n)))
	    {
              link_errors := concat (link_errors, sprintf ('<TR><TD class="gendata">%s.%s.%s</TD><TD CLASS="gendata">Already linked</TD></TR>',q,o,n));
              goto next_loop;
	    }


          q1 := name_part (pro, 0);
          o1 := name_part (pro, 1);
          n1 := name_part (pro, 2);
          cmn1 := get_keyword (sprintf ('PRN_%s', pro), params, n1);
          if (cmn1 <> n1) n1 := cmn1;
          stmt := 'attach procedure ';
          if (q1 = '')
	    {
              stmt := concat (stmt, sprintf (' "%I"."%I" (', o1,n1));
            }
          else
	    {
              stmt := concat (stmt, sprintf (' "%I"."%I"."%I" (', q1,o1,n1));
            }

          pars := get_keyword (sprintf ('P_%s',pro), params, NULL);
	  if (pars is not null)
            pars := deserialize (decode_base64 (pars));
	  else
	    pars := vector ()
	    ;
          declare br integer;
          i := 0; l := length (pars); br := 0;
	  while (i < l)
	    {
	      declare t, na, dt, st, t1 varchar;
              t1 := '';
	      if (not isarray (pars[i]))
	        goto nexti;
              na := pars [i][1];
	      t := pars [i][0];


	      dt := get_keyword (sprintf ('%s_%s_t',pro, na), params, pars [i][2]);
	      st := get_keyword (sprintf ('%s_%s_s',pro, na), params, '');

              --if (t = 'UNDEFINED')
              t1 := get_keyword (sprintf ('%s_%s_io',pro, na), params, '');
	      if (t1 <> '')
		t := t1;

              meta := vector_concat (meta, vector (vector (t, concat('"',na,'"'), dt, st)));

	      if (t = 'RESULTSET')
		{
	          goto nexti;
		}

	      if (t = 'RETURNS')
	        {
	          stmt := concat (trim (stmt, ', '), ') RETURNS ', dt);
		  br := 1;
		}
	      else if (t <> 'RESULTSET')
		{
                  stmt := concat (stmt, t, ' ', na, ' ', dt);
		}
	      if (st <> '')
		{
                  stmt := concat (stmt, ' __soap_type ''', st, '''');
		}
              stmt := concat (stmt, ',');
nexti:
              i := i + 1;
	    }
          stmt := trim (stmt, ', ');

	  if (not br)
            stmt := concat (stmt, ')');

          stmt := concat (stmt, sprintf (' as "%I"."%I"."%I" from ''%s''', q,o,n, _dsn));

          -- here we are ready to attach
	  declare att_type varchar;
	  att_type := '';
          att_type := get_keyword (sprintf ('wrap_%s', pro), params, '');
	  if (att_type = 'wrap' or att_type = 'rset')
	    {
	      declare make_resultset integer;
	      declare _comment varchar;
              _comment := get_keyword (sprintf ('COMMENT_%s',pro), params, '');
	      if (att_type = 'rset')
		make_resultset := 1;
	      else
		make_resultset := 0;
	      st := '00000';
              vd_remote_proc_wrapper (_dsn, pro, concat (q,'.',o,'.',n), meta, st, msg, make_resultset, _comment);
	    }
	  else
	    {
	      st := '00000';
	      exec (stmt, st, msg);
	    }

	  if (st <> '00000')
	    {
  	      http ('<TABLE CLASS="genlist" BORDER="0" CELLPADDING="0">', ses);
  	      http (sprintf ('<TR><TD CLASS="errorhead" COLSPAN="2">Link of procedure from %s failed:</TD></TR>', _dsn), ses);
  	      http ('<TR><TD CLASS="AdmBorders" COLSPAN="2"><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="2" ALT=""></TD></TR>', ses);
 	      http (sprintf ('<TR><TD CLASS="genlisthead">SQL State</TD><TD CLASS="gendata">%s</TD></TR>', coalesce (st, '')), ses);
 	      http (sprintf ('<TR><TD CLASS="genlisthead">Error Message</TD><TD CLASS="gendata">%s</TD></TR>', coalesce (msg, '')), ses);
  	      http ('</TABLE>', ses);
              params := deserialize(decode_base64 (get_keyword ('all_pars', params, encode_base64(serialize(vector())))));
	      goto err_end;
	    }
next_loop:;
	}
      if (link_errors = '')
        {
          http_request_status ('HTTP/1.1 302 Found');
          http_header ('Location: admin_link_proc.vsp\r\n');
	  return;
	}
      else
	{
?>
<html>
  <head>
  <link rel="stylesheet" type="text/css" href="<?=adm_what_css()?>">
  <script language="javascript" src="admin_utils.js"></script>
    <title>External procedures management</title>
    <meta name="AUTHOR" content="OpenLink Software">
    <meta name="DESCRIPTION" content="Link External Procedures into Virtuoso using VSP">
  </head>
  <BODY>
<?vsp  adm_page_header('External Procedures Management', NULL); ?>
   <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="2">
   <tr><TD CLASS="genlistheadt" align=center>Procedure</TD><TD CLASS="genlistheadt" >Status</TD></tr>
   <FORM method=POST action="admin_link_proc.vsp">
   <?vsp http(link_errors); ?>
   <TR><TD colspan=2 align=center><input type=submit name="OK" value="OK"></TD></TR>
   </FORM>
   <TABLE>
  </TD></TR></TABLE>
<?vsp adm_page_footer(); ?>
</BODY>
</HTML>
<?vsp
	  return;
	}
    }
err_end:;
?>

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">

<html>
  <head>
  <link rel="stylesheet" type="text/css" href="<?=adm_what_css()?>">
  <script language="javascript" src="admin_utils.js"></script>
    <title>External procedures management</title>
    <meta name="AUTHOR" content="OpenLink Software">
    <meta name="DESCRIPTION" content="Link External Procedures into Virtuoso using VSP">
  </head>
  <BODY>
<?vsp  adm_page_header('External Procedures Management', NULL); ?>
<?include adm_js_check.vsp ?>



  <FORM name="sel_list" method="POST" action="admin_link_proc_1.vsp">
   <input type=hidden name=dsn value="<?=_dsn?>">
   <input type=hidden name=user value="<?=_user?>">
   <input type=hidden name=pass value="<?=_pass?>">
   <input type=hidden name=all_pars value="<?=encode_base64(serialize(params))?>">


<?vsp

   http (string_output_string(ses));

   if ({?'link'} is not null)
     {
?>

  <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="2"><TR><TD>
<!--
   <TR><TD CLASS="genhead" COLSPAN="3">Link the External Procedures</TD></TR>
   <TR><TD CLASS="AdmBorders" COLSPAN="3"><IMG SRC="images/1x1.gif" WIDTH="1" HEIGHT="2" ALT=""></TD></TR>
   -->
<?vsp

       if (_dsn <> '')
	 {
           declare pro, q,o,n, q1,o1,n1, lname any;
	   declare i, l, j integer;
           i := 0;
	   --dbg_obj_print (params);
           while (pro := adm_next_checkbox ('PR_', params, i))
             {
	       declare ncm varchar;
	        q := name_part (pro, 0);
	        o := name_part (pro, 1);
	        n := name_part (pro, 2);
	       ncm := get_keyword (sprintf ('PRN_%s', pro), params, n);
	       if (ncm <> n)
                 n := ncm;

                lname := att_local_name (_dsn, pro);

	        q1 := name_part (lname, 0);
	        o1 := name_part (lname, 1);
	        n1 := SYS_ALFANUM_NAME(n);


		declare cols, ncols, k, wrapit any;
		declare pars varchar;
		if (q = '') q := NULL;
	        cols := sql_procedure_cols (_dsn, q, o, n, NULL);
		--dbg_obj_print (cols);
                j := 0; l := length (cols); k := 0;
                ncols := make_array (l, 'any');
                wrapit := '';
		while (j < l)
		  {
		    declare stype, sprec, sscale any;
		    declare type, prec, scale, ty, nam, lopts any;
		    --dbg_obj_print (cols[j]);
                    stype := cols[j][5];
                    sprec := cols[j][7];
                    sscale := cols[j][10];
		    att_sql_to_dv_type (stype, sprec, sscale, null, null, type, prec, scale, lopts);
                    ty := case cols[j][4]
			    when 1 then 'IN'
			    when 4 then 'OUT'
			    when 2 then 'INOUT'
			    when 3 then 'RESULTSET'
			    when 5 then 'RETURNS'
			    else 'UNDEFINED'
			  end;
                    if (ty = 'OUT' and cols[j][6] = 'PL/SQL TABLE')
		      {
		        ty := 'RESULTSET';
		      }
                     wrapit := 'checked';

                    nam := SYS_ALFANUM_NAME (cols[j][3]);
		    --dbg_obj_print (cols[j][17], cols[j][3], dv_type_title (type), prec, scale, cols[j][4]);
		    if (cols[j][4] <> 5 and length (cols[j]) > 16 and cols[j][17] <= l)
		      {
 		        aset (ncols, cols[j][17] - 1, vector (ty,nam, dv_type_title (type)));
		      }
		    else if (cols[j][4] <> 5)
		      {
 		        aset (ncols, k, vector (ty,nam, dv_type_title (type)));
                        k := k + 1;
		      }
	            else
                      aset (ncols, l - 1, vector (ty, nam, dv_type_title (type)));
                    j:=j+1;
		  }
		--dbg_obj_print (ncols);

?>

   <TABLE CLASS="genlist" BORDER="0" CELLPADDING="0" CELLSPACING="2">
     <TR>
     <TD rowspan="3" valign="top"><input type="checkbox" name="PR_<?=pro?>" checked></TD>
     <input type="hidden" name="P_<?=pro?>" value="<?= encode_base64 (serialize (ncols)) ?>">
     <input type="hidden" name="PRN_<?=pro?>" value="<?= n ?>">
     <TD CLASS="genlisthead" NOWRAP>External Name</TD>
<?vsp
    declare _den, _p_pat varchar;
    _den := '';
    _p_pat := pro;
    _p_pat := replace (_p_pat, '*', '\\*');
    _p_pat := replace (_p_pat, '+', '\\+');
    _p_pat := replace (_p_pat, ']', '\\]');
    _p_pat := replace (_p_pat, '[', '\\[');
    _p_pat := replace (_p_pat, '(', '\\(');
    _p_pat := replace (_p_pat, ')', '\\)');
    _p_pat := replace (_p_pat, '.', '\\.');
    if (exists (select 1 from SYS_PROCEDURES where
	  regexp_match (sprintf ('\-\-"DSN:%s PROCEDURE:%s"',
	      _dsn, _p_pat),
	    coalesce (P_TEXT, blob_to_string(P_MORE))) is not null))
      {
        _den := '* ';
        _deni := _deni + 1;
      }
?>
     <TD CLASS="gendata"><?=_den?><?=o?>.<?=n?></TD>
     </TR>
     <TR>
       <TD CLASS="genlisthead" NOWRAP>Description</TD>
       <TD CLASS="geninput"><input type=text name="COMMENT_<?=pro?>" value="" size="60"></TD></TR>
     <TR><TD VALIGN="top">
     <TABLE CLASS="genlist" BORDER="0" CELLPADDING="0" CELLSPACING="2">
       <TR><TD COLSPAN="2" class="genlistheadt" NOWRAP>Local Name</TD></TR>
       <TR><TD COLSPAN="2" CLASS="geninput"><input type=text name="N_<?=pro?>" value="<?=n1?>"></TD></TR>
       <TR><TD COLSPAN="2" class="genlistheadt" NOWRAP>Database</TD></TR>
       <TR><TD COLSPAN="2" CLASS="geninput"><input type=text name="Q_<?=pro?>" value="<?=q1?>"></TD></TR>
       <TR><TD COLSPAN="2" class="genlistheadt" NOWRAP>Schema (Owner)</TD></TR>
       <TR><TD COLSPAN="2" CLASS="geninput"><input type=text name="O_<?=pro?>" value="<?=o1?>"></TD></TR>
       <TR><TD COLSPAN="2"><BR /></TD></TR>
       <TR><TD COLSPAN="2" class="genlistheadt" NOWRAP>PL Wrapper Requirements</TD></TR>
       <TR><TD CLASS="genradio" NOWRAP>
         SOAP Execution <input type=radio name="wrap_<?=pro?>" value="wrap" checked><BR />
	 SQL Execution <input type=radio name="wrap_<?=pro?>" value="rset"><BR />
	 None <input type=radio name="wrap_<?=pro?>" value="attach">
	 </TD></TR>
     </TABLE>
     </TD>

     <TD VALIGN="top">
     <TABLE CLASS="genlist" CELLPADDING="0" CELLSPACING="2" BORDER="0">
     <TR><TD CLASS="genlistheadt" COLSPAN="4">Parameters</TD></TR>
     <TR>
     <TD CLASS="genlistheadt" NOWRAP >Type</TD>
     <TD CLASS="genlistheadt" NOWRAP >Name</TD>
     <TD CLASS="genlistheadt" NOWRAP >Data Type</TD>
     <TD CLASS="genlistheadt" NOWRAP >SOAP Type</TD>
     </TR>
<?vsp
                j := 0;
                pars := '(';
                declare cl integer;
                cl := 0;
		while (j < l)
		  {
		    declare dt_type varchar;
		    if (not isarray(ncols[j]))
		      goto next_j;
                    dt_type := ncols[j][2];
	            if (dt_type = 'NVARCHAR'
			and (driv like 'OPL%' or driv like 'SQL_%')
			and upper (sys_stat ('st_build_opsys_id')) <> 'WIN32')
		      {
                         dt_type := 'VARCHAR';
		      }
                    if (ncols[j][0] <> 'RETURNS')
		      {
                        pars := concat (pars, ncols[j][0], ' ', ncols[j][1], ' ', dt_type, ', ');
?>
                        <TR>
			  <TD CLASS="gendata">
                            <?vsp
			       if (ncols[j][0] = 'RESULTSET')
				 {
                            ?>
			    <?=ncols[j][0]?>
			    <?vsp
			         }
			       else
			         {
			    ?>
				<select name="<?=pro?>_<?=ncols[j][1]?>_io">
				<option name="IN" <?=select_if ('IN', ncols[j][0])?>>IN</option>
				<option name="OUT" <?=select_if ('OUT', ncols[j][0])?>>OUT</option>
				<option name="INOUT" <?=select_if ('INOUT', ncols[j][0])?>>INOUT</option>
				</select>
		            <?vsp
			         }
			    ?>
			  </TD>
			  <TD CLASS="gendata">
			    <?=ncols[j][1]?>
			  </TD>
			  <TD CLASS="geninput">
		   <?vsp adm_make_option_list (type1, concat (pro,'_',ncols[j][1],'_t') , dt_type, 0); ?>
			  </TD>
			  <TD CLASS="geninput">
		   <?vsp adm_make_option_list (type2, concat (pro,'_',ncols[j][1],'_s') , '', 1); ?>
			  </TD>
			</TR>
<?vsp
		      }
		    else
		      {
                        pars := trim (pars, ', ');
                        pars := concat (pars, ') RETURNS ', dt_type);
                        cl := 1;
?>
                        <TR>
			  <TD CLASS="gendata">
			    <?=initcap(lcase(ncols[j][0]))?>
			  </TD>
			  <TD CLASS="gendata">
			  </TD>
			  <TD CLASS="geninput">
			   <?vsp adm_make_option_list (type1, concat (pro,'_',ncols[j][1],'_t') , dt_type, 0); ?>
			  </TD>
			  <TD CLASS="geninput">
		   <?vsp adm_make_option_list (type2, concat (pro,'_',ncols[j][1],'_s') , '', 1); ?>
			  </TD>
			</TR>
<?vsp
		      }
next_j:;
		    j:=j+1;
		  }
		if (not cl)
		  {
		    pars := trim (pars, ', ');
		    pars := concat (pars, ')');
		  }

?>

     </TABLE>
     </TD></TR>
     </TABLE>
     <BR /><BR />
<?vsp
	     }
	 }

	if (_deni)
	  {
?>

  <TR><TD COLSPAN="2">* Denotes procedure already linked.</TD></TR>

<?vsp
	  }

     }

?>


  </TD></TR>
  <TR><TD  CLASS="genlist" ALIGN="right">
  <INPUT type="button" name="select_all" value="Select All" onClick="selectAllCheckboxes(this.form, this)">
  <INPUT type="submit" name="link1" value="Link Selected">
  </TD></TR></TABLE>
  </FORM>
<?vsp adm_page_footer(); ?>
</BODY>
</HTML>