| ... | ... |
@@ -1,3 +1,5 @@ |
| 1 |
+0.1725 |
|
| 2 |
+ - improved join clause parsing. |
|
| 1 | 3 |
0.1724 |
| 2 | 4 |
- added EXPERIMENTAL like_value method to DBIx::Custom |
| 3 | 5 |
- sqlfilter option is renamed to after_build_sql, sqlfilter is DEPRECATED! |
| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
package DBIx::Custom; |
| 2 | 2 |
use Object::Simple -base; |
| 3 | 3 |
|
| 4 |
-our $VERSION = '0.1724'; |
|
| 4 |
+our $VERSION = '0.1725'; |
|
| 5 | 5 |
use 5.008001; |
| 6 | 6 |
|
| 7 | 7 |
use Carp 'croak'; |
| ... | ... |
@@ -1457,11 +1457,16 @@ sub _push_join {
|
| 1457 | 1457 |
$j_clause =~ s/'.+?'//g; |
| 1458 | 1458 |
my $q_re = quotemeta($q); |
| 1459 | 1459 |
$j_clause =~ s/[$q_re]//g; |
| 1460 |
+ |
|
| 1461 |
+ my @j_clauses = reverse split /\s(and|on)\s/, $j_clause; |
|
| 1460 | 1462 |
my $c = $self->safety_character; |
| 1461 |
- my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/; |
|
| 1462 |
- if ($j_clause =~ $join_re) {
|
|
| 1463 |
- $table1 = $1; |
|
| 1464 |
- $table2 = $2; |
|
| 1463 |
+ my $join_re = qr/(?:^|\s)($c+)\.$c+\s.+\s($c+)\.$c+/; |
|
| 1464 |
+ for my $clause (@j_clauses) {
|
|
| 1465 |
+ if ($clause =~ $join_re) {
|
|
| 1466 |
+ $table1 = $1; |
|
| 1467 |
+ $table2 = $2; |
|
| 1468 |
+ last; |
|
| 1469 |
+ } |
|
| 1465 | 1470 |
} |
| 1466 | 1471 |
} |
| 1467 | 1472 |
croak qq{join clause must have two table name after "on" keyword. } .
|
| ... | ... |
@@ -2163,10 +2168,13 @@ Note that you don't have to specify like '[\w]'. |
| 2163 | 2168 |
=head2 C<separator> |
| 2164 | 2169 |
|
| 2165 | 2170 |
my $separator = $self->separator; |
| 2166 |
- $dbi = $self->separator($separator); |
|
| 2171 |
+ $dbi = $self->separator('-');
|
|
| 2172 |
+ |
|
| 2173 |
+Separator which join table name and column name. |
|
| 2174 |
+This have effect to C<column> and C<mycolumn> method, |
|
| 2175 |
+and C<select> method's column option. |
|
| 2167 | 2176 |
|
| 2168 |
-Separator whichi join table and column. |
|
| 2169 |
-This is used by C<column> and C<mycolumn> method. |
|
| 2177 |
+Default to C<.>. |
|
| 2170 | 2178 |
|
| 2171 | 2179 |
=head2 C<exclude_table> |
| 2172 | 2180 |
|
| ... | ... |
@@ -4033,6 +4033,40 @@ $result = $dbi->select( |
| 4033 | 4033 |
); |
| 4034 | 4034 |
is_deeply($result->all, [{"$table2.$key3" => 4}]);
|
| 4035 | 4035 |
|
| 4036 |
+$dbi = DBIx::Custom->connect; |
|
| 4037 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 4038 |
+eval { $dbi->execute("drop table $table2") };
|
|
| 4039 |
+$dbi->execute($create_table1); |
|
| 4040 |
+$dbi->execute($create_table2); |
|
| 4041 |
+$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
|
|
| 4042 |
+$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
|
|
| 4043 |
+$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
|
|
| 4044 |
+$result = $dbi->select( |
|
| 4045 |
+ table => $table1, |
|
| 4046 |
+ column => [{$table2 => [$key3]}],
|
|
| 4047 |
+ join => [ |
|
| 4048 |
+ "left outer join $table2 on $table1.$key1 = $table2.$key1 and $table2.$key3 > '3'" |
|
| 4049 |
+ ] |
|
| 4050 |
+); |
|
| 4051 |
+is_deeply($result->all, [{"$table2.$key3" => 4}]);
|
|
| 4052 |
+ |
|
| 4053 |
+$dbi = DBIx::Custom->connect; |
|
| 4054 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 4055 |
+eval { $dbi->execute("drop table $table2") };
|
|
| 4056 |
+$dbi->execute($create_table1); |
|
| 4057 |
+$dbi->execute($create_table2); |
|
| 4058 |
+$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
|
|
| 4059 |
+$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 4});
|
|
| 4060 |
+$dbi->insert(table => $table2, param => {$key1 => 1, $key3 => 1});
|
|
| 4061 |
+$result = $dbi->select( |
|
| 4062 |
+ table => $table1, |
|
| 4063 |
+ column => [{$table2 => [$key3]}],
|
|
| 4064 |
+ join => [ |
|
| 4065 |
+ "left outer join $table2 on $table2.$key3 > '3' and $table1.$key1 = $table2.$key1" |
|
| 4066 |
+ ] |
|
| 4067 |
+); |
|
| 4068 |
+is_deeply($result->all, [{"$table2.$key3" => 4}]);
|
|
| 4069 |
+ |
|
| 4036 | 4070 |
test 'columns'; |
| 4037 | 4071 |
$dbi = MyDBI1->connect; |
| 4038 | 4072 |
$model = $dbi->model($table1); |