111 |
sub drop_triggers { |
sub drop_triggers { |
112 |
my $table = shift || die "no table?"; |
my $table = shift || die "no table?"; |
113 |
|
|
114 |
warn "removing triggers from $table\n"; |
my $sth = $dbh->prepare(qq{ |
115 |
|
SELECT relname,tgname |
116 |
foreach my $t (qw/UPDATE INSERT DELETE/) { |
FROM pg_trigger JOIN pg_class ON relfilenode = tgrelid |
117 |
my $lc_t = lc($t); |
WHERE tgname LIKE 'pgest_trigger_%' AND relname = ? |
118 |
$dbh->do(qq{ DROP TRIGGER pgest_trigger_${lc_t} ON ${table} }); |
}) || $dbh->errstr; |
119 |
|
|
120 |
|
$sth->execute( $table ) || $sth->errstr(); |
121 |
|
|
122 |
|
warn "there are ", $sth->rows, " triggers instead of just 3, dropping all\n" if ($sth->rows != 3); |
123 |
|
|
124 |
|
while (my $row = $sth->fetchrow_hashref) { |
125 |
|
my $sql = sprintf(qq{ DROP TRIGGER %s ON %s }, $row->{tgname}, $row->{relname} ); |
126 |
|
#warn "# $sql\n"; |
127 |
|
$dbh->do( $sql ) || $dbh->errstr; |
128 |
} |
} |
129 |
|
|
130 |
|
warn "removed ", $sth->rows, " triggers from $table\n" if ($sth->rows); |
131 |
|
|
132 |
} |
} |
133 |
|
|
134 |
if ($c->{drop}) { |
if ($c->{drop}) { |
197 |
$c->{sql} ||= "select * from $table"; |
$c->{sql} ||= "select * from $table"; |
198 |
|
|
199 |
my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr(); |
my $sth = $dbh->prepare($c->{sql}) || die $dbh->errstr(); |
200 |
$sth->execute() || die $sth->errstr(); |
$sth->execute() || die $sth->errstr; |
201 |
|
|
202 |
my @cols = @{ $sth->{NAME} }; |
my @cols = @{ $sth->{NAME} }; |
203 |
|
|
272 |
|
|
273 |
#warn "$sql\n"; |
#warn "$sql\n"; |
274 |
|
|
275 |
$dbh->do( $sql ) || die $dbh->errstr(); |
$dbh->do( $sql ) || die $dbh->errstr; |
276 |
|
|
277 |
} |
} |
278 |
|
|
279 |
|
warn "created consistency triggers\n"; |
280 |
|
|
281 |
$dbh->commit; |
$dbh->commit; |
282 |
|
|
283 |
=head1 SEARCHING |
=head1 SEARCHING |