1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#!/usr/bin/perl
use strict;
use warnings;
use Env qw(VALUE);
use DBI;
my $key = $ARGV[0];
# DBI will use default value coming from env
# see puppet manifests
my $dbh = DBI->connect("dbi:Pg:","","", {
AutoCommit => 0,
RaiseError => 1,
});
my $table = "phpbb_config";
# FIXME add rollback if there is a problem
# http://docstore.mik.ua/orelly/linux/dbi/ch06_03.htm
my $update = $dbh->prepare("UPDATE $table SET config_value = ?, is_dynamic = ? WHERE config_name = ?");
my $insert = $dbh->prepare("INSERT INTO $table ( config_value, is_dynamic, config_name ) VALUES ( ? , ? , ? )");
my $res = $update->execute($VALUE, 1, $key) or die "cannot do update $?";
if ($res == 0 ) {
$insert->execute($VALUE, 1, $key) or die "cannot do insert $?";
}
$dbh->commit();
$dbh->disconnect();
|