#
#	filmdb.pm: not a separate namespace though
#
#	(C) Duncan C. White, 21st March 2000
#
use DBI;
use strict;

my $dbh;


sub opendb
{
        my $db = $_[0] || $ENV{PGDATABASE} || "films";         # which db
	my $server = $ENV{PGHOST} || "db.doc.ic.ac.uk";
	my $port = 5432;
	my $user='lab';
	my $password='lab';
	$dbh = DBI->connect("dbi:Pg:dbname=$db;host=$server;port=$port",
		$user, $password ) or die "can't connect\n";
	#$dbh->{AutoCommit} = 1;
	return $dbh;
}


sub dbtype ()
{
	return "postgres";
}


sub escapequotes ($)
{
	# in postgres, need to backslash escape single quotes
	$_[0] =~ s/'/\\'/g;
	return $_[0];
}


sub closedb ()
{
        $dbh->disconnect;
        $dbh = undef;
}


1;
