... | ... |
@@ -1,6 +1,7 @@ |
1 | 1 |
0.22 |
2 | 2 |
- added EXPERIMENTAL DBIx::Custom::Result::kv method |
3 | 3 |
- added EXPERIMENTAL DBIx::Custom::Result::flat method |
4 |
+ - added where => {name => [val1, val2, val3]} support |
|
4 | 5 |
0.2111 |
5 | 6 |
- "created_at" option is renamed to "ctime" option. |
6 | 7 |
"created_at" is DEPRECATED! |
... | ... |
@@ -2,8 +2,7 @@ use 5.008007; |
2 | 2 |
package DBIx::Custom; |
3 | 3 |
use Object::Simple -base; |
4 | 4 |
|
5 |
-our $VERSION = '0.2111'; |
|
6 |
-use 5.008001; |
|
5 |
+our $VERSION = '0.22'; |
|
7 | 6 |
|
8 | 7 |
use Carp 'croak'; |
9 | 8 |
use DBI; |
... | ... |
@@ -1678,43 +1677,46 @@ sub _where_clause_and_param { |
1678 | 1677 |
$where = $self->_id_to_param($id, $primary_key, $table) if defined $id; |
1679 | 1678 |
$where_param ||= {}; |
1680 | 1679 |
my $w = {}; |
1681 |
- my $where_clause = ''; |
|
1682 | 1680 |
|
1683 |
- my $obj; |
|
1684 |
- |
|
1685 |
- if (ref $where) { |
|
1686 |
- if (ref $where eq 'HASH') { |
|
1687 |
- my $clause = ['and']; |
|
1688 |
- my $column_join = ''; |
|
1689 |
- for my $column (keys %$where) { |
|
1690 |
- $column_join .= $column; |
|
1691 |
- my $table; |
|
1692 |
- my $c; |
|
1693 |
- if ($column =~ /(?:(.*?)\.)?(.*)/) { |
|
1694 |
- $table = $1; |
|
1695 |
- $c = $2; |
|
1696 |
- } |
|
1697 |
- |
|
1698 |
- my $table_quote; |
|
1699 |
- $table_quote = $self->q($table) if defined $table; |
|
1700 |
- my $column_quote = $self->q($c); |
|
1701 |
- $column_quote = $table_quote . '.' . $column_quote |
|
1702 |
- if defined $table_quote; |
|
1703 |
- push @$clause, "$column_quote = :$column"; |
|
1681 |
+ if (ref $where eq 'HASH') { |
|
1682 |
+ my $clause = []; |
|
1683 |
+ my $column_join = ''; |
|
1684 |
+ for my $column (keys %$where) { |
|
1685 |
+ $column_join .= $column; |
|
1686 |
+ my $table; |
|
1687 |
+ my $c; |
|
1688 |
+ if ($column =~ /(?:(.*?)\.)?(.*)/) { |
|
1689 |
+ $table = $1; |
|
1690 |
+ $c = $2; |
|
1704 | 1691 |
} |
1692 |
+ |
|
1693 |
+ my $table_quote; |
|
1694 |
+ $table_quote = $self->q($table) if defined $table; |
|
1695 |
+ my $column_quote = $self->q($c); |
|
1696 |
+ $column_quote = $table_quote . '.' . $column_quote |
|
1697 |
+ if defined $table_quote; |
|
1698 |
+ push @$clause, "$column_quote = :$column"; |
|
1699 |
+ } |
|
1705 | 1700 |
|
1706 |
- # Check unsafety column |
|
1707 |
- my $safety = $self->{safety_character}; |
|
1708 |
- unless ($column_join =~ /^[$safety\.]+$/) { |
|
1709 |
- for my $column (keys %$where) { |
|
1710 |
- croak qq{"$column" is not safety column name } . _subname |
|
1711 |
- unless $column =~ /^[$safety\.]+$/; |
|
1712 |
- } |
|
1701 |
+ # Check unsafety column |
|
1702 |
+ my $safety = $self->{safety_character}; |
|
1703 |
+ unless ($column_join =~ /^[$safety\.]+$/) { |
|
1704 |
+ for my $column (keys %$where) { |
|
1705 |
+ croak qq{"$column" is not safety column name } . _subname |
|
1706 |
+ unless $column =~ /^[$safety\.]+$/; |
|
1713 | 1707 |
} |
1714 |
- |
|
1715 |
- $obj = $self->where(clause => $clause, param => $where); |
|
1716 | 1708 |
} |
1717 |
- elsif (ref $where eq 'DBIx::Custom::Where') { $obj = $where } |
|
1709 |
+ |
|
1710 |
+ $w->{clause} = @$clause ? "where ( " . join(' and ', @$clause) . " ) " : '' ; |
|
1711 |
+ $w->{param} = $where; |
|
1712 |
+ $w->{param} = keys %$where_param |
|
1713 |
+ ? $self->merge_param($where_param, $where) |
|
1714 |
+ : $where; |
|
1715 |
+ } |
|
1716 |
+ elsif (ref $where) { |
|
1717 |
+ my $obj; |
|
1718 |
+ |
|
1719 |
+ if (ref $where eq 'DBIx::Custom::Where') { $obj = $where } |
|
1718 | 1720 |
elsif (ref $where eq 'ARRAY') { |
1719 | 1721 |
$obj = $self->where(clause => $where->[0], param => $where->[1]); |
1720 | 1722 |
} |
... | ... |
@@ -1725,10 +1727,10 @@ sub _where_clause_and_param { |
1725 | 1727 |
. _subname |
1726 | 1728 |
unless ref $obj eq 'DBIx::Custom::Where'; |
1727 | 1729 |
|
1730 |
+ $w->{clause} = $obj->to_string; |
|
1728 | 1731 |
$w->{param} = keys %$where_param |
1729 | 1732 |
? $self->merge_param($where_param, $obj->param) |
1730 | 1733 |
: $obj->param; |
1731 |
- $w->{clause} = $obj->to_string; |
|
1732 | 1734 |
} |
1733 | 1735 |
elsif ($where) { |
1734 | 1736 |
$w->{clause} = "where $where"; |
... | ... |
@@ -3241,7 +3243,7 @@ The above is same as the followin one. |
3241 | 3243 |
|
3242 | 3244 |
Parameter shown before where clause. |
3243 | 3245 |
|
3244 |
-For example, if you want to contain tag in join clause, |
|
3246 |
+For example, if you want to contain named placeholder in join clause, |
|
3245 | 3247 |
you can pass parameter by C<param> option. |
3246 | 3248 |
|
3247 | 3249 |
join => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . |