#!/usr/bin/perl -w

use strict;
use DBI;

@ARGV == 2
	or die "syntax: $0 dsn table > output\n";

my ($dsn, $user, $pass, $attr) = split / /, shift, 4;
my $table = shift;

my $dbh = DBI->connect($dsn, $user, $pass, $attr && eval $attr)
	or die "cannot connect to $dsn: ".DBI->errstr."\n";

my $sth = $dbh->prepare("select * from $table limit 1")
	or die "cannot prepare: ".$dbh->errstr."\n";

$sth->execute
	or die "cannot execute: ".$dbh->errstr."\n";

for (@{$sth->{NAME}}) { print "$_\n" }

if ($sth->errstr) {
	die "cannot fetch: ".$sth->errstr."\n";
}

$sth->finish;

$dbh->disconnect;
