I won't go into the whole long, and incredibly silly story as to why I wrote this, I'll just sum it up in a few bullets:

Thus the jcsh (Jack & Coke SHell) was born...

#!perl -w use Getopt::Std; use vars qw($opt_S $opt_U $opt_D $opt_P); $opt_S = 'DEFAULTSERVER'; $opt_U = 'defaultuser'; getopt('SUDP'); unless (defined $opt_P) { print "Password: "; system "stty -echo"; $opt_P = <>; print "\n"; system "stty echo"; } do { my $num = 1; my $line = ""; while ($line !~ /^go|;/) { print "$opt_U-$opt_S $num>"; $line = <>; $num++; chomp $line; exit if $line eq 'exit'; $num = 1 if $line eq 'reset'; } print <<EOB; | |------------- |jack and coke (1 row affected) EOB } while (1);

Replies are listed 'Best First'.
Re: Fake sqsh
by mpeppler (Vicar) on Jul 09, 2002 at 00:37 UTC
    Ah but you're missing command line editing!

    I've actually writen a few isql clones in perl, including one that was left as an exercise for my students :-)

    I just found the following - written for perl 4/sybperl 1.xx, with a last modified date of Feb 22, 1994:

    #!/usr/local/bin/sybperl require 'sybperl.pl'; require 'getopts.pl'; &Getopts('P:U:'); &dblogin($opt_U, $opt_P); select(STDOUT); $| = 1; # set unbuffered $count = 1; print "$count> "; while(<>) { /^exit|^quit/ && exit(0); /^go/ && do { &exec; $count = 1; print "$count> "; next; }; &dbcmd($_); ++$count; print "$count> "; } sub exec { local($ret, $numcol, $i); local(@dat, %width); &dbsqlexec; while(($ret = &dbresults) != $NO_MORE_RESULTS) { $numcol = &dbnumcols; for($i = 1; $i <= $numcol; ++$i) { $width{$i} = &dbcollen(0, $i); printf("%-$width{$i}.$width{$i}s ", &dbcolname(0, $i)); } print "\n\n"; while(@dat = &dbnextrow) { for($i = 1; $i <= $numcol; ++$i) { printf("%$width{$i}.$width{$i}s ", $dat[$i-1]); } print "\n"; } while(@dat = &dbretdata) { print "@dat\n"; } } }
    I think I used that for my presentation at the 1994 Sybase User Group conference. I have a feeling I'd write that a little bit differently today :-)

    Michael

Re: Fake sqsh
by cephas (Pilgrim) on Jul 09, 2002 at 21:53 UTC
    Missing more than just command line editing. Where's \do and \done? go -m vert/bcp,etc?

    Since you're in perl though, you mind writing a -m csv to dump results to a PROPERLY quoted CSV format?

    I think I should replace isql on our machines with your script. People should learn to use sqsh, its what isql should have been.... but I'll stay off the soap box today.....


    cephas