remembering parameters

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have two queries -- I pass the result of the SELECT query to a stored
procedure. The result from the SELECT query is different during every
pass and I somehow need to remember the old value and pass that to the
store procedure when next time the perl script runs. I would appreciate
some help.

#!/usr/bin/perl  -w
use strict ;
use DBI qw/:sql_types/;

my $SQL_server   = "mssql" ;
my $SQL_username = "user" ;
my $SQL_password = "XXXXX" ;

my $dbh = DBI->connect("dbi:Sybase:server=$SQL_server",
                        {PrintError => 1});

die "Unable for connect to server $DBI::errstr" unless $dbh;

   $dbh->do("use MyDatabase"); # Set the database to use.
    my $last ; # this is where I would store the old value, need to
remember it from the previous run

    my $qry="SELECT Col1 from Table" ;
    my $sth = $dbh->prepare($qry);
    $sth->execute ;
    #new value
    my @row = $sth->fetchrow_array ;

#stored procedure
   my $sp_qry = "EXEC Stored_Procedure ?" ;
   my $sth1 = $dbh->prepare($sp_qry) ;
   $sth1->bind_param(1, $row[0], SQL_VARCHAR);
   or die "Couldn't execute statement: " . $sth1->errstr;
   print "\n";
   while (my  @rs = $sth1->fetchrow_array)
            print "Results: $rs[0]\n" ;

   $sth1->finish() ;
   $dbh->disconnect() ;

Re: remembering parameters

Sharif Islam wrote:
Quoted text here. Click to load it

Write it to a file:

perldoc -f open
perldoc perlopentut

Or store it in a table by date, or some other relevant key, if needed,
then query the table on your next run.

Re: remembering parameters

J. Gleixner wrote:
Quoted text here. Click to load it

thanks, the file method worked fine.


Site Timeline