| ... | ... |
@@ -1,4 +1,6 @@ |
| 1 | 1 |
0.1691 |
| 2 |
+ - EXPERIMTANL column method think about separator |
|
| 3 |
+ - removed EXPERIMENTAL col method. |
|
| 2 | 4 |
- added EXPERIMENTAL separater method |
| 3 | 5 |
- added EXPERIMENTAL select prefix option. |
| 4 | 6 |
- fixed bug that data_source DEPRECATED warnings pirnt STDERR |
| ... | ... |
@@ -168,30 +168,20 @@ sub assign_param {
|
| 168 | 168 |
return $tag; |
| 169 | 169 |
} |
| 170 | 170 |
|
| 171 |
-sub col {
|
|
| 172 |
- my ($self, $table, $columns) = @_; |
|
| 173 |
- |
|
| 174 |
- # Reserved word quote |
|
| 175 |
- my $q = $self->reserved_word_quote; |
|
| 176 |
- |
|
| 177 |
- # Column clause |
|
| 178 |
- my @column; |
|
| 179 |
- $columns ||= []; |
|
| 180 |
- push @column, "$q$table$q.$q$_$q as $q${table}.$_$q" for @$columns;
|
|
| 181 |
- |
|
| 182 |
- return join (', ', @column);
|
|
| 183 |
-} |
|
| 184 |
- |
|
| 185 | 171 |
sub column {
|
| 186 | 172 |
my ($self, $table, $columns) = @_; |
| 187 | 173 |
|
| 188 | 174 |
# Reserved word quote |
| 189 | 175 |
my $q = $self->reserved_word_quote; |
| 190 | 176 |
|
| 177 |
+ # Separator |
|
| 178 |
+ my $separator = $self->separator; |
|
| 179 |
+ |
|
| 191 | 180 |
# Column clause |
| 192 | 181 |
my @column; |
| 193 | 182 |
$columns ||= []; |
| 194 |
- push @column, "$q$table$q.$q$_$q as $q${table}__$_$q" for @$columns;
|
|
| 183 |
+ push @column, "$q$table$q.$q$_$q as $q${table}${separator}$_$q"
|
|
| 184 |
+ for @$columns; |
|
| 195 | 185 |
|
| 196 | 186 |
return join (', ', @column);
|
| 197 | 187 |
} |
| ... | ... |
@@ -911,7 +901,7 @@ sub select {
|
| 911 | 901 |
$columns = [$columns] unless ref $columns eq 'ARRAY'; |
| 912 | 902 |
foreach my $column (@$columns) {
|
| 913 | 903 |
if (ref $column eq 'HASH') {
|
| 914 |
- $column = $self->col(%$column) if ref $column eq 'HASH'; |
|
| 904 |
+ $column = $self->column(%$column) if ref $column eq 'HASH'; |
|
| 915 | 905 |
} |
| 916 | 906 |
elsif (ref $column eq 'ARRAY') {
|
| 917 | 907 |
croak "Format must be [COLUMN, as => ALIAS] " . _subname |
| ... | ... |
@@ -82,23 +82,6 @@ sub column {
|
| 82 | 82 |
return $self->dbi->column($table, $columns); |
| 83 | 83 |
} |
| 84 | 84 |
|
| 85 |
-sub col {
|
|
| 86 |
- my ($self, $table, $columns) = @_; |
|
| 87 |
- |
|
| 88 |
- $self->{_table_alias} ||= {};
|
|
| 89 |
- my $dist; |
|
| 90 |
- $dist = $self->dbi->{_table_alias}{$table}
|
|
| 91 |
- ? $self->dbi->{_table_alias}{$table}
|
|
| 92 |
- : $table; |
|
| 93 |
- |
|
| 94 |
- $self->dbi->{_model_from} ||= {};
|
|
| 95 |
- my $model = $self->dbi->{_model_from}->{$dist};
|
|
| 96 |
- |
|
| 97 |
- $columns ||= $self->model($model)->columns; |
|
| 98 |
- |
|
| 99 |
- return $self->dbi->col($table, $columns); |
|
| 100 |
-} |
|
| 101 |
- |
|
| 102 | 85 |
sub DESTROY { }
|
| 103 | 86 |
|
| 104 | 87 |
sub method {
|
| ... | ... |
@@ -1868,6 +1868,7 @@ test 'mycolumn and column'; |
| 1868 | 1868 |
$dbi = MyDBI7->connect($NEW_ARGS->{0});
|
| 1869 | 1869 |
$dbi->execute($CREATE_TABLE->{0});
|
| 1870 | 1870 |
$dbi->execute($CREATE_TABLE->{2});
|
| 1871 |
+$dbi->separator('__');
|
|
| 1871 | 1872 |
$dbi->setup_model; |
| 1872 | 1873 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 1873 | 1874 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
|
| ... | ... |
@@ -2112,7 +2113,7 @@ $result = $model->select_at( |
| 2112 | 2113 |
] |
| 2113 | 2114 |
); |
| 2114 | 2115 |
is_deeply($result->one, |
| 2115 |
- {key1 => 1, key2 => 2, table2__key1 => 1, table2__key3 => 3});
|
|
| 2116 |
+ {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
|
|
| 2116 | 2117 |
|
| 2117 | 2118 |
$result = $model->select_at( |
| 2118 | 2119 |
column => [ |
| ... | ... |
@@ -2121,7 +2122,7 @@ $result = $model->select_at( |
| 2121 | 2122 |
] |
| 2122 | 2123 |
); |
| 2123 | 2124 |
is_deeply($result->one, |
| 2124 |
- {key1 => 1, table2__key1 => 1});
|
|
| 2125 |
+ {key1 => 1, 'table2.key1' => 1});
|
|
| 2125 | 2126 |
$result = $model->select_at( |
| 2126 | 2127 |
column => [ |
| 2127 | 2128 |
$model->mycolumn(['key1']), |
| ... | ... |
@@ -2184,7 +2185,7 @@ $result = $model->select( |
| 2184 | 2185 |
where => {'table2_alias.key3' => 2}
|
| 2185 | 2186 |
); |
| 2186 | 2187 |
is_deeply($result->one, |
| 2187 |
- {table2_alias__key1 => 1, table2_alias__key3 => 48});
|
|
| 2188 |
+ {'table2_alias.key1' => 1, 'table2_alias.key3' => 48});
|
|
| 2188 | 2189 |
|
| 2189 | 2190 |
test 'type() option'; |
| 2190 | 2191 |
$dbi = DBIx::Custom->connect( |
| ... | ... |
@@ -2241,7 +2242,7 @@ $result = $model->select( |
| 2241 | 2242 |
where => {'table1.key1' => 1}
|
| 2242 | 2243 |
); |
| 2243 | 2244 |
is_deeply($result->one, |
| 2244 |
- {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
|
|
| 2245 |
+ {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
|
|
| 2245 | 2246 |
is_deeply($model2->select->one, {key1 => 1, key3 => 3});
|
| 2246 | 2247 |
|
| 2247 | 2248 |
test 'model method'; |
| ... | ... |
@@ -2557,7 +2558,7 @@ is($row->{key1}, 1);
|
| 2557 | 2558 |
is($row->{key2}, 2);
|
| 2558 | 2559 |
is($row->{key3}, 3);
|
| 2559 | 2560 |
|
| 2560 |
-test 'col'; |
|
| 2561 |
+test 'column separator is default .'; |
|
| 2561 | 2562 |
$dbi = MyDBI7->connect($NEW_ARGS->{0});
|
| 2562 | 2563 |
$dbi->execute($CREATE_TABLE->{0});
|
| 2563 | 2564 |
$dbi->execute($CREATE_TABLE->{2});
|
| ... | ... |
@@ -2566,14 +2567,14 @@ $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2566 | 2567 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
|
| 2567 | 2568 |
$model = $dbi->model('table1');
|
| 2568 | 2569 |
$result = $model->select( |
| 2569 |
- column => [$model->col('table2')],
|
|
| 2570 |
+ column => [$model->column('table2')],
|
|
| 2570 | 2571 |
where => {'table1.key1' => 1}
|
| 2571 | 2572 |
); |
| 2572 | 2573 |
is_deeply($result->one, |
| 2573 | 2574 |
{'table2.key1' => 1, 'table2.key3' => 3});
|
| 2574 | 2575 |
|
| 2575 | 2576 |
$result = $model->select( |
| 2576 |
- column => [$model->col('table2' => [qw/key1 key3/])],
|
|
| 2577 |
+ column => [$model->column('table2' => [qw/key1 key3/])],
|
|
| 2577 | 2578 |
where => {'table1.key1' => 1}
|
| 2578 | 2579 |
); |
| 2579 | 2580 |
is_deeply($result->one, |
| ... | ... |
@@ -2754,6 +2755,20 @@ is_deeply($result->one, |
| 2754 | 2755 |
{key1 => 2, key2 => 2, 'table2.key1' => 3, 'table2.key3' => 9});
|
| 2755 | 2756 |
is_deeply($model2->select->one, {key1 => 3, key3 => 9});
|
| 2756 | 2757 |
|
| 2758 |
+$dbi->separator('__');
|
|
| 2759 |
+$model = $dbi->model('table1');
|
|
| 2760 |
+$result = $model->select( |
|
| 2761 |
+ column => [ |
|
| 2762 |
+ $model->mycolumn, |
|
| 2763 |
+ {table2 => [qw/key1 key3/]}
|
|
| 2764 |
+ ], |
|
| 2765 |
+ where => {'table1.key1' => 1}
|
|
| 2766 |
+); |
|
| 2767 |
+is_deeply($result->one, |
|
| 2768 |
+ {key1 => 2, key2 => 2, 'table2__key1' => 3, 'table2__key3' => 9});
|
|
| 2769 |
+is_deeply($model2->select->one, {key1 => 3, key3 => 9});
|
|
| 2770 |
+ |
|
| 2771 |
+ |
|
| 2757 | 2772 |
test 'filter_off'; |
| 2758 | 2773 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| 2759 | 2774 |
$dbi->execute($CREATE_TABLE->{0});
|