dnl Copyright (C) 2014 The Meme Factory, Inc. http://www.meme.com/
dnl
dnl This file is part of Gombe-MI.
dnl
dnl Gombe-MI is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 3 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with Gombe-MI. If not, see .
dnl
dnl The convert access program has a bug, fix it.
dnl
dnl Karl O. Pinc
-- When the convert_access() program created O events rows from DEVBEH!
-- comments and moved the DEVBEH! comment into the event comment it
-- was too greedy and moved everything after the DEVBEH![.
-- At this point we changed our minds and want the intervals.comment
-- untouched even though sometimes the DEVBEH! portion is duplicated
-- in an events.comment.
DO $$
DECLARE
n INT;
c TEXT;
this_intid INT;
this_eid INT;
BEGIN
FOR c IN
SELECT events.comment
FROM events
WHERE events.behavior = 'O'
AND events.comment ~ '^DEVBEH'
LOOP
n := POSITION(']' IN c);
UPDATE events
SET comment = SUBSTRING(c FOR n);
WHERE events.eid = this_eid;
UPDATE intervals
SET comment = COALESCE(intervals.comment, '') || c
WHERE intervals.iid = this_iid;
END LOOP;
END;
$$