/[pgestraier]/trunk/bin/pgest-index.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/pgest-index.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 62 by dpavlin, Mon Aug 7 13:24:49 2006 UTC revision 63 by dpavlin, Mon Aug 7 14:30:55 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  use strict;  use strict;
4  use Search::Estraier 0.06;  use Search::Estraier 0.07;
5  use DBI;  use DBI;
6  use Data::Dumper;  use Data::Dumper;
7  use Encode qw/from_to/;  use Encode qw/from_to/;
# Line 32  GetOptions($c, qw/node_url=s sql=s pk_co Line 32  GetOptions($c, qw/node_url=s sql=s pk_co
32    
33  warn "# c: ", Dumper($c) if ($c->{debug});  warn "# c: ", Dumper($c) if ($c->{debug});
34    
35    my $table = $c->{name} || die "no name?";
36    
37  # create and configure node  # create and configure node
38  my $node = new Search::Estraier::Node(  my $node = new Search::Estraier::Node(
39          url => $c->{node_url},          url => $c->{node_url},
# Line 42  my $node = new Search::Estraier::Node( Line 44  my $node = new Search::Estraier::Node(
44          debug => $c->{debug} >= 4 ? 1 : 0,          debug => $c->{debug} >= 4 ? 1 : 0,
45  );  );
46    
47    $node->master(
48            action => 'nodeclr',
49            name => $table,
50    );
51    
52  # create DBI connection  # create DBI connection
53  my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr;  my $dbh = DBI->connect("DBI:$c->{dbi}","","") || die $DBI::errstr;
54    
55    # create PostgreSQL functions
56    $dbh->do(qq{
57    
58    CREATE OR REPLACE FUNCTION pgest(text, text, text, int, text, text, text, int, int, text[])
59            RETURNS setof record
60            AS 'pgest','pgest_node'
61            LANGUAGE 'C' IMMUTABLE CALLED ON NULL INPUT;
62    
63    CREATE OR REPLACE FUNCTION pgest_trigger() RETURNS TRIGGER
64            AS 'pgest', 'pgest_trigger'
65            LANGUAGE 'C' STRICT;
66    
67    }) || die $dbh->errstr();
68    
69    
70    # drop existing triggers
71    foreach my $t (qw/UPDATE INSERT DELETE/) {
72            my $lc_t = lc($t);
73            $dbh->do(qq{ DROP TRIGGER pgest_trigger_${lc_t} ON ${table} });
74    }
75    
76    $dbh->begin_work;
77    
78  my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr();  my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr();
79  $sth->execute() || die $sth->errstr();  $sth->execute() || die $sth->errstr();
80    
# Line 100  while (my $row = $sth->fetchrow_hashref( Line 130  while (my $row = $sth->fetchrow_hashref(
130    
131  }  }
132    
 my $table = $c->{name} || die "no name?";  
   
133  my $cols = "'" . join("','", @cols) . "'";  my $cols = "'" . join("','", @cols) . "'";
134    
135  foreach my $t (qw/UPDATE INSERT DELETE/) {  foreach my $t (qw/UPDATE INSERT DELETE/) {
136    
137          my $lc_t = lc($t);          my $lc_t = lc($t);
138    
         $dbh->do(qq{ DROP TRIGGER pgest_trigger_${lc_t} ON ${table} });  
   
139          my $sql = qq{          my $sql = qq{
140    
141                  CREATE TRIGGER pgest_trigger_${lc_t} AFTER ${t}                  CREATE TRIGGER pgest_trigger_${lc_t} AFTER ${t}
# Line 120  foreach my $t (qw/UPDATE INSERT DELETE/) Line 146  foreach my $t (qw/UPDATE INSERT DELETE/)
146    
147          };          };
148    
149          warn "$sql\n";          #warn "$sql\n";
150    
151          $dbh->do( $sql ) || die $dbh->errstr();          $dbh->do( $sql ) || die $dbh->errstr();
152    
153  }  }
154    
155    $dbh->commit;

Legend:
Removed from v.62  
changed lines
  Added in v.63

  ViewVC Help
Powered by ViewVC 1.1.26