Solved

Covert Sybase DBLIB calls to Postgres

Posted on 2013-01-30
2
430 Views
Last Modified: 2013-02-13
I need to convert Sysbase calls in Perl to Postgres. How should I go about, do I need to use the DBI module?

 execute($dbh, qq!CREATE TABLE tempdb..$gSensGrpParam{$sensType}{tmpSensTable} ( $gTmpSensTableDefinition )!);

 @result = RunSqlCmdWithResult($dbh, $cmd);

   
   
      @result = RunSqlCmdWithResult($dbh, $cmd);

   
   
      @result = RunSqlCmdWithResult($dbh, $cmd);

   
   
      @result = RunSqlCmdWithResult($dbh, $cmd);

   
   
      @results = RunSqlCmdWithResult($dbh, $cmd);

   
   
      @results = RunSqlCmdWithResult($dbh, $cmd);

   
   
      bcpDataFile($filename);

   
   
      if (@data = $dbh->dbnextrow) {

   
   
      if (@data = $dbh->dbnextrow) {

   
   
      LogError("Command FAILED!!\n\t$bcp_cmd\n");

   
   
      LogError("Command FAILED!!\n\t$bcp_cmd\n");

   
   
      LogInfo("BCP command

    \n $cmd");

   
   
      LogInfo("BCP command

    \n $cmd");

   
   
      LogInfo("BCP filename

     $filename");

   
   
      my $result = RunSqlCmd($dbh, $cmd);

   
   
      my $result = RunSqlCmd($dbh, $cmd);

   
   
      my $result = RunSqlCmd($dbh, $cmd);

   
   
      my $status = $dbh->dbuse($database);

   
   
      my @results = RunSqlCmdWithResult($dbh, $cmd);

   
   
      my @results = RunSqlCmdWithResult($dbh, $cmd);

   
   
      while ( @data = $dbh->dbnextrow ) {

   
   
      while ( @data = $dbh->dbnextrow ) {

   
   
      while ( @data = $dbh->dbnextrow ) {
   
   
      while ( @data = $dbh->dbnextrow ) {
   
   
     # bcp the file
   
   
     # bcp the files
   
   
     # bcp the files
   
   
     # bcp the files
   
   
     # bcp to load data
   
   
     # get the directory name for saving bcp files

   
   
     #$betaTable => $betaBCP,

   
   
     #$volTable => $volBCP

   
   
     $bcpfiledir = $bcpfiledir . "/" . $line;

   
   
     $betaTable => $betaBCP,

   
   
     $bskTable => $bskBCP,

   
   
     $cmd = "bcp $DBName.$DBOwner.$aggrTable in $aggrBCP -U $DBUser -P $DBPass -S $DBServer  -c -t \\;";

   
   
     $cmd = "bcp $DBName.$DBOwner.$sensTable in $sensBCP -U $DBUser -P $DBPass -S $DBServer  -c -t \\;";

   
   
     $dbh->dbclose();

   
   
     $dbh->dbclose();

   
   
     $dbh->dbclose();

   
   
     $dbh->dbclose();

   
   
     $dbh->dbclose();

   
   
     $dbh->dbclose();

   
   
     $dbh->dbcmd($sql) == SUCCEED  || die "Fail to dbcmd $sql";

   
   
     $dbh->dbresults == SUCCEED || die "Fail to dbresults $sql";

   
   
     $dbh->dbsqlexec == SUCCEED || die "Fail to dbsqlexec $sql";

   
   
     $dir = $localRoot. "/".  $bcpDataDirName;

   
   
     $doBcp = true;

   
   
     $filename = $restoreRoot. "/". $bcpDataDirName. "/". $businessDate. ".tar.gz";

   
   
     $lookupBCP = $lookupBCP . "-" . $runId;

   
   

BackTestBetaAdj.pl:use Sybase::DBlib;
BackTestBetaAdj.pl:my $dbh;
BackTestBetaAdj.pl:$dbh=Sybase::DBlib->dblogin($sUserId, $sPassword, $sServer) or
BackTestBetaAdj.pl:$dbh->dbuse($sDatabase);
BackTestBetaAdj.pl:     $s1 = $dbh->dbcmd($sSqlCmd);
BackTestBetaAdj.pl:     $s2 = $dbh->dbsqlexec;
BackTestBetaAdj.pl:     $s3 = $dbh->dbresults;
BackTestBetaAdj.pl:     while( @data = $dbh->dbnextrow )
BackTestBetaAdj.pl:             $s1 = $dbh->dbcmd($sqlSelect);
BackTestBetaAdj.pl:             $s2 = $dbh->dbsqlexec;
BackTestBetaAdj.pl:             $s3 = $dbh->dbresults;
BackTestBetaAdj.pl:             while( @data = $dbh->dbnextrow )
BackTestBetaAdj.pl:     $s1 = $dbh->dbcmd($sqlUpdate);
BackTestBetaAdj.pl:     $s2 = $dbh->dbsqlexec;
BackTestBetaAdj.pl:     $s3 = $dbh->dbresults;
BackTestBetaAdj.pl:                     $s1 = $dbh->dbcmd($sqlSelect);
BackTestBetaAdj.pl:                     $s2 = $dbh->dbsqlexec;
BackTestBetaAdj.pl:                     $s3 = $dbh->dbresults;
BackTestBetaAdj.pl:                             while( @data = $dbh->dbnextrow )
BackTestBetaAdj.pl:        $dbh->dbclose();

3      bcpCommSens.pl            
bcpCommSens.pl:# Name:  bcpsens.pl
bcpCommSens.pl:# Description: Script to bcp commodity sensitivity and aggregation files to database
bcpCommSens.pl:use Sybase::DBlib;
bcpCommSens.pl:my $sensBCP = $rc->getValue($configType . ".SensitivityBCPFile");
bcpCommSens.pl:my $aggrBCP = $rc->getValue($configType . ".AggregationBCPFile");
bcpCommSens.pl:#$sensBCP =~ s/\@CCYYMMDD/$businessDate/g;
bcpCommSens.pl:#$aggrBCP =~ s/\@CCYYMMDD/$businessDate/g;
bcpCommSens.pl:LogDebug("Bcp file for db table $sensTable is $sensBCP.");
bcpCommSens.pl:LogDebug("Bcp file for db table $aggrTable is $aggrBCP.");
bcpCommSens.pl:LoadBCPFiles();
bcpCommSens.pl:# load bcp files into database
bcpCommSens.pl:sub LoadBCPFiles
bcpCommSens.pl: LogDebug("calling LoadBCPFiles.");
bcpCommSens.pl: my $dbh = Sybase::DBlib->dblogin($DBUser, $DBPass, $DBServer);
bcpCommSens.pl: my $status = $dbh->dbuse($DBName);
bcpCommSens.pl: my $result = RunSqlCmd($dbh, $cmd);
bcpCommSens.pl: $result = RunSqlCmd($dbh, $cmd);
bcpCommSens.pl: $dbh->dbclose();
bcpCommSens.pl: # bcp to load data
bcpCommSens.pl: $cmd = "bcp $DBName.$DBOwner.$sensTable in $sensBCP -U $DBUser -P $DBPass -S $DBServer  -c -t \\;";
bcpCommSens.pl: LogInfo("BCP command:\n                   $cmd");
bcpCommSens.pl: $cmd = "bcp $DBName.$DBOwner.$aggrTable in $aggrBCP -U $DBUser -P $DBPass -S $DBServer  -c -t \\;";
bcpCommSens.pl: LogInfo("BCP command:\n                   $cmd");
bcpCommSens.pl:}        # end of LoadBCPFiles
0
Comment
Question by:rockrem
2 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 38836083
Your best bet is to use DBI.  I'm surprised you're still using Sybase::DBLib - it has (I think) been deprecated for a *long* time (we moved off it (to DBI and DBD::Sybase) over a decade ago).

One potential major gotcha is that Sybase supports multiple sql statements in a single query whereas almost every other db does not (MS SQL Server is the only other one I know of that supports this).  If that is the case, you will likely have to do some potentially major restructuring to your sql.

Also, the bcp commands will need to change to whatever Postgres uses.
0
 

Author Comment

by:rockrem
ID: 38886197
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now