| ... | ... |
@@ -1,6 +1,10 @@ |
| 1 | 1 |
0.1733 |
| 2 |
+ - select method where_param option is DEPRECATED! |
|
| 3 |
+ use where => [STRING, PARAM] syntax instead |
|
| 2 | 4 |
- delete method where_param option is DEPRECATED! |
| 5 |
+ use where => [STRING, PARAM] syntax instead |
|
| 3 | 6 |
- update method where_param option is DEPRECATED! |
| 7 |
+ use where => [STRING, PARAM] syntax instead |
|
| 4 | 8 |
- update method param option is DEPRECATED! |
| 5 | 9 |
- insert method param option is DEPRECATED! |
| 6 | 10 |
- removed argument checking logic because in database performance is more |
| ... | ... |
@@ -793,38 +793,28 @@ sub select {
|
| 793 | 793 |
: defined $table ? [$table] |
| 794 | 794 |
: []; |
| 795 | 795 |
$opt{table} = $tables;
|
| 796 |
- my $columns = $opt{column};
|
|
| 797 | 796 |
my $where = $opt{where} || {};
|
| 798 |
- my $join = $opt{join} || [];
|
|
| 799 |
- croak qq{"join" must be array reference } . _subname
|
|
| 800 |
- unless ref $join eq 'ARRAY'; |
|
| 801 |
- my $relation = $opt{relation};
|
|
| 802 |
- warn "select() relation option is DEPRECATED!" |
|
| 803 |
- if $relation; |
|
| 804 | 797 |
my $param = $opt{param} || {}; # DEPRECATED!
|
| 805 | 798 |
warn "select() param option is DEPRECATED!" |
| 806 | 799 |
if keys %$param; |
| 807 | 800 |
my $where_param = $opt{where_param} || $param || {};
|
| 808 |
- my $id = $opt{id};
|
|
| 809 |
- my $primary_key = $opt{primary_key};
|
|
| 810 |
- croak "update method primary_key option " . |
|
| 811 |
- "must be specified when id is specified " . _subname |
|
| 812 |
- if defined $id && !defined $primary_key; |
|
| 813 |
- $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
|
| 814 |
- my $prefix = $opt{prefix};
|
|
| 815 | 801 |
|
| 816 | 802 |
# Add relation tables(DEPRECATED!); |
| 817 |
- $self->_add_relation_table($tables, $relation); |
|
| 803 |
+ if ($opt{relation}) {
|
|
| 804 |
+ warn "select() relation option is DEPRECATED!"; |
|
| 805 |
+ $self->_add_relation_table($tables, $opt{relation});
|
|
| 806 |
+ } |
|
| 818 | 807 |
|
| 819 | 808 |
# Select statement |
| 820 | 809 |
my $sql = 'select '; |
| 821 | 810 |
|
| 822 | 811 |
# Prefix |
| 823 |
- $sql .= "$prefix " if defined $prefix; |
|
| 812 |
+ $sql .= "$opt{prefix} " if defined $opt{prefix};
|
|
| 824 | 813 |
|
| 825 | 814 |
# Column clause |
| 826 |
- if ($columns) {
|
|
| 827 |
- $columns = [$columns] unless ref $columns eq 'ARRAY'; |
|
| 815 |
+ if (defined $opt{column}) {
|
|
| 816 |
+ my $columns |
|
| 817 |
+ = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
|
|
| 828 | 818 |
foreach my $column (@$columns) {
|
| 829 | 819 |
if (ref $column eq 'HASH') {
|
| 830 | 820 |
$column = $self->column(%$column) if ref $column eq 'HASH'; |
| ... | ... |
@@ -846,7 +836,7 @@ sub select {
|
| 846 | 836 |
|
| 847 | 837 |
# Table |
| 848 | 838 |
$sql .= 'from '; |
| 849 |
- if ($relation) {
|
|
| 839 |
+ if ($opt{relation}) {
|
|
| 850 | 840 |
my $found = {};
|
| 851 | 841 |
foreach my $table (@$tables) {
|
| 852 | 842 |
$sql .= $self->_q($table) . ', ' unless $found->{$table};
|
| ... | ... |
@@ -867,8 +857,8 @@ sub select {
|
| 867 | 857 |
|
| 868 | 858 |
# Where |
| 869 | 859 |
my $where_clause = ''; |
| 870 |
- $where = $self->_id_to_param($id, $primary_key, $tables->[-1]) |
|
| 871 |
- if defined $id; |
|
| 860 |
+ $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $tables->[-1])
|
|
| 861 |
+ if defined $opt{id};
|
|
| 872 | 862 |
if (ref $where eq 'ARRAY' && !ref $where->[0]) {
|
| 873 | 863 |
$where_clause = "where " . $where->[0]; |
| 874 | 864 |
$where_param = $where->[1]; |
| ... | ... |
@@ -888,14 +878,14 @@ sub select {
|
| 888 | 878 |
unshift @$tables, @{$self->_search_tables($where_clause)};
|
| 889 | 879 |
|
| 890 | 880 |
# Push join |
| 891 |
- $self->_push_join(\$sql, $join, $tables); |
|
| 881 |
+ $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
|
|
| 892 | 882 |
|
| 893 | 883 |
# Add where clause |
| 894 | 884 |
$sql .= "$where_clause "; |
| 895 | 885 |
|
| 896 | 886 |
# Relation(DEPRECATED!); |
| 897 |
- $self->_push_relation(\$sql, $tables, $relation, $where_clause eq '' ? 1 : 0) |
|
| 898 |
- if $relation; |
|
| 887 |
+ $self->_push_relation(\$sql, $tables, $opt{relation}, $where_clause eq '' ? 1 : 0)
|
|
| 888 |
+ if $opt{relation};
|
|
| 899 | 889 |
|
| 900 | 890 |
# Execute query |
| 901 | 891 |
my $result = $self->execute($sql, $where_param, %opt); |
| ... | ... |
@@ -1380,6 +1370,8 @@ sub _option {
|
| 1380 | 1370 |
sub _push_join {
|
| 1381 | 1371 |
my ($self, $sql, $join, $join_tables) = @_; |
| 1382 | 1372 |
|
| 1373 |
+ $join ||= []; |
|
| 1374 |
+ |
|
| 1383 | 1375 |
# No join |
| 1384 | 1376 |
return unless @$join; |
| 1385 | 1377 |
|
| ... | ... |
@@ -3423,6 +3415,7 @@ L<DBIx::Custom> |
| 3423 | 3415 |
update_param_tag # will be removed at 2017/1/1 |
| 3424 | 3416 |
|
| 3425 | 3417 |
# Options |
| 3418 |
+ select method where_param option # will be removed 2017/1/1 |
|
| 3426 | 3419 |
delete method where_param option # will be removed 2017/1/1 |
| 3427 | 3420 |
update method where_param option # will be removed 2017/1/1 |
| 3428 | 3421 |
insert method param option # will be removed at 2017/1/1 |
| ... | ... |
@@ -2175,6 +2175,20 @@ $rows = $dbi->select( |
| 2175 | 2175 |
)->all; |
| 2176 | 2176 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
|
| 2177 | 2177 |
|
| 2178 |
+$dbi = DBIx::Custom->connect; |
|
| 2179 |
+eval { $dbi->execute("drop table $table1") };
|
|
| 2180 |
+$dbi->execute($create_table1); |
|
| 2181 |
+$dbi->insert(table => $table1, param => {$key1 => 1, $key2 => 2});
|
|
| 2182 |
+$dbi->insert(table => $table1, param => {$key1 => 2, $key2 => 3});
|
|
| 2183 |
+$rows = $dbi->select( |
|
| 2184 |
+ table => $table1, |
|
| 2185 |
+ where => [ |
|
| 2186 |
+ "$key1 = :$key1 and $key2 = :$key2", |
|
| 2187 |
+ {$key1 => 1, $key2 => 2}
|
|
| 2188 |
+ ] |
|
| 2189 |
+)->all; |
|
| 2190 |
+is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
|
|
| 2191 |
+ |
|
| 2178 | 2192 |
test 'delete() string where'; |
| 2179 | 2193 |
$dbi = DBIx::Custom->connect; |
| 2180 | 2194 |
eval { $dbi->execute("drop table $table1") };
|
| ... | ... |
@@ -4007,16 +4021,6 @@ $rows = $dbi->select( |
| 4007 | 4021 |
)->all; |
| 4008 | 4022 |
is_deeply($rows, [{$key1 => 1, $key2 => 2}]);
|
| 4009 | 4023 |
|
| 4010 |
-eval {
|
|
| 4011 |
- $rows = $dbi->select( |
|
| 4012 |
- table => $table1, |
|
| 4013 |
- column => "$table1.$key1 as ${table1}_$key1, $table2.$key1 as ${table2}_$key1, $key2, $key3",
|
|
| 4014 |
- where => {"$table1.$key2" => 2},
|
|
| 4015 |
- join => {"$table1.$key1" => "$table2.$key1"}
|
|
| 4016 |
- ); |
|
| 4017 |
-}; |
|
| 4018 |
-like ($@, qr/array/); |
|
| 4019 |
- |
|
| 4020 | 4024 |
$rows = $dbi->select( |
| 4021 | 4025 |
table => $table1, |
| 4022 | 4026 |
where => {$key1 => 1},
|