summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-03-07 23:13:56 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-03-07 23:13:56 (GMT)
commit30726d6fabbd3e683245391c6c0abb1d7b946899 (patch)
treefd832f77910ef494c13f693f089ef03ff3c05c27
parentfe246fdcd6ca8a7863ae6e80e58ab7c544feb820 (diff)
downloadblogengine-30726d6fabbd3e683245391c6c0abb1d7b946899.zip
blogengine-30726d6fabbd3e683245391c6c0abb1d7b946899.tar.gz
blogengine-30726d6fabbd3e683245391c6c0abb1d7b946899.tar.bz2
Use RaiseError instead of checking for errors after every command.
-rwxr-xr-xinsert-entries.pl35
1 files changed, 12 insertions, 23 deletions
diff --git a/insert-entries.pl b/insert-entries.pl
index bde5aa2..8e81893 100755
--- a/insert-entries.pl
+++ b/insert-entries.pl
@@ -89,24 +89,17 @@ if ( defined($ARGV[0]) ) {
$doc = $parser->parse_fh(\*STDIN);
}
-my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", "", "", {AutoCommit=>1,PrintError=>1,pg_enable_utf8=>1})
- or die "Can't connect to database";
-$dbh->do("SET TIME ZONE 0")
- or die "Can't set timezone";
+my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", "", "", {AutoCommit=>1,RaiseError=>1,pg_enable_utf8=>1});
+$dbh->do("SET TIME ZONE 0");
my ($sth_check, $sth_insert, $sth_update);
-$sth_check = $dbh->prepare("SELECT sha1 FROM entries WHERE id=?")
- or die "Can't prepare statement";
+$sth_check = $dbh->prepare("SELECT sha1 FROM entries WHERE id=?");
if ( $obtain_cdates ) {
- $sth_insert = $dbh->prepare("INSERT INTO entries(id,edate,lang,title,content,sha1,cdate) VALUES (?,?,?,?,?,?,?)")
- or die "Can't prepare statement";
- $sth_update = $dbh->prepare("UPDATE entries SET (edate,mdate,lang,title,content,sha1,cdate)=(?,DEFAULT,?,?,?,?,?) WHERE id=?")
- or die "Can't prepare statement";
+ $sth_insert = $dbh->prepare("INSERT INTO entries(id,edate,lang,title,content,sha1,cdate) VALUES (?,?,?,?,?,?,?)");
+ $sth_update = $dbh->prepare("UPDATE entries SET (edate,mdate,lang,title,content,sha1,cdate)=(?,DEFAULT,?,?,?,?,?) WHERE id=?");
} else {
- $sth_insert = $dbh->prepare("INSERT INTO entries(id,edate,lang,title,content,sha1) VALUES (?,?,?,?,?,?)")
- or die "Can't prepare statement";
- $sth_update = $dbh->prepare("UPDATE entries SET (edate,mdate,lang,title,content,sha1)=(?,DEFAULT,?,?,?,?) WHERE id=?")
- or die "Can't prepare statement";
+ $sth_insert = $dbh->prepare("INSERT INTO entries(id,edate,lang,title,content,sha1) VALUES (?,?,?,?,?,?)");
+ $sth_update = $dbh->prepare("UPDATE entries SET (edate,mdate,lang,title,content,sha1)=(?,DEFAULT,?,?,?,?) WHERE id=?");
}
sub get_node_lang {
@@ -130,7 +123,7 @@ foreach my $node ( $entry_list->get_nodelist ) {
$node->setAttributeNS(XML_XML_NS, "lang", $lang) if defined($lang);
my $str = $node->serialize();
my $sha1 = sha1_hex(encode("utf8",$str));
- $sth_check->execute($id) or die "Can't check sha1 for entry";
+ $sth_check->execute($id);
my $exists = $sth_check->rows;
next if $exists && ($sth_check->fetchrow_array)[0] eq $sha1;
my $title_node = ($xpc->findnodes("title", $node))[0];
@@ -146,20 +139,16 @@ foreach my $node ( $entry_list->get_nodelist ) {
if ( $exists ) {
print STDERR "Updating entry $id\n";
if ( $obtain_cdates ) {
- $sth_update->execute($date, $lang, $title, $str, $sha1, $cdate, $id)
- or die "Can't update entry";
+ $sth_update->execute($date, $lang, $title, $str, $sha1, $cdate, $id);
} else {
- $sth_update->execute($date, $lang, $title, $str, $sha1, $id)
- or die "Can't update entry";
+ $sth_update->execute($date, $lang, $title, $str, $sha1, $id);
}
} else {
print STDERR "Registering entry $id\n";
if ( $obtain_cdates ) {
- $sth_insert->execute($id, $date, $lang, $title, $str, $sha1, $cdate)
- or die "Can't register entry";
+ $sth_insert->execute($id, $date, $lang, $title, $str, $sha1, $cdate);
} else {
- $sth_insert->execute($id, $date, $lang, $title, $str, $sha1)
- or die "Can't register entry";
+ $sth_insert->execute($id, $date, $lang, $title, $str, $sha1);
}
}
}