File: blog_query.sql

package info (click to toggle)
virtuoso-opensource 6.1.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 245,116 kB
  • sloc: ansic: 639,631; sql: 439,225; xml: 287,085; java: 61,048; sh: 38,723; cpp: 36,889; cs: 25,240; php: 12,562; yacc: 9,036; lex: 7,149; makefile: 6,093; jsp: 4,447; awk: 1,643; perl: 1,017; ruby: 1,003; python: 329
file content (135 lines) | stat: -rw-r--r-- 4,093 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
--  
--  $Id: blog_query.sql,v 1.2 2006/08/16 07:58:12 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2006 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
--  
--  
create procedure make_wwwroot ()
{
  if (not exists (select 1 from HTTP_PATH where HP_LPATH = '/RPC2' and HP_HOST = '*ini*'))
    {
	  declare bapi, i, l any;
	  declare grant_stmt, gst, gmsg varchar;
	  VHOST_DEFINE (lpath=>'/RPC2', ppath=>'/SOAP/', soap_user=>'MT', soap_opts=>vector ('XML-RPC', 'yes'));
	  bapi := BLOG.."mt.supportedMethods" ();
          i := 0; l := length (bapi);
 	  while (i < l)
	    {
	      grant_stmt := 'grant execute on BLOG.DBA."'||bapi[i]||'" to "MT"';
	      gst := '00000';
	      exec (grant_stmt, gst, gmsg);
	      i := i + 1;
	    }
    }
}
;

create procedure blog_rpc_uri ()
{
  return 'http://localhost:'||server_http_port ()||'/RPC2';
}
;

create procedure sql_demo (in bid varchar)
  {
    declare req BLOG.."blogRequest";
    declare stru BLOG.."MTWeblogPost";
    req := new BLOG.."blogRequest" ();

    req.appkey := 'appKey';
    req.blogid := bid;
    req.user_name := 'bloguser';
    req.passwd := 'bloguserpass';
    stru := new BLOG.."MTWeblogPost" ();
    stru.title := 'select CompanyName from Demo.demo.Shippers';
    stru.description := '<table border="1">
    <sql:query xmlns:sql="urn:schemas-openlink-com:xml-sql" >
    select 1 as tag , null as parent, CompanyName as [tr!1!td!element] from Demo.demo.Shippers for
    xml explicit
    </sql:query>
    </table>';
    req.struct := stru;
    BLOG.metaweblog.new_Post (blog_rpc_uri (), req);
  }
;

create procedure xquery_demo (in bid varchar)
  {
    declare req BLOG.."blogRequest";
    declare stru BLOG.."MTWeblogPost";
    req := new BLOG.."blogRequest" ();

    req.appkey := 'appKey';
    req.blogid := bid;
    req.user_name := 'bloguser';
    req.passwd := 'bloguserpass';
    stru := new BLOG.."MTWeblogPost" ();
    stru.title := 'XQuery';
    stru.description :=
    '<div>
    <sql:xquery  xmlns:sql="urn:schemas-openlink-com:xml-sql"
    sql:context="http://localhost:'|| server_http_port () ||'/tutorial/apps/blog_query/">
    <![CDATA[
    <table border="1"> { for $o in document ("opml.xml")//outline
    return <tr><td>{ string ($o/@text) }</td></tr>
    }
    </table>
    ]]>
    </sql:xquery>
    </div>';
    req.struct := stru;
    BLOG.metaweblog.new_Post (blog_rpc_uri (), req);
  }
;

create procedure make_user_blog_and_posts ()
  {
    declare uid int;
    declare id any;
    declare inst DB.DBA.wa_blog2;

    if (exists (select 1 from SYS_USERS where U_NAME = 'bloguser'))
      return;
    uid := USER_CREATE ('bloguser', 'bloguserpass',
      vector ('DAV_ENABLE', 1, 'E-MAIL', 'example@domain', 'FULL_NAME', 'XML templates demo'));

    inst := new DB.DBA.wa_blog2 ();
    inst.wa_name := 'bloguser_blog';

    id := inst.wa_new_inst ('bloguser');

    whenever not found goto nf;
    select bi_blog_id into id from blog..sys_blog_info, sys_users where bi_owner = u_id and u_name = 'bloguser';

    exec ('grant select on Demo.demo.Shippers to bloguser');
    exec ('grant execute on DB.DBA.XML_URI_GET_STRING to bloguser');
    exec ('grant execute on DB.DBA.XML_URI_GET_STRING_OR_ENT to bloguser');
    commit work;
    sql_demo (id);
    xquery_demo (id);
    nf:;
  }
;

make_wwwroot ()
;

make_user_blog_and_posts ()
;