Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gorgone): Do not log errors when checking if we need to create/update db schema #1580

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions gorgone/gorgone/class/db.pm
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,18 @@ sub do {
}

sub error {
my ($self, $error, $query) = @_;
my ($self, $error, $query, %options) = @_;
my ($package, $filename, $line) = caller 1;

%options = () if (ref(\%options) ne 'HASH');

chomp($query);
$self->{lastError} = "SQL error: $error (caller: $package:$filename:$line)
Query: $query
";
$self->{logger}->writeLogError($error);
unless ($options{no_log}) {
$self->{logger}->writeLogError($error);
}
if ($self->{transaction_begin} == 1) {
$self->rollback();
}
Expand All @@ -336,6 +340,9 @@ sub query {
my ($self) = shift;
my ($status, $count) = (0, -1);
my $statement_handle;
my %error_options = ();

$error_options{no_log} = 1 if ($_[0]->{no_error_log});

while (1) {
if (!defined($self->{instance})) {
Expand All @@ -348,7 +355,7 @@ sub query {
$count++;
$statement_handle = $self->{instance}->prepare($_[0]->{query});
if (!defined($statement_handle)) {
$self->error($self->{instance}->errstr, $_[0]->{query});
$self->error($self->{instance}->errstr, $_[0]->{query}, %error_options);
$status = -1;
last if ($self->{force} == 0 || ($self->{force} == 2 && $count == 1));
sleep(1);
Expand All @@ -367,7 +374,7 @@ sub query {
$rv = $statement_handle->execute();
}
if (!$rv) {
$self->error($statement_handle->errstr, $_[0]->{query});
$self->error($statement_handle->errstr, $_[0]->{query}, %error_options);
$status = -1;
last if ($self->{force} == 0 || ($self->{force} == 2 && $count == 1));
sleep(1);
Expand Down
6 changes: 4 additions & 2 deletions gorgone/gorgone/standard/library.pm
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,11 @@ sub init_database {
return if (!defined($options{autocreate_schema}) || $options{autocreate_schema} != 1);

my $db_version = '1.0';
my ($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT `value` FROM gorgone_information WHERE `key` = 'version'} });
# don't log errors for this query as we know the tables may not exist, and
# that's the info we're looking for
my ($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT `value` FROM gorgone_information WHERE `key` = 'version'}, no_error_log => 1 });
if ($status == -1) {
($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT 1 FROM gorgone_identity LIMIT 1} });
($status, $sth) = $options{gorgone}->{db_gorgone}->query({ query => q{SELECT 1 FROM gorgone_identity LIMIT 1}, no_error_log => 1 });
if ($status == -1) {
create_schema(gorgone => $options{gorgone}, logger => $options{logger}, version => $options{version});
return ;
Expand Down