Win has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone ever produced anything like the following, and has got MS SQL 2000 to accept the requests that are submitted. Without error messages like:
DBD::ODBC::db do failed: [Microsoft][ODBC SQL Server Driver][SQL Serve +r]Line 567: Incorrect syntax near 'GO'. (SQL-42000)(DBD: Execute imme +diate failed err=-1) at Run_required_SPROCS.pl line 97, <FILE> line 9 +35. <code>
The code:
#! perl -w use strict; use warnings; use DBI; use DBD::ODBC; use File::Copy; my ($data_source, $database, $user_id, $password) = qw(127.0.0.1 not_t +elling not_telling not_telling ); # This ip address is an address tha +t is common to all computers and therefore is a perminant ip address my $conn_string = "driver={SQL Server}; Server=$data_source; Database= +$database; Trusted_Connection=yes"; my $dbh = DBI->connect( "DBI:ODBC:$conn_string" ) or die $DBI::errstr; my @files; my $line; my $file; while (<*.sql>) { next if $_ eq 'Activate.sql'; $file = $_; open (FILE, "$file"); my $line_number = 0; my $run; LINE: while (<FILE>){ my $line = $_; $line_number = $line_number +1; $run = 1; if ($line_number == 1){ $run = 0 if $line !~ m/^ALTER\sPROCEDURE\s/; last LINE; } else { $run = 1; } last LINE; } if ($run == 1){ push (@files, $file); } else { #Do nothing } } print "@files"; my $line_B; my $FH; my $batch; foreach my $filename ( @files ) { open ( FILE, "<", $filename ) or die( "Couldn't open $filename: $!" ); my $batch = ""; INNER: while ((<FILE>)) { # s/ALTER\bPROCEDURE/CREATE PROCEDURE/; $batch .= $_; last INNER if eof || m/^\s*go\s*$/i; } # print $batch; # sleep 5; $dbh->do($batch) if ($batch =~ m/\s*go\s*$/msi); #http://perldoc.pe +rl.org/perlre.html }
Update: By the way. This program now works very well when the SPROCS are already present but does not work when I want to create new SPROCS. Never mind.

Replies are listed 'Best First'.
Re: DBD::ODBC error
by VSarkiss (Monsignor) on Oct 07, 2005 at 18:12 UTC

      Actually... the go has nothing to do with Transact-SQL. It just happened to be the token that isql used to identify the end of a batch. Similar to MySQL's ;.

      Jason L. Froebe

      Team Sybase member

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1