Showing 3 changed files with 32 additions and 41 deletions
+2
Changes
... ...
@@ -1,4 +1,6 @@
1 1
 0.1733
2
+    - select method join option can receive string.
3
+    - removed DEPRECATED status of select param option
2 4
     - select method where_param option is DEPRECATED!
3 5
       use where => [STRING, PARAM] syntax instead
4 6
     - delete method where_param option is DEPRECATED!
+20 -41
lib/DBIx/Custom.pm
... ...
@@ -788,16 +788,11 @@ sub select {
788 788
     my ($self, %opt) = @_;
789 789
 
790 790
     # Options
791
-    my $table = $opt{table};
792
-    my $tables = ref $table eq 'ARRAY' ? $table
793
-               : defined $table ? [$table]
791
+    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
792
+               : defined $opt{table} ? [$opt{table}]
794 793
                : [];
795 794
     $opt{table} = $tables;
796
-    my $where     = $opt{where} || {};
797
-    my $param = $opt{param} || {}; # DEPRECATED!
798
-    warn "select() param option is DEPRECATED!"
799
-      if keys %$param;
800
-    my $where_param = $opt{where_param} || $param || {};
795
+    my $where_param = $opt{where_param} || delete $opt{param} || {};
801 796
     
802 797
     # Add relation tables(DEPRECATED!);
803 798
     if ($opt{relation}) {
... ...
@@ -811,7 +806,7 @@ sub select {
811 806
     # Prefix
812 807
     $sql .= "$opt{prefix} " if defined $opt{prefix};
813 808
     
814
-    # Column clause
809
+    # Column
815 810
     if (defined $opt{column}) {
816 811
         my $columns
817 812
           = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
... ...
@@ -848,7 +843,7 @@ sub select {
848 843
         $sql .= $self->_q($main_table) . ' ';
849 844
     }
850 845
     $sql =~ s/, $/ /;
851
-    croak "Not found table name " . _subname
846
+    croak "select method table option must be specified " . _subname
852 847
       unless $tables->[-1];
853 848
 
854 849
     # Add tables in parameter
... ...
@@ -856,39 +851,26 @@ sub select {
856 851
             @{$self->_search_tables(join(' ', keys %$where_param) || '')};
857 852
     
858 853
     # Where
859
-    my $where_clause = '';
860
-    $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $tables->[-1])
861
-      if defined $opt{id};
862
-    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
863
-        $where_clause = "where " . $where->[0];
864
-        $where_param = $where->[1];
865
-    }
866
-    elsif (ref $where) {
867
-        $where = $self->_where_to_obj($where);
868
-        $where_param = keys %$where_param
869
-                     ? $self->merge_param($where_param, $where->param)
870
-                     : $where->param;
871
-        
872
-        # String where
873
-        $where_clause = $where->to_string;
874
-    }
875
-    elsif ($where) { $where_clause = "where $where" }
854
+    my $where = defined $opt{id}
855
+              ? $self->_id_to_param($opt{id}, $opt{primary_key}, $tables->[-1])
856
+              : $opt{where};
857
+    my $w = $self->_where_clause_and_param($where, $where_param);
876 858
     
877 859
     # Add table names in where clause
878
-    unshift @$tables, @{$self->_search_tables($where_clause)};
860
+    unshift @$tables, @{$self->_search_tables($w->{clause})};
879 861
     
880
-    # Push join
862
+    # Join statement
881 863
     $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
882 864
     
883 865
     # Add where clause
884
-    $sql .= "$where_clause ";
866
+    $sql .= "$w->{clause} ";
885 867
     
886 868
     # Relation(DEPRECATED!);
887
-    $self->_push_relation(\$sql, $tables, $opt{relation}, $where_clause eq '' ? 1 : 0)
869
+    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
888 870
       if $opt{relation};
889 871
     
890 872
     # Execute query
891
-    my $result = $self->execute($sql, $where_param, %opt);
873
+    my $result = $self->execute($sql, $w->{param}, %opt);
892 874
     
893 875
     return $result;
894 876
 }
... ...
@@ -1370,7 +1352,7 @@ sub _option {
1370 1352
 sub _push_join {
1371 1353
     my ($self, $sql, $join, $join_tables) = @_;
1372 1354
     
1373
-    $join ||= [];
1355
+    $join = [$join] unless ref $join eq 'ARRAY';
1374 1356
     
1375 1357
     # No join
1376 1358
     return unless @$join;
... ...
@@ -1435,9 +1417,7 @@ sub _push_join {
1435 1417
       keys %$need_tables;
1436 1418
     
1437 1419
     # Add join clause
1438
-    for my $need_table (@need_tables) {
1439
-        $$sql .= $tree->{$need_table}{join} . ' ';
1440
-    }
1420
+    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
1441 1421
 }
1442 1422
 
1443 1423
 sub _quote {
... ...
@@ -1700,7 +1680,7 @@ sub apply_filter {
1700 1680
 sub select_at {
1701 1681
     my ($self, %opt) = @_;
1702 1682
 
1703
-    warn "select_at is DEPRECATED! use update and id option instead";
1683
+    warn "select_at is DEPRECATED! use select method id option instead";
1704 1684
 
1705 1685
     # Options
1706 1686
     my $primary_keys = delete $opt{primary_key};
... ...
@@ -1723,7 +1703,7 @@ sub select_at {
1723 1703
 sub delete_at {
1724 1704
     my ($self, %opt) = @_;
1725 1705
 
1726
-    warn "delete_at is DEPRECATED! use update and id option instead";
1706
+    warn "delete_at is DEPRECATED! use delete method id option instead";
1727 1707
     
1728 1708
     # Options
1729 1709
     my $primary_keys = delete $opt{primary_key};
... ...
@@ -1740,7 +1720,7 @@ sub delete_at {
1740 1720
 sub update_at {
1741 1721
     my $self = shift;
1742 1722
 
1743
-    warn "update_at is DEPRECATED! use update and id option instead";
1723
+    warn "update_at is DEPRECATED! use update method id option instead";
1744 1724
     
1745 1725
     # Options
1746 1726
     my $param;
... ...
@@ -1762,7 +1742,7 @@ sub update_at {
1762 1742
 sub insert_at {
1763 1743
     my $self = shift;
1764 1744
     
1765
-    warn "insert_at is DEPRECATED! use insert and id option instead";
1745
+    warn "insert_at is DEPRECATED! use insert method id option instead";
1766 1746
     
1767 1747
     # Options
1768 1748
     my $param;
... ...
@@ -3422,7 +3402,6 @@ L<DBIx::Custom>
3422 3402
     insert method param option # will be removed at 2017/1/1
3423 3403
     insert method id option # will be removed at 2017/1/1
3424 3404
     select method relation option # will be removed at 2017/1/1
3425
-    select method param option # will be removed at 2017/1/1
3426 3405
     select method column option [COLUMN, as => ALIAS] format
3427 3406
       # will be removed at 2017/1/1
3428 3407
     execute method's sqlfilter option # will be removed at 2017/1/1
+10
t/common.t
... ...
@@ -2148,6 +2148,16 @@ $rows = $dbi->select(
2148 2148
 )->all;
2149 2149
 is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2150 2150
 
2151
+$rows = $dbi->select(
2152
+    table => $table1,
2153
+    column => "$table1.$key1 as ${table1}_$key1, $key2, $key3",
2154
+    where   => {"$table1.$key2" => 3},
2155
+    join  => "inner join (select * from $table2 where {= $table2.$key3})" . 
2156
+             " $table2 on $table1.$key1 = $table2.$key1",
2157
+    param => {"$table2.$key3" => 5}
2158
+)->all;
2159
+is_deeply($rows, [{"${table1}_$key1" => 2, $key2 => 3, $key3 => 5}]);
2160
+
2151 2161
 test 'select() string where';
2152 2162
 $dbi = DBIx::Custom->connect;
2153 2163
 eval { $dbi->execute("drop table $table1") };