Fernando Luna wrote:

Fernando Luna wrote:


[...]
I am running perl version 5.005_03 built for AIX Unix.

Get ready to upgrade.

So, is this version not stable enough for me to do what I want? Why should I worry about upgrading right now?

It's stable - but note that the release notes for DBI 1.33 say that 5.5.3 won't be supported much longer, nor 5.6.0.


My currently approach is a ksh script that calls sqlplus. The statements are separated by either a semi-colon (which I guess most
databases use) or a forward slash (which Oracle supports through the sqlplus tool, though in all other cases only the semi-colon is appropriate).

You'll have to hack the attachment a bit to handle the slashes. The ix_Fetchable attribute is obsolete and should be replaced by NUM_OF_FIELDS (check spelling) - it should be greater than 0.



I'd be very thankful for any help you can toss my way.

See attachment.



--
Jonathan Leffler ([EMAIL PROTECTED], [EMAIL PROTECTED]) #include <disclaimer.h>
Guardian of DBD::Informix 1.04.PC1 -- http://dbi.perl.org/
#!/usr/bin/perl -w
#
#       @(#)$Id: sqlcmd.sh,v 54.2 1997/04/08 18:59:42 johnl Exp $
#
#       SQL Command Reader & Executor

use Getopt::Std;
use DBI;

$delim = $ENV{DBDELIMITER};
$delim = "|" unless $delim;

sub print_row
{
        my (@row) = @_;
        my ($i);
        for ($i = 0; $i < @row; $i++)
        {

                print "$row[$i]" if (defined $row[$i]);
                print "$delim";
        }
        print "\n";
}

# Execute an SQL command -- the preparable ones...
sub sql_exec
{
        my ($cmd) = @_;
        my ($sth);
        print "+ $cmd\n" if ($opt_x);
        warn "SQL command failed: $DBI::errstr\n"
                unless ($sth = $dbh->prepare($cmd) and $sth->execute);
        if ($sth->{ix_Fetchable})
        {
                # SELECT statements other than SELECT...INTO TEMP, and
                # EXECUTE PROCEDURE statements which return values.
                my (@row);
                while (@row = @{$sth->fetch})
                {
                        print_row(@row);
                }
        }
        warn "SQL command failed: $DBI::errstr\n"
                unless $sth->finish;
}

# BUG: this code does not support multiple occurrences of the -e option on
# the command line.  Nor does it support the -f option.
$opt_d = '.DEFAULT.';
$opt_e = '';
$opt_x = '';
$opt_V = '';
getopts('d:e:xV');

# Print version information
if ($opt_V)
{
        print "$0: SQLCMD Version $Revision: 54.2 $ ($Date: 1997/04/08 18:59:42 $)\n";
        $drh = DBI->install_driver('Informix');
        print "DBI Version $DBI::VERSION\n";
        print "DBD::$drh->{Name} Version $drh->{Version}\n";
        print "$drh->{ProductName}\n";
        exit(0);
}

# Pre-select database
die "Failed to connect to the database\n" unless
        $dbh = DBI->connect($opt_d,'','','Informix');

if ($opt_e)
{
        # Command line SQL statement
        sql_exec $opt_e;
}
else
{
        # Read SQL commands from files (or stdin)
        $cmd = "";
        while (<>)
        {
                next if /^\s*$/;
                $cmd .= $_;
                if (/;/)        # Inaccurate, but OK for first hack!
                {
                        sql_exec $cmd;
                        $cmd = "";
                }
        }
}

$dbh->disconnect;

__END__

Reply via email to