Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
-- Пачка 5.4. Те же кейсы, что на стенде: вывод Java в файл.
CREATE OR REPLACE FUNCTION dbms_java_set_output_to_file(
    id varchar2, file_path varchar2,
    allow_replace number DEFAULT 1,
    from_stdout number DEFAULT 1,
    from_stderr number DEFAULT 1) RETURNS varchar2
    AS 'dbms_java_set_output_to_file' LANGUAGE internal;
CREATE OR REPLACE FUNCTION dbms_java_remove_output_to_file(id varchar2) RETURNS varchar2
    AS 'dbms_java_remove_output_to_file' LANGUAGE internal;
CREATE OR REPLACE FUNCTION dbms_java_enable_output_to_file(id varchar2) RETURNS varchar2
    AS 'dbms_java_enable_output_to_file' LANGUAGE internal;
CREATE OR REPLACE FUNCTION dbms_java_disable_output_to_file(id varchar2) RETURNS varchar2
    AS 'dbms_java_disable_output_to_file' LANGUAGE internal;
CREATE OR REPLACE FUNCTION dbms_java_query_output_to_file(id varchar2) RETURNS varchar2
    AS 'dbms_java_query_output_to_file' LANGUAGE internal;
CREATE OR REPLACE PROCEDURE dbms_java_initialize_output_to_file(id varchar2, path varchar2)
    AS 'dbms_java_initialize_output_to_file' LANGUAGE internal;
CREATE OR REPLACE PROCEDURE dbms_java_finalize_output_to_file(id varchar2)
    AS 'dbms_java_finalize_output_to_file' LANGUAGE internal;
CREATE OR REPLACE FUNCTION dbms_java_endsession() RETURNS varchar2
    AS 'dbms_java_endsession' LANGUAGE internal;
CREATE OR REPLACE FUNCTION dbms_java_endsession_and_related_state() RETURNS varchar2
    AS 'dbms_java_endsession_and_related_state' LANGUAGE internal;
CREATE OR REPLACE PROCEDURE dbms_java_grant_permission(grantee varchar2, permission_type varchar2, permission_name varchar2, permission_action varchar2)
    AS 'dbms_java_grant_permission' LANGUAGE internal;
CALL dbms_java_grant_permission(current_user::varchar2, 'SYS:java.io.FilePermission'::varchar2, '/tmp/jf.txt'::varchar2, 'read,write,delete'::varchar2);
DO $$
BEGIN
    CALL dbms_java_dropjava('OutF');
EXCEPTION WHEN OTHERS THEN NULL;
END $$;
DROP FUNCTION IF EXISTS rjt_outf_hi();
NOTICE:  function rjt_outf_hi() does not exist, skipping
DROP FUNCTION IF EXISTS rjt_outf_err();
NOTICE:  function rjt_outf_err() does not exist, skipping
DROP FUNCTION IF EXISTS rjt_outf_read();
NOTICE:  function rjt_outf_read() does not exist, skipping
DROP FUNCTION IF EXISTS rjt_outf_wipe();
NOTICE:  function rjt_outf_wipe() does not exist, skipping
DO $$
BEGIN
    PERFORM dbms_java_remove_output_to_file('rjt.file');
    PERFORM dbms_java_remove_output_to_file('rjt.frep');
    PERFORM dbms_java_remove_output_to_file('rjt.fstd');
    PERFORM dbms_java_endsession_and_related_state();
END $$;
CALL dbms_java_create_source('OutF', $src$
public class OutF {
    public static String hi() {
        System.out.println("hello-file");
        return "ok";
    }
    public static String err() {
        System.err.println("hello-ferr");
        return "ok";
    }
    public static String wipe() {
        new java.io.File("/tmp/jf.txt").delete();
        return "ok";
    }
    public static String read() throws Exception {
        java.io.File f = new java.io.File("/tmp/jf.txt");
        if (!f.exists())
            return "NONE";
        java.io.FileInputStream in = new java.io.FileInputStream(f);
        byte[] buf = new byte[(int) f.length()];
        int n = in.read(buf);
        in.close();
        if (n < 0)
            return "EMPTY";
        String text = new String(buf, 0, n, "UTF-8");
        return text.replace("\n", "|").replace("\r", "");
    }
}
$src$, current_schema()::varchar2, true);
CREATE FUNCTION rjt_outf_hi() RETURNS varchar2
LANGUAGE java AS 'OutF.hi() return java.lang.String';
CREATE FUNCTION rjt_outf_err() RETURNS varchar2
LANGUAGE java AS 'OutF.err() return java.lang.String';
CREATE FUNCTION rjt_outf_read() RETURNS varchar2
LANGUAGE java AS 'OutF.read() return java.lang.String';
CREATE FUNCTION rjt_outf_wipe() RETURNS varchar2
LANGUAGE java AS 'OutF.wipe() return java.lang.String';
DO $$
DECLARE
    msg text;
    hi text;
    body text;
