in reply to Re: How to determine when sybase process complete
in thread How to determine when sybase process complete

This is the sub routine that alters the sybase database. the alter command can run for a extended period of time.
sub _grow_db() { my ( $dbh, $dbname, $increase, $tran_size, $data_pool, $log_pool ) = @ +_; my $log_increase = int ( $increase * $params->get("Device.Log.Percent" +) / 100 ); my $max_tran_size = int ( $params->get("Max.Tran.Size") ); my $sql = "use master"; $$dbh->do($sql) or $app->log($FATAL, "Can't do SQL statement [ $sql ] :: $DBI::errst +r"); $app->log($INFO,"Altering database $dbname. Increasing data segment b +y $increase MB"); my $sql="alter database $dbname on "; foreach my $device ( @$data_pool ) { next if ( $$device{free} == 0 ); if ( $increase >= $$device{free} ) { $sql .= "$$device{name}=$$device{free},"; $increase -= $$device{free}; $$device{free} = 0; } else { $sql .= "$$device{name}=$increase,"; $$device{free} -= $increase; $increase = 0; } last if ( $increase == 0 ); } if ( $tran_size < $max_tran_size ) { $app->log($INFO,"Altering database $dbname. Increasing log segment by +$log_increase MB"); $sql =~ s/,$//; $sql .= " log on "; foreach my $device ( @$log_pool ) { next if ( $$device{free} == 0 ); if ( $log_increase >= $$device{free} ) { $sql .= "$$device{name}=$$device{free},"; $log_increase -= $$device{free}; $$device{free} = 0; } else { $sql .= "$$device{name}=$log_increase,"; $$device{free} -= $log_increase; $log_increase = 0; } last if ( $log_increase == 0 ); } } $sql =~ s/,$//; #$$dbh->do($sql) # or $app->log($FATAL,"Can't do SQL statement [ $sql ] :: $DBI::err +str"); my $sth = $$dbh->prepare($sql) or $app->log($FATAL,"Can't prepare SQL statement [ $sql ] :: $DBI: +:errstr"); $sth->execute(); $sth->finish();
this is the output from a alter database command.
alter database D_IGT_IMP on data023device = 43 log on
log003device = 5
2> go
Extending database by 22016 pages on disk data023device
Extending database by 2560 pages on disk log003device
Warning: Using ALTER DATABASE to extend the log segment
will cause user thresholds on the log segment within 128
pages of the last
chance threshold to be disabled.
} This is the sub routinne that fails if run after the alter database.
sub get_table_info() { my ( $dbh, $table ) = @_; my @columns = (); my $sql = "exec sp_getcol2 $table"; my $sth = $$dbh->prepare( $sql ) or $app->log($FATAL,"Can't prepare SQL statement [ $sql ] :: $DBI: +:errstr"); $sth->execute() or $app->log($FATAL,"Can't prepare SQL statement [ $sql ] :: $DBI: +:errstr"); while ( my (@results) = $sth->fetchrow_array() ) { my $col_ref = { 'name' => $results[0], 'type' => $results[1], 'length' => $results[2], 'prec' => $results[3], 'scale' => $results[4], 'null' => $results[5], 'identity' => $results[8] }; push @columns, $col_ref; } $sth->finish(); return \@columns; }