- select() column option can receive array referenc...
...e in array.
| ... | ... |
@@ -1,4 +1,6 @@ |
| 1 | 1 |
0.1686 |
| 2 |
+ - select() column option can receive array reference in array. |
|
| 3 |
+ This is EXPERIMENTAL |
|
| 2 | 4 |
- select() EXPERIMETNAL column option hash format |
| 3 | 5 |
return table.column, not table__column |
| 4 | 6 |
- added EXPERIMENTAL col method. |
| ... | ... |
@@ -873,11 +873,21 @@ sub select {
|
| 873 | 873 |
my @sql; |
| 874 | 874 |
push @sql, 'select'; |
| 875 | 875 |
|
| 876 |
+ # Reserved word quote |
|
| 877 |
+ my $q = $self->reserved_word_quote; |
|
| 878 |
+ |
|
| 876 | 879 |
# Column clause |
| 877 | 880 |
if ($columns) {
|
| 878 | 881 |
$columns = [$columns] unless ref $columns eq 'ARRAY'; |
| 879 | 882 |
foreach my $column (@$columns) {
|
| 880 |
- $column = $self->col(%$column) if ref $column eq 'HASH'; |
|
| 883 |
+ if (ref $column eq 'HASH') {
|
|
| 884 |
+ $column = $self->col(%$column) if ref $column eq 'HASH'; |
|
| 885 |
+ } |
|
| 886 |
+ elsif (ref $column eq 'ARRAY') {
|
|
| 887 |
+ croak "Format must be [COLUMN, as => ALIAS] " . _subname |
|
| 888 |
+ unless @$column == 3 && $column->[1] eq 'as'; |
|
| 889 |
+ $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
|
|
| 890 |
+ } |
|
| 881 | 891 |
unshift @$tables, @{$self->_search_tables($column)};
|
| 882 | 892 |
push @sql, ($column, ','); |
| 883 | 893 |
} |
| ... | ... |
@@ -887,7 +897,6 @@ sub select {
|
| 887 | 897 |
|
| 888 | 898 |
# Table |
| 889 | 899 |
push @sql, 'from'; |
| 890 |
- my $q = $self->reserved_word_quote; |
|
| 891 | 900 |
if ($relation) {
|
| 892 | 901 |
my $found = {};
|
| 893 | 902 |
foreach my $table (@$tables) {
|
| ... | ... |
@@ -1635,8 +1644,7 @@ L<DBIx::Custom> is L<DBI> wrapper module. |
| 1635 | 1644 |
There are many basic methods to execute various queries. |
| 1636 | 1645 |
C<insert()>, C<update()>, C<update_all()>,C<delete()>, |
| 1637 | 1646 |
C<delete_all()>, C<select()>, |
| 1638 |
-C<insert_at()>, C<update_at()>, |
|
| 1639 |
-C<delete_at()>, C<select_at()>, C<execute()> |
|
| 1647 |
+C<execute()> |
|
| 1640 | 1648 |
|
| 1641 | 1649 |
=item * |
| 1642 | 1650 |
|
| ... | ... |
@@ -2388,13 +2396,23 @@ You can specify hash reference. This is EXPERIMENTAL. |
| 2388 | 2396 |
{book => [qw/author title/]},
|
| 2389 | 2397 |
{person => [qw/name age/]}
|
| 2390 | 2398 |
]); |
| 2391 |
- |
|
| 2392 |
-This is expanded to the following one by C<column> method automatically. |
|
| 2393 | 2399 |
|
| 2394 |
- book.author as book__author, |
|
| 2395 |
- book.title as book__title, |
|
| 2396 |
- person.name as person__name, |
|
| 2397 |
- person.age as person__age |
|
| 2400 |
+This is expanded to the following one by C<col> method automatically. |
|
| 2401 |
+ |
|
| 2402 |
+ book.author as "book.author", |
|
| 2403 |
+ book.title as "book.title", |
|
| 2404 |
+ person.name as "person.name", |
|
| 2405 |
+ person.age as "person.age" |
|
| 2406 |
+ |
|
| 2407 |
+You can specify array reference in array refernce. |
|
| 2408 |
+ |
|
| 2409 |
+ $dbi->select(column => [ |
|
| 2410 |
+ ['date(book.register_datetime)', as => 'book.register_date'] |
|
| 2411 |
+ ]); |
|
| 2412 |
+ |
|
| 2413 |
+These is joined and quoted. |
|
| 2414 |
+ |
|
| 2415 |
+ date(book.register_datetime) as "book.register_date" |
|
| 2398 | 2416 |
|
| 2399 | 2417 |
=item C<where> |
| 2400 | 2418 |
|
| ... | ... |
@@ -2125,6 +2125,24 @@ $result = $model->select_at( |
| 2125 | 2125 |
is_deeply($result->one, |
| 2126 | 2126 |
{key1 => 1, 'table2.key1' => 1});
|
| 2127 | 2127 |
|
| 2128 |
+$result = $model->select_at( |
|
| 2129 |
+ column => [ |
|
| 2130 |
+ $model->mycolumn(['key1']), |
|
| 2131 |
+ ['table2.key1', as => 'table2.key1'] |
|
| 2132 |
+ ] |
|
| 2133 |
+); |
|
| 2134 |
+is_deeply($result->one, |
|
| 2135 |
+ {key1 => 1, 'table2.key1' => 1});
|
|
| 2136 |
+ |
|
| 2137 |
+eval{
|
|
| 2138 |
+ $result = $model->select_at( |
|
| 2139 |
+ column => [ |
|
| 2140 |
+ ['table2.key1', asaaaa => 'table2.key1'] |
|
| 2141 |
+ ] |
|
| 2142 |
+ ); |
|
| 2143 |
+}; |
|
| 2144 |
+like($@, qr/COLUMN/); |
|
| 2145 |
+ |
|
| 2128 | 2146 |
test 'dbi method from model'; |
| 2129 | 2147 |
{
|
| 2130 | 2148 |
package MyDBI9; |