Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more consistent error messages
  • Loading branch information
kraih committed Jan 28, 2018
1 parent e221f63 commit 67d9d63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions lib/SQL/Abstract/Pg.pm
Expand Up @@ -17,7 +17,7 @@ sub select {
my @fields;
for my $field (@$fields) {
if (ref $field eq 'ARRAY') {
puke 'as value needs at least 2 elements' if @$field < 2;
puke 'field alias must be in the form [$name => $alias]' if @$field < 2;
push @fields,
$self->_quote($field->[0])
. $self->_sqlcase(' as ')
Expand Down Expand Up @@ -47,9 +47,9 @@ sub _insert_returning {
$conflict => {
ARRAYREF => sub {
my ($fields, $set) = @$conflict;
puke qq{on_conflict value "$fields" not allowed}
puke qq{on_conflict value "$fields" is not allowed}
unless ref $fields eq 'ARRAY';
puke qq{on_conflict value "$set" not allowed}
puke qq{on_conflict value "$set" is not allowed}
unless ref $set eq 'HASH';

$conflict_sql
Expand Down Expand Up @@ -126,7 +126,7 @@ sub _order_by {
$self->_SWITCH_refkind(
$for => {
SCALAR => sub {
puke qq{for value "$for" not allowed} unless $for eq 'update';
puke qq{for value "$for" is not allowed} unless $for eq 'update';
$for_sql = $self->_sqlcase('UPDATE');
},
SCALARREF => sub { $for_sql .= $$for }
Expand All @@ -151,7 +151,7 @@ sub _table {

$table = $self->SUPER::_table(\@table);
for my $join (@join) {
puke 'join value needs at least 3 elements' if @$join < 3;
puke 'join must be in the form [$table, $fk => $pk]' if @$join < 3;
my $type = @$join > 3 ? shift @$join : '';
my ($name, $fk, $pk) = @$join;
$table
Expand Down
7 changes: 4 additions & 3 deletions t/sql.t
Expand Up @@ -114,7 +114,7 @@ is_deeply \@sql, ['SELECT * FROM "foo" FOR update skip locked'], 'right query';

# FOR (unsupported value)
eval { $abstract->select('foo', '*', undef, {for => 'update skip locked'}) };
like $@, qr/for value "update skip locked" not allowed/, 'right error';
like $@, qr/for value "update skip locked" is not allowed/, 'right error';
eval { $abstract->select('foo', '*', undef, {for => []}) };
like $@, qr/ARRAYREF/, 'right error';

Expand All @@ -130,7 +130,8 @@ is_deeply \@sql,

# AS (unsupported value)
eval { $abstract->select('foo', [[]]) };
like $@, qr/as value needs at least 2 elements/, 'right error';
like $@, qr/field alias must be in the form \[\$name => \$alias\]/,
'right error';

# JOIN
@sql = $abstract->select(['foo', ['bar', foo_id => 'id']]);
Expand Down Expand Up @@ -160,6 +161,6 @@ is_deeply \@sql,

# JOIN (unsupported value)
eval { $abstract->select(['foo', []]) };
like $@, qr/join value needs at least 3 elements/, 'right error';
like $@, qr/join must be in the form \[\$table, \$fk => \$pk\]/, 'right error';

done_testing();

0 comments on commit 67d9d63

Please sign in to comment.