/ conversion / access /
/conversion/access/fix_comment
1 dnl Copyright (C) 2014 The Meme Factory, Inc. http://www.meme.com/
2 dnl
3 dnl This file is part of Gombe-MI.
4 dnl
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.
9 dnl
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.
14 dnl
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/>.
17 dnl
18 dnl The convert access program has a bug, fix it.
19 dnl
20 dnl Karl O. Pinc <kop@meme.com>
21
22 -- When the convert_access() program created O events rows from DEVBEH!
23 -- comments and moved the DEVBEH! comment into the event comment it
24 -- was too greedy and moved everything after the DEVBEH![.
25
26 -- At this point we changed our minds and want the intervals.comment
27 -- untouched even though sometimes the DEVBEH! portion is duplicated
28 -- in an events.comment.
29
30 DO $$
31 DECLARE
32 n INT;
33 c TEXT;
34 this_intid INT;
35 this_eid INT;
36
37 BEGIN
38
39 FOR c IN
40 SELECT events.comment
41 FROM events
42 WHERE events.behavior = 'O'
43 AND events.comment ~ '^DEVBEH'
44 LOOP
45
46 n := POSITION(']' IN c);
47
48 UPDATE events
49 SET comment = SUBSTRING(c FOR n);
50 WHERE events.eid = this_eid;
51
52 UPDATE intervals
53 SET comment = COALESCE(intervals.comment, '') || c
54 WHERE intervals.iid = this_iid;
55
56 END LOOP;
57 END;
58 $$