diff options
Diffstat (limited to 'lib/Travelynx/Command/database.pm')
-rw-r--r-- | lib/Travelynx/Command/database.pm | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm index 1c97cce..190063b 100644 --- a/lib/Travelynx/Command/database.pm +++ b/lib/Travelynx/Command/database.pm @@ -9,17 +9,27 @@ has usage => sub { shift->extract_usage }; sub get_schema_version { my ($dbh) = @_; - my $schema_version - = $dbh->selectall_arrayref(qq{select version from schema_version}); - if ( not defined $schema_version ) { + # We do not want DBD to print an SQL error if schema_version does not + # exist, as this is not an error in this case. Setting $dbh->{PrintError} = + # 0 would disable error printing for all subsequent SQL operations, however, + # we only want to disable it for this specific query. Hence we use a + # prepared statement and only disable error printing only there. + my $sth = $dbh->prepare(qq{select version from schema_version}); + $sth->{PrintError} = 0; + my $success = $sth->execute; + + if ( not defined $success ) { return undef; } - elsif ( @{$schema_version} == 1 ) { - return $schema_version->[0][0]; + + my $rows = $sth->fetchall_arrayref; + + if ( @{$rows} == 1 ) { + return $rows->[0][0]; } else { - printf( "Found multiple schema versions: %s", @{$schema_version} ); + printf( "Found multiple schema versions: %s", @{$rows} ); exit(1); } } |