Skip to content

Commit

Permalink
Fixed check_costs.pl to always create table if table does not exists
Browse files Browse the repository at this point in the history
This allows one to always use --skip-create-table for repeated runs.
  • Loading branch information
montywi authored and spetrunia committed Feb 15, 2023
1 parent 587646a commit bd2cebb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tests/check_costs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ ()
setup_engine($engine);
setup($opt_init_query);
$table= $base_table . "_$engine";
if (!defined($opt_skip_create))
if (!defined($opt_skip_create) || !check_if_table_exist($table))
{
my $index_type="";

Expand Down Expand Up @@ -270,7 +270,7 @@ ()
ENGINE= $engine")
or die "Got error on CREATE TABLE: $DBI::errstr";
}
$cur_rows= get_row_count();
$cur_rows= get_row_count($table);
if ($cur_rows == 0 || !defined($opt_skip_create))
{
$dbh->do("insert into $table select
Expand Down Expand Up @@ -976,6 +976,8 @@ ()

sub get_row_count()
{
my ($table)= @_;
my ($query, $sth, $row);
$query= "select count(*) from $table";
$sth= $dbh->prepare($query) || die "Got error on '$query': " . $dbh->errstr . "\n";
if (!$sth->execute)
Expand All @@ -994,6 +996,7 @@ ()
sub get_variable()
{
my ($name)= @_;
my ($query, $sth, $row);
$query= "select @@" . $name;
if (!($sth= $dbh->prepare($query)))
{
Expand All @@ -1003,3 +1006,18 @@ ()
$row= $sth->fetchrow_arrayref();
return $row->[0];
}


sub check_if_table_exist()
{
my ($name)= @_;
my ($query,$sth);
$query= "select 1 from $name limit 1";
$sth= $dbh->prepare($query) || die "Got error on '$query': " . $dbh->errstr . "\n";
print $sth->fetchrow_arrayref();
if (!$sth->execute || !defined($sth->fetchrow_arrayref()))
{
return 0; # Table does not exists
}
return 1;
}

0 comments on commit bd2cebb

Please sign in to comment.