Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Squerl] multi-table Dataset dies on mutating methods

  • Loading branch information...
commit 97aa3ee4532c3bb64325d120d80fae80b61b9eef 1 parent 6ccdc96
@masak authored
Showing with 24 additions and 2 deletions.
  1. +12 −2 lib/Squerl.pm
  2. +12 −0 t/squerl/02-dataset.t
View
14 lib/Squerl.pm
@@ -130,6 +130,11 @@ class Squerl::Dataset does Positional {
$sql
}
+ method check_modification_allowed() {
+ die ~Squerl::InvalidOperation.new('Joined datasets cannot be modified')
+ if %!opts<from> ~~ Array && %!opts<from>.elems > 1;
+ }
+
method select_sql() {
return self.static_sql(%!opts<sql>)
if %!opts.exists('sql');
@@ -145,6 +150,8 @@ class Squerl::Dataset does Positional {
return self.static_sql(%!opts<sql>)
if %!opts.exists('sql');
+ self.check_modification_allowed();
+
# RAKUDO: Real string interpolation
"DELETE FROM {%!opts<from>}";
}
@@ -153,6 +160,8 @@ class Squerl::Dataset does Positional {
return self.static_sql(%!opts<sql>)
if %!opts.exists('sql');
+ self.check_modification_allowed();
+
# RAKUDO: Real string interpolation
"TRUNCATE TABLE {%!opts<from>}";
}
@@ -161,6 +170,8 @@ class Squerl::Dataset does Positional {
return self.static_sql(%!opts<sql>)
if %!opts.exists('sql');
+ self.check_modification_allowed();
+
my (@columns, @values);
for @positionals {
when Pair {
@@ -198,8 +209,7 @@ class Squerl::Dataset does Positional {
return self.static_sql(%!opts<sql>)
if %!opts.exists('sql');
- die ~Squerl::InvalidOperation.new('Joined datasets cannot be modified')
- if %!opts<from> ~~ Array && %!opts<from>.elems > 1;
+ self.check_modification_allowed();
my $values = join $COMMA_SEPARATOR, map {
"{.key} = {self.literal(.value)}"
View
12 t/squerl/02-dataset.t
@@ -286,6 +286,18 @@ $dataset = Squerl::Dataset.new(undef).from('t1', 't2');
throws_exception { $dataset.update_sql( a => 1 ) },
'Squerl::InvalidOperation',
'multi-table dataset dies on .update_sql';
+
+ throws_exception { $dataset.delete_sql() },
+ 'Squerl::InvalidOperation',
+ 'multi-table dataset dies on .delete_sql';
+
+ throws_exception { $dataset.truncate_sql() },
+ 'Squerl::InvalidOperation',
+ 'multi-table dataset dies on .truncate_sql';
+
+ throws_exception { $dataset.insert_sql() },
+ 'Squerl::InvalidOperation',
+ 'multi-table dataset dies on .insert_sql';
}
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.