added EXPERIMENTAL select() wrap option to support...
...Oracle ROWNUM
| ... | ... |
@@ -1,3 +1,5 @@ |
| 1 |
+0.1679 |
|
| 2 |
+ - added EXPERIMENTAL select() wrap option to support Oracle ROWNUM |
|
| 1 | 3 |
0.1678 |
| 2 | 4 |
- DBIx::Custom::Model filter attribute can receive hash reference |
| 3 | 5 |
- DBIx::Custom::Where clause attribute can receive clause without column name |
| ... | ... |
@@ -1,6 +1,6 @@ |
| 1 | 1 |
package DBIx::Custom; |
| 2 | 2 |
|
| 3 |
-our $VERSION = '0.1678'; |
|
| 3 |
+our $VERSION = '0.1679'; |
|
| 4 | 4 |
|
| 5 | 5 |
use 5.008001; |
| 6 | 6 |
use strict; |
| ... | ... |
@@ -811,7 +811,8 @@ sub register_filter {
|
| 811 | 811 |
sub register_tag { shift->query_builder->register_tag(@_) }
|
| 812 | 812 |
|
| 813 | 813 |
our %SELECT_ARGS |
| 814 |
- = map { $_ => 1 } @COMMON_ARGS, qw/column where append relation join param/;
|
|
| 814 |
+ = map { $_ => 1 } @COMMON_ARGS,
|
|
| 815 |
+ qw/column where append relation join param wrap/; |
|
| 815 | 816 |
|
| 816 | 817 |
sub select {
|
| 817 | 818 |
my ($self, %args) = @_; |
| ... | ... |
@@ -831,6 +832,7 @@ sub select {
|
| 831 | 832 |
my $relation = delete $args{relation};
|
| 832 | 833 |
my $param = delete $args{param} || {};
|
| 833 | 834 |
my $query_return = $args{query};
|
| 835 |
+ my $wrap = delete $args{wrap};
|
|
| 834 | 836 |
|
| 835 | 837 |
# Check arguments |
| 836 | 838 |
foreach my $name (keys %args) {
|
| ... | ... |
@@ -900,6 +902,14 @@ sub select {
|
| 900 | 902 |
# Append |
| 901 | 903 |
push @sql, $append if $append; |
| 902 | 904 |
|
| 905 |
+ # Wrap |
|
| 906 |
+ if ($wrap) {
|
|
| 907 |
+ croak "wrap option must be array refrence (DBIx::Custom::select)" |
|
| 908 |
+ unless ref $wrap eq 'ARRAY'; |
|
| 909 |
+ unshift @sql, $wrap->[0]; |
|
| 910 |
+ push @sql, $wrap->[1]; |
|
| 911 |
+ } |
|
| 912 |
+ |
|
| 903 | 913 |
# SQL |
| 904 | 914 |
my $sql = join (' ', @sql);
|
| 905 | 915 |
|
| ... | ... |
@@ -2129,3 +2129,24 @@ $rows = $dbi->select( |
| 2129 | 2129 |
)->fetch_hash_all; |
| 2130 | 2130 |
is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]);
|
| 2131 | 2131 |
|
| 2132 |
+ |
|
| 2133 |
+test 'select() wrap option'; |
|
| 2134 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
|
| 2135 |
+$dbi->execute($CREATE_TABLE->{0});
|
|
| 2136 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 2137 |
+$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3});
|
|
| 2138 |
+$rows = $dbi->select( |
|
| 2139 |
+ table => 'table1', |
|
| 2140 |
+ column => 'key1', |
|
| 2141 |
+ wrap => ['select * from (', ') as t where key1 = 1']
|
|
| 2142 |
+)->fetch_hash_all; |
|
| 2143 |
+is_deeply($rows, [{key1 => 1}]);
|
|
| 2144 |
+ |
|
| 2145 |
+eval {
|
|
| 2146 |
+$dbi->select( |
|
| 2147 |
+ table => 'table1', |
|
| 2148 |
+ column => 'key1', |
|
| 2149 |
+ wrap => 'select * from ('
|
|
| 2150 |
+) |
|
| 2151 |
+}; |
|
| 2152 |
+like($@, qr/array/); |