#!/usr/bin/perl -w

use strict;
use DBI;

# could use `dsns' to get list, then grep through it for the right one, if we
# do not know anything about the driver in question...?

my %dbi_drivers = map {lc $_, $_} DBI->available_drivers;

@ARGV >= 2 && @ARGV <= 4
	or die "syntax: $0 driver database [host [port]]\n";

my ($driver_input, $database, $host, $port) = @ARGV;

my $driver = $dbi_drivers{$driver_input} || $driver_input;

# use TCP with stupid mSQL - perhaps just a config problem on my machine?
$driver eq 'mSQL' and $host ||= 'localhost';

print "dbi:$driver:";
print $driver eq "Pg" ?  "dbname" : "database";
print "=$database";
$host and print ";host=$host";
$port and print ";port=$port";
print "\n";
