| ... | ... |
@@ -1,8 +1,9 @@ |
| 1 | 1 |
0.1643 |
| 2 |
- add table tag |
|
| 3 |
- fix bug : filter can't overwirite undef value. |
|
| 4 |
- add feature to apply_filter(). you can apply end filter. |
|
| 5 |
- add feature to apply_filter(). TABLE__COLUMN is filterded now. |
|
| 2 |
+ add experimental selection option to select() |
|
| 3 |
+ add experimental table tag |
|
| 4 |
+ fix bug : filter can't overwirite undef value. |
|
| 5 |
+ add experimental feature to apply_filter(). you can apply end filter. |
|
| 6 |
+ add experimental feature to apply_filter(). TABLE__COLUMN is filterded now. |
|
| 6 | 7 |
0.1642 |
| 7 | 8 |
removed experimental DBIx::Custom::Table base() method |
| 8 | 9 |
table created by tabled method can call base_$method correponding to base_table's one |
| ... | ... |
@@ -487,7 +487,7 @@ sub register_filter {
|
| 487 | 487 |
sub register_tag { shift->query_builder->register_tag(@_) }
|
| 488 | 488 |
|
| 489 | 489 |
our %VALID_SELECT_ARGS |
| 490 |
- = map { $_ => 1 } qw/table column where append relation filter query/;
|
|
| 490 |
+ = map { $_ => 1 } qw/table column where append relation filter query selection/;
|
|
| 491 | 491 |
|
| 492 | 492 |
sub select {
|
| 493 | 493 |
my ($self, %args) = @_; |
| ... | ... |
@@ -503,33 +503,41 @@ sub select {
|
| 503 | 503 |
my $tables = ref $table eq 'ARRAY' ? $table |
| 504 | 504 |
: defined $table ? [$table] |
| 505 | 505 |
: []; |
| 506 |
- croak qq{"table" option must be specified} unless @$tables;
|
|
| 507 |
- my $columns = $args{column} || [];
|
|
| 508 |
- my $where = $args{where} || {};
|
|
| 509 |
- my $relation = $args{relation};
|
|
| 510 |
- my $append = $args{append};
|
|
| 511 |
- my $filter = $args{filter};
|
|
| 506 |
+ my $columns = $args{column} || [];
|
|
| 507 |
+ my $selection = $args{selection} || '';
|
|
| 508 |
+ my $where = $args{where} || {};
|
|
| 509 |
+ my $relation = $args{relation};
|
|
| 510 |
+ my $append = $args{append};
|
|
| 511 |
+ my $filter = $args{filter};
|
|
| 512 | 512 |
|
| 513 | 513 |
# SQL stack |
| 514 | 514 |
my @sql; |
| 515 | 515 |
|
| 516 | 516 |
push @sql, 'select'; |
| 517 | 517 |
|
| 518 |
- # Column clause |
|
| 519 |
- if (@$columns) {
|
|
| 520 |
- foreach my $column (@$columns) {
|
|
| 521 |
- push @sql, ($column, ','); |
|
| 518 |
+ if ($selection) {
|
|
| 519 |
+ croak qq{Can't contain "where" clause in selection}
|
|
| 520 |
+ if $selection =~ /\swhere\s/; |
|
| 521 |
+ push @sql, $selection; |
|
| 522 |
+ } |
|
| 523 |
+ else {
|
|
| 524 |
+ # Column clause |
|
| 525 |
+ if (@$columns) {
|
|
| 526 |
+ foreach my $column (@$columns) {
|
|
| 527 |
+ push @sql, ($column, ','); |
|
| 528 |
+ } |
|
| 529 |
+ pop @sql if $sql[-1] eq ','; |
|
| 530 |
+ } |
|
| 531 |
+ else { push @sql, '*' }
|
|
| 532 |
+ |
|
| 533 |
+ # Table |
|
| 534 |
+ croak qq{"table" option must be specified} unless @$tables;
|
|
| 535 |
+ push @sql, 'from'; |
|
| 536 |
+ foreach my $table (@$tables) {
|
|
| 537 |
+ push @sql, ($table, ','); |
|
| 522 | 538 |
} |
| 523 | 539 |
pop @sql if $sql[-1] eq ','; |
| 524 | 540 |
} |
| 525 |
- else { push @sql, '*' }
|
|
| 526 |
- |
|
| 527 |
- # Table |
|
| 528 |
- push @sql, 'from'; |
|
| 529 |
- foreach my $table (@$tables) {
|
|
| 530 |
- push @sql, ($table, ','); |
|
| 531 |
- } |
|
| 532 |
- pop @sql if $sql[-1] eq ','; |
|
| 533 | 541 |
|
| 534 | 542 |
# Where |
| 535 | 543 |
my $w; |
| ... | ... |
@@ -1243,7 +1251,8 @@ This is same as L<DBI>'s C<rollback>. |
| 1243 | 1251 |
append => $append, |
| 1244 | 1252 |
relation => \%relation, |
| 1245 | 1253 |
filter => \%filter, |
| 1246 |
- query => 1); |
|
| 1254 |
+ query => 1, |
|
| 1255 |
+ selection => $selection); |
|
| 1247 | 1256 |
|
| 1248 | 1257 |
Execute select statement. |
| 1249 | 1258 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
| ... | ... |
@@ -1254,6 +1263,10 @@ C<append> is a string added at the end of the SQL statement. |
| 1254 | 1263 |
C<filter> is filters when parameter binding is executed. |
| 1255 | 1264 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
| 1256 | 1265 |
default to 0. This is experimental. |
| 1266 |
+C<selection> is string of column name and tables. This is experimental |
|
| 1267 |
+ |
|
| 1268 |
+ selection => 'name, location.name as location_name ' . |
|
| 1269 |
+ 'from company inner join location' |
|
| 1257 | 1270 |
|
| 1258 | 1271 |
First element is a string. it contains tags, |
| 1259 | 1272 |
such as "{= title} or {like author}".
|
| ... | ... |
@@ -1322,7 +1335,7 @@ Method to set and get caches. |
| 1322 | 1335 |
|
| 1323 | 1336 |
The following tags is available. |
| 1324 | 1337 |
|
| 1325 |
-=head2 C<table> |
|
| 1338 |
+=head2 C<(experimental) table> |
|
| 1326 | 1339 |
|
| 1327 | 1340 |
Table tag |
| 1328 | 1341 |
|
| ... | ... |
@@ -1329,3 +1329,9 @@ $result = $dbi->select( |
| 1329 | 1329 |
); |
| 1330 | 1330 |
is($result->fetch_first->[0], 'B'); |
| 1331 | 1331 |
|
| 1332 |
+test 'selection'; |
|
| 1333 |
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
|
| 1334 |
+$dbi->execute($CREATE_TABLE->{0});
|
|
| 1335 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 1336 |
+$result = $dbi->select(selection => '* from table1', where => {key1 => 1});
|
|
| 1337 |
+is_deeply($result->fetch_hash_all, [{key1 => 1, key2 => 2}]);
|