1 dnl Copyright (C) 2013 The Meme Factory, Inc., http://www.meme.com/
3 dnl This file is part of Gombe-MI.
5 dnl Gombe-MI is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; either version 3 of the License, or
8 dnl (at your option) any later version.
10 dnl This program is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 dnl GNU General Public License for more details.
15 dnl You should have received a copy of the GNU General Public License
16 dnl along with Gombe-MI. If not, see <http://www.gnu.org/licenses/>.
18 dnl Delete_gc Delete group comp for a follow.
20 dnl Karl O. Pinc <kop@meme.com>
24 include(`copyright.m4')
25 include(`constants.m4')
29 CREATE OR REPLACE FUNCTION delete_gc(followdate DATE
30 , mom VARCHAR(gmi_animid_len))
34 gmi_function_set_search_path
36 -- Delete group comp of a follow, specified by date and mom.
38 -- GPL_notice(` --', `2013', `The Meme Factory, Inc. http://www.meme.com/')
40 -- Syntax: delete_gc(followdate, mom)
43 -- followdate Date of the follow.
44 -- mom Chimpid of mom in the follow.
47 -- TRUE if group comp rows were deleted and FALSE otherwise.
54 this_followid follows.followid%TYPE;
59 SELECT follows.followid
62 JOIN followparts ON (followparts.followid = follows.followid)
63 JOIN followroles ON (followroles.role = followparts.role)
64 JOIN chimpids AS fcid ON (fcid.chimpid = followparts.chimpid)
65 JOIN chimpids AS this_cid ON (this_cid.animid = fcid.animid)
66 WHERE follows.date = followdate
67 AND followroles.function = 'gmi_mom'
68 AND this_cid.chimpid = mom;
74 RETURN delete_gc(this_followid);
77 grant_func_priv(`delete_gc(DATE, VARCHAR(gmi_animid_len))')
81 CREATE OR REPLACE FUNCTION delete_gc(this_followid INT)
85 gmi_function_set_search_path
87 -- Delete group comp of a follow, specified by followid.
89 -- GPL_notice(` --', `2013', `The Meme Factory, Inc. http://www.meme.com/')
91 -- Syntax: delete_gc(followid)
94 -- followid FOLLOWS.FollowID of the follow.
97 -- TRUE if group comp rows were deleted and FALSE otherwise.
105 this_rgid raw_groups.rgid%TYPE;
109 -- Delete group comps from the beginning of the day to the end.
110 -- This prevents re-assignment of group comps to intervals
111 -- because intervals before the first group comp of the day
112 -- are not assigned to a group comp.
116 SELECT raw_groups.rgid
118 JOIN raw_groups ON (raw_groups.sheetid = intervals.sheetid)
119 WHERE intervals.followid = this_followid
120 GROUP BY raw_groups.rgid
121 ORDER BY raw_groups.time
124 DELETE FROM raw_groups
125 WHERE raw_groups.rgid = this_rgid;
130 -- Change the fieldfollows.gcstatus to NULL.
133 FROM (SELECT sheets.ffid
135 JOIN sheets ON (sheets.sheetid = intervals.sheetid)
136 WHERE intervals.followid = this_followid
137 GROUP BY sheets.ffid) AS ffids
138 WHERE fieldfollows.ffid = ffids.ffid;
143 grant_func_priv(`delete_gc(INT)')