#!/usr/bin/perl
#------------------------------------------------------------------------------
# Copyright (C) 2001 Thomax Kaulmann
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


# ok, first:
# alter table video_conn add linked int(11) not null;
# alter table audio_conn add linked int(11) not null;
# alter table picture_conn add linked int(11) not null;
# alter table text_conn add linked int(11) not null;

# change things in the *PARSE routines to use the linked field

use OMA;

$db=OMA::opendb();

sub update {

	$st=$db->prepare("
		select ". $what ."_conn.*
		from ". $what ."_conn,item
		where ". $what ."_conn.item_sid = item.sid
		and item.type != 'meta'
	");

	$st->execute();
	while(@row=$st->fetchrow()) {
		$st2=$db->prepare("select ". $what ."_conn.item_sid
							from ". $what ."_conn, item
							where ". $what ."_conn.item_sid=item.sid
							and ". $what ."_conn.". $what ."_page=$row[1]
		");
		$st2->execute();
		while(@row2=$st2->fetchrow()) {
			$st3=$db->prepare("
				update ". $what ."_conn set linked=$row[0] where item_sid=$row2[0]
			");
			$st3->execute();
		}
		$st2->finish();
	}
	$st->finish();
}

$what = "picture";
update;
$what = "audio";
update;
$what = "video";
update;
$what = "text";
update;
