PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: Using files to load database objects
Date: Jul 12 1999 11:07PM

John Portis writes:
 > 
 > 
 > Thank you.  How does one emulate the go statement?

You could do something like this:

while(1) {
   while(<>) {
      last if /^go/;     # execute this batch if go is on a line by itself
      exit if /^quit/;   # quit this script if 'quit' is on a line
      dbh->dbcmd($_);
   }
   $dbh->dbsqlexec;
   while($dbh->dbresults != NO_MORE_RESULTS) {
        while(@d = $dbh->dbnextrow) {
             print "@d\n";    # just in case...
        }
   }
}

This is just one of several possibilities.

Note that the above code will only exit if it hits 'quit' (ie it won't 
exit when the file has been read completely...) Fixing this is left as
an exercise for the reader :-)

Michael


 > Michael Peppler  on 07/12/99 05:56:22 PM
 > 
 > Please respond to SYBPERL-L@listproc.net
 > 
 > To:   SybPerl Discussion List 
 > cc:    (bcc: John Portis/Wayne/FNX)
 > 
 > Subject:  Re: Using files to load database objects
 > 
 > 
 > John Portis writes:
 >  >
 >  > I am trying to read a file that already has the sql for loading a
 > database
 >  > object (e.g. loads numerous triggers).  I've tried to join the file in a
 >  > variable and then execute.  I've also tried to keep calling
 >  > dbh->dbcmd("$_") and at the end of the file call dbh->dbsqlexec. I don't
 >  > know how to get the whole script into the one dbcmd.
 > 
 > Normally, something like this should work:
 > 
 > while(<>) {
 >    dbh->dbcmd($_);
 > }
 > $dbh->dbsqlexec;
 > while($dbh->dbresults != NO_MORE_RESULTS) {
 >     while(@d = $dbh->dbnextrow) {
 >      print "@d\n";    # just in case...
 >     }
 > }
 > 
 > However, if your load script has 'go' statements in it (that would
 > normally be interpreted by isql) then you'd have to emulate that in
 > the loop too.
 > 
 > Michael
 > --
 > Michael Peppler         -||-  Data Migrations Inc.
 > mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
 > Int. Sybase User Group  -||-  http://www.isug.com
 > Sybase on Linux mailing list: ase-linux-list@isug.com
 > 
 > 
 > 
 > 
 > 
 > 

-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@peppler.org    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com