forked from samv/git-p4raw
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuilddepot.sql
More file actions
109 lines (98 loc) · 2.27 KB
/
Copy pathbuilddepot.sql
File metadata and controls
109 lines (98 loc) · 2.27 KB
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
/* produciton change */
/* depot paths */
/*
create table depotpaths
(
depotpaths_id serial
, depotpath text
, hash int
);
create index depotpaths_hash on depotpaths(hash) ;
*/
-- drop index depotpaths_depotpath ;
-- create unique index depotpaths_depotpath on depotpaths(depotpath);
create or replace function create_or_find_depotpaths( in_path text) returns integer
language 'plpgsql' as
$$
DECLARE
in_hash int;
id int;
BEGIN
in_hash := hashtext(in_path);
select into id depotpath_id from depotpaths where hash = in_hash and depotpath = in_path;
if id is null then
insert into depotpaths(depotpath_id, depotpath, hash) values
( DEFAULT, in_path, in_hash) returning depotpath_id into id;
end if;
return id;
END;
$$;
drop function find_all() ;
create or replace function find_all() returns boolean
language 'plpgsql' as
$find_all$
DECLARE
curs1 refcursor;
-- s text;
-- o text;
rc integer;
rec record;
BEGIN
OPEN curs1 for select object, subject from integed ;
<<build_depot>>
LOOP
FETCH curs1 INTO rec ;
EXIT build_depot WHEN NOT FOUND;
rc:= create_or_find_depotpaths(rec.subject);
rc:=create_or_find_depotpaths(rec.object);
END LOOP build_depot;
CLOSE curs1;
return true;
END;
$find_all$;
/*
Table "public.label"
depotpath | text | not null
Table "public.rev"
depotpath | text | not null
rcs_file | text |
Table "public.revcx"
depotpath | text | not null
*/
create or replace function find_all_too() returns boolean
language 'plpgsql' as
$find_all$
DECLARE
curs1 refcursor;
curs2 refcursor;
curs3 refcursor;
curs4 refcursor;
-- s text;
-- o text;
rc boolean;
rec record;
BEGIN
OPEN curs1 for select depotpath as pathname from label;
rc:= find_all_by_cur(curs1);
OPEN curs2 for select depotpath as pathname from revcx;
rc:= find_all_by_cur(curs2);
return rc;
END;
$find_all$;
create or replace function find_all_by_cur(curs1 refcursor) returns boolean
language 'plpgsql' as
$$
DECLARE
rc integer;
rec record;
BEGIN
<<build_depot>>
LOOP
FETCH curs1 INTO rec ;
EXIT build_depot WHEN NOT FOUND;
rc:= create_or_find_depotpaths(rec.pathname);
END LOOP build_depot;
CLOSE curs1;
return true;
END;
$$;