File: blog.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 (193 lines) | stat: -rw-r--r-- 5,240 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
--  
--  $Id: blog.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;
	    }
    }
}
;

make_wwwroot ()
;

drop table blog_cache
;

drop table blog_settings
;

create table blog_cache (bc_key varchar, bc_id varchar, bc_post_id varchar, bc_created datetime,
             primary key (bc_key,bc_id,bc_post_id))
;

create index blog_cache_dt on blog_cache (bc_created)
;

create table blog_settings (bs_uid varchar primary key, bs_appkey varchar, bs_blogid varchar, bs_endpoint varchar)
;

create procedure
cal_icell (inout control vspx_control, in inx int)
{
  return (control.vc_parent as vspx_row_template).te_rowset[inx];
}
;

create procedure b_get_posts (in f date)
{
 declare arr any;
 declare i, l int;
 declare mblog BLOG.DBA.blogPost;
 declare content, postid varchar;
 declare dateCreated, n datetime;
 declare appkey, blogid, uid, pwd varchar;
 appkey := connection_get('appkey');
 blogid := connection_get('blogid');
 uid := connection_get('uid');
 pwd := connection_get('pwd');
 n := now ();
 if (f is null or (year (f) = year (n) and month (f) = month (n) and dayofmonth (f) = dayofmonth (n)))
   {
     arr := BLOG.blogger.get_Recent_Posts (connection_get('endpoint'),
			      BLOG.DBA.blogRequest (appkey, blogid, '', uid, pwd),
			      60);
     i := 0; l := length (arr);
     result_names (content, dateCreated, postid);
     while (i < l)
       {
	 mblog := arr[i];
	 if (i < 10)
	   result (mblog.content, mblog.dateCreated, mblog.postid);
	 insert soft blog_cache (bc_key, bc_id, bc_post_id, bc_created)
		values (appkey, blogid, mblog.postid, mblog.dateCreated);
	 i := i + 1;
       }
  }
 else
  {
    declare sdate, edate datetime;
    sdate := f;
    edate := dateadd ('day', 1, f);
    result_names (content, dateCreated, postid);
    for select bc_post_id from blog_cache where bc_key = appkey and bc_id = blogid and
        bc_created >= sdate and bc_created < edate order by 1 desc
       do
         {
           {
             declare exit handler for sqlstate '*' { goto nexti; };
             mblog := BLOG.blogger.get_Post (connection_get('endpoint'),
			      BLOG.DBA.blogRequest (appkey, blogid, bc_post_id, uid, pwd));
             result (mblog.content, mblog.dateCreated, mblog.postid);
           }
           nexti:;
         }
  }
}
;

create procedure bb_get (in f date)
{
  declare mtd, dta any;
  declare st, msg varchar;
  st := '00000';
  exec ('b_get_posts (?)', st, msg, vector (f), 0, mtd, dta);
  if (dta = 0)
    return vector ();
  return dta;
}
;

create procedure bb_meta (in f date)
{
  declare mtd, dta any;
  declare st, msg varchar;
  st := '00000';
  exec ('b_get_posts (?)', st, msg, vector (f), -1, mtd, dta );
  if (st = '00000')
   return mtd[0];
  else
   return vector ();
}
;

create procedure
b_date_fmt (in d datetime)
returns varchar
{
  declare n date;
  n := now ();
  if (d is null)
    return '';
  if (year (d) = year (n) and month (d) = month (n) and dayofmonth (d) = dayofmonth (n))
    return sprintf ('%02d:%02d:%02d', hour (d), minute (d), second (d));
  else
    return sprintf ('%d/%d/%d', month (d), dayofmonth (d), year (d));
}
;

create procedure
b_tit_fmt (in d datetime)
returns varchar
{
  declare n date;
  n := now ();
  if (d is null or (year (d) = year (n) and month (d) = month (n) and dayofmonth (d) = dayofmonth (n)))
    return 'Previous 10 posts...';
  else
    return sprintf ('Posts for %d/%d/%d...', month (d), dayofmonth (d), year (d));
}
;

create procedure
blog_user_password (in name varchar)
{
  declare pass varchar;
  pass := NULL;
  whenever not found goto none;
  select pwd_magic_calc (U_NAME, U_PASSWORD, 1) into pass
      from SYS_USERS where U_NAME = name and U_DAV_ENABLE = 1 and U_IS_ROLE = 0;
none:
  return pass;
}
;


create procedure
cell_fmt (in x any, in y any)
{
  return BLOG..cell_fmt (x, y);
}
;