... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
0.1670 |
2 |
- - removed EXPERIMETNAL select() column hash option. it's a little complex |
|
3 |
- |
|
2 |
+ - removed EXPERIMETNAL select() column hash option. it's a little complex. |
|
3 |
+ - added EXPERIMETAL select() param option. |
|
4 | 4 |
0.1669 |
5 | 5 |
- renamed update_param to update_param_tag, update_param is DEPRECATED! |
6 | 6 |
- renamed insert_param to insert_param_tag, insert_param is DEPRECATED! |
... | ... |
@@ -841,7 +841,7 @@ sub register_filter { |
841 | 841 |
sub register_tag { shift->query_builder->register_tag(@_) } |
842 | 842 |
|
843 | 843 |
our %SELECT_ARGS |
844 |
- = map { $_ => 1 } @COMMON_ARGS, qw/column where append relation join/; |
|
844 |
+ = map { $_ => 1 } @COMMON_ARGS, qw/column where append relation join param/; |
|
845 | 845 |
|
846 | 846 |
sub select { |
847 | 847 |
my ($self, %args) = @_; |
... | ... |
@@ -906,6 +906,9 @@ sub select { |
906 | 906 |
|
907 | 907 |
# Main table |
908 | 908 |
croak "Not found table name" unless $tables->[-1]; |
909 |
+ |
|
910 |
+ # Add table names in param |
|
911 |
+ unshift @$tables, @{$self->_tables(join(' ', keys %$param) || '')}; |
|
909 | 912 |
|
910 | 913 |
# Where |
911 | 914 |
my $w = $self->_where($where); |
... | ... |
@@ -1310,8 +1313,8 @@ sub _push_join { |
1310 | 1313 |
|
1311 | 1314 |
my $join_clause = $join->[$i]; |
1312 | 1315 |
my $q_re = quotemeta($q); |
1313 |
- my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/ |
|
1314 |
- : qr/\s([^\.\s]+?)\..+\s([^\.\s]+?)\..+?$/; |
|
1316 |
+ my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/ |
|
1317 |
+ : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/; |
|
1315 | 1318 |
if ($join_clause =~ $join_re) { |
1316 | 1319 |
|
1317 | 1320 |
my $table1 = $1; |
... | ... |
@@ -2087,4 +2087,41 @@ test 'merge_param'; |
2087 | 2087 |
my $param3 = {key1 => 1}; |
2088 | 2088 |
my $param = $dbi->merge_param($param1, $param2, $param3); |
2089 | 2089 |
is_deeply($param, {key1 => [1, 1, 1], key2 => [2, 2], key3 => 3}); |
2090 |
-} |
|
2090 |
+} |
|
2091 |
+ |
|
2092 |
+test 'select() param option'; |
|
2093 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2094 |
+$dbi->execute($CREATE_TABLE->{0}); |
|
2095 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2096 |
+$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2097 |
+$dbi->execute($CREATE_TABLE->{2}); |
|
2098 |
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4}); |
|
2099 |
+$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5}); |
|
2100 |
+$DB::single = 1; |
|
2101 |
+$rows = $dbi->select( |
|
2102 |
+ table => 'table1', |
|
2103 |
+ column => 'table1.key1 as table1_key1, key2, key3', |
|
2104 |
+ where => {'table1.key2' => 3}, |
|
2105 |
+ join => ['inner join (select * from table2 where {= table2.key3})' . |
|
2106 |
+ ' as table2 on table1.key1 = table2.key1'], |
|
2107 |
+ param => {'table2.key3' => 5} |
|
2108 |
+)->fetch_hash_all; |
|
2109 |
+is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]); |
|
2110 |
+ |
|
2111 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
2112 |
+$dbi->reserved_word_quote('"'); |
|
2113 |
+$dbi->execute($CREATE_TABLE->{0}); |
|
2114 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
2115 |
+$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
2116 |
+$dbi->execute($CREATE_TABLE->{2}); |
|
2117 |
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 4}); |
|
2118 |
+$dbi->insert(table => 'table2', param => {key1 => 2, key3 => 5}); |
|
2119 |
+$rows = $dbi->select( |
|
2120 |
+ table => 'table1', |
|
2121 |
+ column => 'table1.key1 as table1_key1, key2, key3', |
|
2122 |
+ where => {'table1.key2' => 3}, |
|
2123 |
+ join => ['inner join (select * from table2 where {= table2.key3})' . |
|
2124 |
+ ' as table2 on "table1"."key1" = "table2"."key1"'], |
|
2125 |
+ param => {'table2.key3' => 5} |
|
2126 |
+)->fetch_hash_all; |
|
2127 |
+is_deeply($rows, [{table1_key1 => 2, key2 => 3, key3 => 5}]); |