Showing 3 changed files with 21 additions and 112 deletions
+6 -2
Changes
... ...
@@ -1,7 +1,11 @@
1
-0.1667
1
+0.1670
2
+    - removed EXPERIMETNAL select() column hash option. it's a little complex
3
+
4
+0.1669
2 5
     - renamed update_param to update_param_tag, update_param is DEPRECATED!
3 6
     - renamed insert_param to insert_param_tag, insert_param is DEPRECATED!
4
-    - added EXPERIMENTAL updat_param no_set option.
7
+0.1668
8
+    - added EXPERIMENTAL update_param no_set option.
5 9
     - added EXPERIMENTAL reserved_word_quote attribute.
6 10
 0.1666
7 11
     - removed from cache() and cache_method() document for a while and cache() value
+13 -93
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1669';
3
+our $VERSION = '0.1670';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -867,6 +867,7 @@ sub select {
867 867
     croak qq{"join" must be array reference}
868 868
       unless ref $join eq 'ARRAY';
869 869
     my $relation = delete $args{relation};
870
+    my $param = delete $args{param} || {};
870 871
     
871 872
     # Add relation tables(DEPRECATED!);
872 873
     $self->_add_relation_table($tables, $relation);
... ...
@@ -875,58 +876,14 @@ sub select {
875 876
     my @sql;
876 877
     push @sql, 'select';
877 878
     
879
+    # Column clause
878 880
     if ($columns) {
879
-
880 881
         $columns = [$columns] if ! ref $columns;
881
-        
882
-        if (ref $columns eq 'HASH') {
883
-            # Find tables
884
-            my $main_table;
885
-            my %tables;
886
-            if ($columns->{table}) {
887
-                foreach my $table (@{$columns->{table}}) {
888
-                    if (($table || '') eq $tables->[-1]) {
889
-                        $main_table = $table;
890
-                    }
891
-                    else {
892
-                        $tables{$table} = 1;
893
-                    }
894
-                }
895
-            }
896
-            elsif ($columns->{all}) {
897
-                $main_table = $tables->[-1] || '';
898
-                foreach my $j (@$join) {
899
-                    my $tables = $self->_tables($j);
900
-                    foreach my $table (@$tables) {
901
-                        $tables{$table} = 1;
902
-                    }
903
-                }
904
-                delete $tables{$main_table};
905
-            }
906
-            
907
-            push @sql, $columns->{prepend} if $columns->{prepend};
908
-            
909
-            # Column clause of main table
910
-            if ($main_table) {
911
-                push @sql, $self->model($main_table)->mycolumn;
912
-                push @sql, ',';
913
-            }
914
-            
915
-            # Column cluase of other tables
916
-            foreach my $table (keys %tables) {
917
-                unshift @$tables, $table;
918
-                push @sql, $self->model($table)->column($table);
919
-                push @sql, ',';
920
-            }
921
-            pop @sql if $sql[-1] eq ',';
922
-        }
923
-        else {
924
-            foreach my $column (@$columns) {
925
-                unshift @$tables, @{$self->_tables($column)};
926
-                push @sql, ($column, ',');
927
-            }
928
-            pop @sql if $sql[-1] eq ',';
882
+        foreach my $column (@$columns) {
883
+            unshift @$tables, @{$self->_tables($column)};
884
+            push @sql, ($column, ',');
929 885
         }
886
+        pop @sql if $sql[-1] eq ',';
930 887
     }
931 888
     
932 889
     # "*" is default
... ...
@@ -952,7 +909,8 @@ sub select {
952 909
     
953 910
     # Where
954 911
     my $w = $self->_where($where);
955
-    $where = $w->param;
912
+    $param = keys %$param ? $self->merge_param($param, $w->param)
913
+                         : $w->param;
956 914
     
957 915
     # String where
958 916
     my $swhere = "$w";
... ...
@@ -982,7 +940,7 @@ sub select {
982 940
     # Execute query
983 941
     my $result = $self->execute(
984 942
         $query,
985
-        param  => $where, 
943
+        param  => $param, 
986 944
         table => $tables,
987 945
         %args
988 946
     );
... ...
@@ -1399,6 +1357,9 @@ sub _where {
1399 1357
         $w = $where;
1400 1358
     }
1401 1359
     elsif (ref $where eq 'ARRAY') {
1360
+        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1361
+             "use \$dbi->select(where => \$dbi->where(clause => " .
1362
+             "CLAUSE, param => PARAMETER));";
1402 1363
         $w = $self->where(
1403 1364
             clause => $where->[0],
1404 1365
             param  => $where->[1]
... ...
@@ -2397,47 +2358,6 @@ Default is '*' unless C<column> is specified.
2397 2358
     # Default
2398 2359
     $dbi->select(column => '*');
2399 2360
 
2400
-You can use hash option in C<column>
2401
-
2402
-=over 4
2403
-
2404
-=item all EXPERIMENTAL
2405
-
2406
-Colum clause, contains all columns of joined table. This is true or false value
2407
-
2408
-    $dbi->select(column => {all => 1});
2409
-
2410
-If main table is C<book> and joined table is C<company>,
2411
-This create the following column clause.
2412
-
2413
-    book.author as author
2414
-    book.company_id as company_id
2415
-    company.id as company__id
2416
-    company.name as company__name
2417
-
2418
-Columns of main table is consist of only column name,
2419
-Columns of joined table is consist of table and column name joined C<__>.
2420
-
2421
-Note that this option is failed unless modles is included and
2422
-C<columns> attribute is set.
2423
-
2424
-    # Generally do the following way before using all_column option
2425
-    $dbi->include_model('MyModel')->setup_model;
2426
-
2427
-=item table EXPERIMENTAL
2428
-
2429
-You can also specify table names by C<table> option
2430
-
2431
-    $dbi->select(column => {table => ['book', 'company']});
2432
-
2433
-=item prepend EXPERIMENTAL
2434
-
2435
-You can add before created statement
2436
-
2437
-    $dbi->select(column => {prepend => 'SOME', all => 1});
2438
-
2439
-=back
2440
-
2441 2361
 =item C<where>
2442 2362
 
2443 2363
 Where clause. This is hash reference or L<DBIx::Custom::Where> object,
+2 -17
t/dbix-custom-core-sqlite.t
... ...
@@ -6,6 +6,8 @@ use utf8;
6 6
 use Encode qw/encode_utf8 decode_utf8/;
7 7
 use Data::Dumper;
8 8
 
9
+$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/};
10
+
9 11
 BEGIN {
10 12
     eval { require DBD::SQLite; 1 }
11 13
         or plan skip_all => 'DBD::SQLite required';
... ...
@@ -1932,7 +1934,6 @@ $rows = $dbi->select(
1932 1934
 is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
1933 1935
           'reserved_word_quote');
1934 1936
 
1935
-test 'model join and column attribute and all_column option';
1936 1937
 {
1937 1938
     package MyDBI8;
1938 1939
     
... ...
@@ -1946,22 +1947,6 @@ test 'model join and column attribute and all_column option';
1946 1947
         return $self;
1947 1948
     }
1948 1949
 }
1949
-$dbi = MyDBI8->connect($NEW_ARGS->{0});
1950
-$dbi->execute($CREATE_TABLE->{0});
1951
-$dbi->execute($CREATE_TABLE->{2});
1952
-$dbi->setup_model;
1953
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1954
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1955
-$model = $dbi->model('table1');
1956
-$result = $model->select_at(
1957
-    column => {table => ['table1', 'table2'], prepend => 'table1.key1 as key1_1,'},
1958
-    where => 1
1959
-);
1960
-is_deeply($result->fetch_hash_first,
1961
-          {key1_1 => 1, key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1962
-$result = $model->select(column => {all => 1});
1963
-is_deeply($result->fetch_hash_first,
1964
-          {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
1965 1950
 
1966 1951
 test 'mycolumn';
1967 1952
 $dbi = MyDBI8->connect($NEW_ARGS->{0});