Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to take bcp from sybase using perl?

Status
Not open for further replies.

Sina

Technical User
Jan 2, 2001
309
CA
Hello everyone,

I'm looking for a script to take a bcp dump of a database from sybase and load it to another sybase database.

So basically connect to source server, take a dump of sourcedb and load that dump on to the destination server.

I really wold like to do that with perl using perl module.

Can anyone help?

Thank you.
 
I don't understand what you mean by bcp but I regularly copy dtabase contents between Sybase, MS SQL and Informix database servers.

It is not particularly hard once you've got the initial configuration out of the way. The modules DBI and DBD::Sybase let you connect to multiple Sybase servers and you can easily read the system catalogues to get the names of the tables.

For each table, read the first row into an array , then use the size of the array to get the number of columns and prepare an insert query with the correct number of placeholders:

[tt]my @firstrow = $q->fetchrow_array();
next TABLE unless @firstrow;
my $SQL = "INSERT INTO $tablename VALUES ( "
. join( ', ', '?' x scalar @firstrow )
. ')'
my $qins = $dbh->prepare( $SQL );
$qins->execute( @firstrow );
while( my @row = $q->fetchrow_array() ) {
$qins->execute( @row );
}[/tt]

I hope that this helps.

Yours, "As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top