Skip to content

Commit

Permalink
Properly handle NULL URIs.
Browse files Browse the repository at this point in the history
Copied from the Firebird engine, but applies to them all.
  • Loading branch information
theory committed Dec 16, 2013
1 parent bc9eb21 commit 506128b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 75 deletions.
74 changes: 0 additions & 74 deletions lib/App/Sqitch/Engine/firebird.pm
Expand Up @@ -380,80 +380,6 @@ sub current_state {
return $state;
}

sub register_project {
my $self = shift;
my $sqitch = $self->sqitch;
my $dbh = $self->dbh;
my $plan = $self->plan;
my $proj = $plan->project;
my $uri = $plan->uri;

my $res = $dbh->selectcol_arrayref(
'SELECT uri FROM projects WHERE project = ?',
undef, $proj
);

if (@{ $res }) {
# A project with that name is already registreed. Compare URIs.
my $reg_uri = $res->[0];
if ( defined $uri && !defined $reg_uri ) {
hurl engine => __x(
'Cannot register "{project}" with URI {uri}: already exists with NULL URI',
project => $proj,
uri => $uri
);
} elsif ( !defined $uri && defined $reg_uri ) {
hurl engine => __x(
'Cannot register "{project}" without URI: already exists with URI {uri}',
project => $proj,
uri => $reg_uri
);
} elsif ( defined $uri && defined $reg_uri ) {
hurl engine => __x(
'Cannot register "{project}" with URI {uri}: already exists with URI {reg_uri}',
project => $proj,
uri => $uri,
reg_uri => $reg_uri,
) if $uri ne $reg_uri;
} else {
# Both are undef, so cool.
}
} else {
# Does the URI already exist?

# Fix "You have not provided a value for non-nullable parameter #0"
my $res;
if (defined $uri) {
$res = $dbh->selectcol_arrayref(
'SELECT project FROM projects WHERE uri = ?',
undef, $uri
);
}
else {
$res = $dbh->selectcol_arrayref(
'SELECT project FROM projects WHERE uri IS null',
undef
);
}

hurl engine => __x(
'Cannot register "{project}" with URI {uri}: project "{reg_prog}" already using that URI',
project => $proj,
uri => $uri,
reg_proj => $res->[0],
) if @{ $res };

# Insert the project.
my $ts = $self->_ts_default;
$dbh->do(qq{
INSERT INTO projects (project, uri, creator_name, creator_email, created_at)
VALUES (?, ?, ?, ?, $ts)
}, undef, $proj, $uri, $sqitch->user_name, $sqitch->user_email);
}

return $self;
}

sub search_events {
my ( $self, %p ) = @_;

Expand Down
4 changes: 3 additions & 1 deletion lib/App/Sqitch/Role/DBIEngine.pm
Expand Up @@ -308,9 +308,11 @@ sub register_project {
}
} else {
# Does the URI already exist?
my $res = $dbh->selectcol_arrayref(
my $res = defined $uri ? $dbh->selectcol_arrayref(
'SELECT project FROM projects WHERE uri = ?',
undef, $uri
) : $dbh->selectcol_arrayref(
'SELECT project FROM projects WHERE uri IS NULL',
);

hurl engine => __x(
Expand Down

0 comments on commit 506128b

Please sign in to comment.