#!/usr/bin/perl # # sy_unload - inspired by Informix' load/unload # # sy_unload [options] databasename select statement words [...] # # options: -q: quoted strings, comma delimited output # -b: bar delimited output (default) # -d: optional delimiter, replaces vertical bar # -U: optional user name # -P: optional password # # Jeff Hecker / Apogee use DBI; $U = "sa"; $P = ""; $delim = "|"; while ( $ARGV[0] =~ m/^-/ ) { $_ = shift ( @ARGV ); print "arg=$_ \n"; m/-U/ && do { $U = shift ( @ARGV ); }; m/-P/ && do { $P = shift ( @ARGV ); }; m/-d/ && do { $delim = shift ( @ARGV ); }; } &usage unless ( $#ARGV > 1 ); $DB = shift ( @ARGV ); # $conn = DBI->connect ( "dbi:Sybase:database=" . $DB . ":scriptname=unload", $U, $P ); $conn = DBI->connect ( "dbi:Sybase:scriptname=unload", $U, $P ); $conn->do ( "use $DB" ); $sth = $conn->prepare ( join ( " ", @ARGV )); $x = $sth->execute; while ( @DATA = $sth->fetchrow_array ) { for $_ ( @DATA ) { s/ *$//; s/\|/\\&/g; } print join ( $delim, @DATA ), "\n"; } $conn->disconnect; exit; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # sub usage { print STDERR <