BEGIN
    RAISE NOTICE 'Expected: NULL|ok|hello-file|';
    BEGIN
        PERFORM rjt_outf_wipe();
    EXCEPTION WHEN OTHERS THEN
        NULL;
    END;
    msg := dbms_java_set_output_to_file('rjt.file', '/tmp/jf.txt');
    BEGIN
        hi := rjt_outf_hi();
    EXCEPTION WHEN OTHERS THEN
        hi := SQLERRM;
    END;
    BEGIN
        body := rjt_outf_read();
    EXCEPTION WHEN OTHERS THEN
        body := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(substr(msg, 1, 160), chr(10), '|'), chr(13), ''), 'NULL')
        || '|' || COALESCE(substr(hi, 1, 80), 'NULL')
        || '|' || COALESCE(substr(body, 1, 200), 'NULL');
END $$;
NOTICE:  Expected: NULL|ok|hello-file|
NOTICE:  Actual:   NULL|ok|hello-file|
DO $$
DECLARE
    msg text;
BEGIN
    RAISE NOTICE 'Expected: Description of output to file specification named rjt.file| output from STDOUT and STDERR|file path: ,''/tmp/|';
    msg := dbms_java_query_output_to_file('rjt.file');
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(msg, chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: Description of output to file specification named rjt.file| output from STDOUT and STDERR|file path: ,'/tmp/|
NOTICE:  Actual:   Description of output to file specification named rjt.file| output from STDOUT and STDERR|file path: ,'/tmp/|
DO $$
DECLARE
    msg text;
    body text;
BEGIN
    RAISE NOTICE 'Expected: NULL|hello-file|';
    msg := dbms_java_disable_output_to_file('rjt.file');
    BEGIN
        IF rjt_outf_hi() IS NULL THEN NULL; END IF;
    EXCEPTION WHEN OTHERS THEN
        msg := COALESCE(msg, '') || ' call=' || SQLERRM;
    END;
    BEGIN
        body := rjt_outf_read();
    EXCEPTION WHEN OTHERS THEN
        body := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %', COALESCE(msg, 'NULL') || '|' || COALESCE(substr(body, 1, 200), 'NULL');
END $$;
NOTICE:  Expected: NULL|hello-file|
NOTICE:  Actual:   NULL|hello-file|
DO $$
DECLARE
    msg text;
    body text;
BEGIN
    RAISE NOTICE 'Expected: NULL|hello-file|hello-file|';
    msg := dbms_java_enable_output_to_file('rjt.file');
    BEGIN
        IF rjt_outf_hi() IS NULL THEN NULL; END IF;
    EXCEPTION WHEN OTHERS THEN
        msg := COALESCE(msg, 'NULL') || ' call=' || SQLERRM;
    END;
    BEGIN
        body := rjt_outf_read();
    EXCEPTION WHEN OTHERS THEN
        body := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %', COALESCE(msg, 'NULL') || '|' || COALESCE(substr(body, 1, 200), 'NULL');
END $$;
NOTICE:  Expected: NULL|hello-file|hello-file|
NOTICE:  Actual:   NULL|hello-file|hello-file|
DO $$
DECLARE
    q text;
BEGIN
    RAISE NOTICE 'Expected: Description of output to file specification named rjt.file| output from STDOUT and STDERR|file path: ,''/tmp/|';
    PERFORM dbms_java_endsession();
    q := dbms_java_query_output_to_file('rjt.file');
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(q, chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: Description of output to file specification named rjt.file| output from STDOUT and STDERR|file path: ,'/tmp/|
NOTICE:  Actual:   Description of output to file specification named rjt.file| output from STDOUT and STDERR|file path: ,'/tmp/|
DO $$
DECLARE
    q text;
BEGIN
    RAISE NOTICE 'Expected: output to file specification "rjt.file" not found';
    PERFORM dbms_java_endsession_and_related_state();
    q := dbms_java_query_output_to_file('rjt.file');
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(substr(q, 1, 200), chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: output to file specification "rjt.file" not found
NOTICE:  Actual:   output to file specification "rjt.file" not found
DO $$
DECLARE
    msg text;
    q text;
BEGIN
    RAISE NOTICE 'Expected: NULL|output to file specification "rjt.file" not found';
    PERFORM dbms_java_set_output_to_file('rjt.file', '/tmp/jf.txt');
    msg := dbms_java_remove_output_to_file('rjt.file');
    q := dbms_java_query_output_to_file('rjt.file');
    RAISE NOTICE 'Actual:   %',
        COALESCE(msg, 'NULL') || '|'
        || COALESCE(replace(replace(substr(q, 1, 160), chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: NULL|output to file specification "rjt.file" not found
NOTICE:  Actual:   NULL|output to file specification "rjt.file" not found
DO $$
DECLARE
    a text;
    b text;
    c text;
    d text;
BEGIN
    RAISE NOTICE 'Expected: output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found';
    a := dbms_java_remove_output_to_file('rjt.missing');
    b := dbms_java_enable_output_to_file('rjt.missing');
    c := dbms_java_disable_output_to_file('rjt.missing');
    d := dbms_java_query_output_to_file('rjt.missing');
    RAISE NOTICE 'Actual:   %',
        COALESCE(a, 'NULL') || '|' || COALESCE(b, 'NULL')
        || '|' || COALESCE(c, 'NULL') || '|' || COALESCE(d, 'NULL');
END $$;
NOTICE:  Expected: output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found
NOTICE:  Actual:   output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found|output to file specification "rjt.missing" not found
DO $$
DECLARE
    msg text;
BEGIN
    RAISE NOTICE 'Expected: ID must not be null';
    BEGIN
        msg := dbms_java_set_output_to_file(NULL::varchar2, '/tmp/jf.txt');
    EXCEPTION WHEN OTHERS THEN
        msg := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(substr(msg, 1, 180), chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: ID must not be null
NOTICE:  Actual:   ID must not be null
DO $$
DECLARE
    msg text;
BEGIN
    RAISE NOTICE 'Expected: ID must not be null';
    BEGIN
        msg := dbms_java_set_output_to_file(''::varchar2, '/tmp/jf.txt');
    EXCEPTION WHEN OTHERS THEN
        msg := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(substr(msg, 1, 180), chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: ID must not be null
NOTICE:  Actual:   ID must not be null
DO $$
DECLARE
    msg text;
BEGIN
    RAISE NOTICE 'Expected: specification with this name already exists';
    PERFORM dbms_java_set_output_to_file('rjt.frep', '/tmp/jf.txt');
    msg := dbms_java_set_output_to_file('rjt.frep', '/tmp/jf.txt', 0);
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(substr(msg, 1, 180), chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: specification with this name already exists
NOTICE:  Actual:   specification with this name already exists
DO $$
DECLARE
    msg text;
    body text;
BEGIN
    RAISE NOTICE 'Expected: NULL|hello-ferr|';
    BEGIN
        PERFORM rjt_outf_wipe();
    EXCEPTION WHEN OTHERS THEN
        NULL;
    END;
    PERFORM dbms_java_remove_output_to_file('rjt.file');
    PERFORM dbms_java_remove_output_to_file('rjt.frep');
    msg := dbms_java_set_output_to_file(
        id => 'rjt.fstd',
        file_path => '/tmp/jf.txt',
        from_stdout => 0);
    BEGIN
        IF rjt_outf_hi() IS NULL THEN NULL; END IF;
        IF rjt_outf_err() IS NULL THEN NULL; END IF;
    EXCEPTION WHEN OTHERS THEN
        msg := COALESCE(msg, 'NULL') || ' call=' || SQLERRM;
    END;
    BEGIN
        body := rjt_outf_read();
    EXCEPTION WHEN OTHERS THEN
        body := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %', COALESCE(msg, 'NULL') || '|' || COALESCE(substr(body, 1, 200), 'NULL');
END $$;
NOTICE:  Expected: NULL|hello-ferr|
NOTICE:  Actual:   NULL|hello-ferr|
DO $$
DECLARE
    msg text;
BEGIN
    RAISE NOTICE 'Expected: ok';
    BEGIN
        CALL dbms_java_initialize_output_to_file('rjt.fini', '/tmp/jf.txt');
        msg := 'ok';
    EXCEPTION WHEN OTHERS THEN
        msg := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(substr(msg, 1, 180), chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: ok
NOTICE:  Actual:   ok
DO $$
DECLARE
    msg text;
BEGIN
    RAISE NOTICE 'Expected: ok';
    BEGIN
        CALL dbms_java_finalize_output_to_file('rjt.fini');
        msg := 'ok';
    EXCEPTION WHEN OTHERS THEN
        msg := SQLERRM;
    END;
    RAISE NOTICE 'Actual:   %',
        COALESCE(replace(replace(substr(msg, 1, 180), chr(10), '|'), chr(13), ''), 'NULL');
END $$;
NOTICE:  Expected: ok
NOTICE:  Actual:   ok
DO $$
BEGIN
    PERFORM dbms_java_remove_output_to_file('rjt.file');
    PERFORM dbms_java_remove_output_to_file('rjt.frep');
    PERFORM dbms_java_remove_output_to_file('rjt.fstd');
    PERFORM dbms_java_remove_output_to_file('rjt.fini');
END $$;
DROP FUNCTION IF EXISTS rjt_outf_hi();
DROP FUNCTION IF EXISTS rjt_outf_err();
DROP FUNCTION IF EXISTS rjt_outf_read();
DROP FUNCTION IF EXISTS rjt_outf_wipe();
DO $$
BEGIN
    CALL dbms_java_dropjava('OutF');
EXCEPTION WHEN OTHERS THEN NULL;
END $$;