#!/usr/bin/perl # TODO : add a test for the filename $article=$ARGV[0]; $db="linuxman"; $article=~/(\d{4})(\d{2})(\d{2})-(\d+)/; ($year,$month,$day,$num)= ($1,$2,$3,$4); use Pg; # Connect to the linuxman database $conn = Pg::connectdb("dbname=$db"); die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status; print "connected to $db\n"; # Find the articles large object ID print "Searching articles number $num for $year $month $day\n"; $result = $conn->exec("SELECT article FROM articles WHERE year = '$year' AND month = '$month' AND day = '$day' AND num='$num'"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; if ($result->ntuples>0) { $oid = $result->getvalue(0,0); # remove the object from the base print "Removing object : $oid\n"; die $conn->errorMessage if (-1 == $conn->lo_unlink($oid)); # delete the articles entry print "Removing articles entries\n"; $result = $conn->exec("DELETE FROM articles WHERE year = '$year' AND month = '$month' AND day = '$day' AND num='$num'"); die $conn->errorMessage unless 1==$result->resultStatus; # Find the oid of attachments $result = $conn->exec("SELECT attachment FROM attachments WHERE year = '$year' AND month = '$month' AND day = '$day' AND num='$num'"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; # Remove the attachements from the base print "Removing attachments\n"; for ($i=0;$i<$result->ntuples;$i++){ $oid = $result->getvalue($i,0); die $conn->errorMessage if -1 == $conn->lo_unlink($oid); } # Remove the attachments table entries print "Removing attachments entries\n"; $result = $conn->exec("DELETE FROM attachments WHERE year = '$year' AND month = '$month' AND day = '$day' AND num='$num'"); die $conn->errorMessage unless 1==$result->resultStatus; exit(0); } print "No article found\n"; exit(0);