#!/usr/bin/perl

$max = 0;
open (OUT, "| psql -U helm helm_mowgli_new_schema");
while (<STDIN>) {
 open (IN,$_);
 $uri1 = <IN>;
 chomp($uri1);
 print "$uri1:\n";
 $uri1 =~ s/'/\\'/g;
 $max++;
 print OUT "create table t$max (prop_id varchar, position varchar, uri varchar, depth int);";
 print OUT "insert into registry values ('$uri1', $max);";
 while (<IN>) {
  chomp;
  ($dir,$context,$uri2,$depth) = split(/\|/);
  print "   Inserisco $dir#$context#$uri2#$depth\n";
  $uri2 =~ s/'/\\'/g;
  print OUT "insert into t$max values ('$dir', '$context', '$uri2', $depth);";
 }
  print "\n";
  close IN;
}
close OUT;
