From: miker Date: Wed, 27 Sep 2006 19:49:36 +0000 (+0000) Subject: new, explicit column transform format X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d1f1cf56f46cdb9d2148476b9474da45151cc4bf;p=evergreen%2Fpines.git new, explicit column transform format git-svn-id: svn://svn.open-ils.org/ILS/trunk@6233 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/examples/reporter-sql-builder-test.pl b/Open-ILS/examples/reporter-sql-builder-test.pl index ede5128e43..109201671f 100755 --- a/Open-ILS/examples/reporter-sql-builder-test.pl +++ b/Open-ILS/examples/reporter-sql-builder-test.pl @@ -7,11 +7,11 @@ use OpenILS::Reporter::SQLBuilder; my $report = { select => [ { relation=> 'circ', - column => { month_trunc => ['checkin_time'] }, + column => { transform => month_trunc => colname => 'checkin_time' }, alias => '::PARAM4', }, { relation=> 'circ-checkin_lib-aou', - column => 'shortname', + column => { colname => 'shortname', transform => 'substring', params => [ 1, 4 ] }, alias => 'Library Short Name', }, { relation=> 'circ-circ_staff-au-card-ac', @@ -19,7 +19,7 @@ my $report = { alias => 'User Barcode', }, { relation=> 'circ', - column => { count => 'id' }, + column => { transform => count => colname => 'id' }, alias => '::PARAM3', }, ], @@ -52,26 +52,26 @@ my $report = { condition => { 'in' => '::PARAM1' }, }, { relation => 'circ', - column => { month_trunc => ['checkin_time'] }, + column => { transform => month_trunc => colname => 'checkin_time' }, condition => { 'in' => '::PARAM2' }, }, ], having => [ { relation => 'circ', - column => { count => 'id' }, + column => { transform => count => colname => 'id' }, condition => { '>' => '::PARAM5' }, }, ], order_by => [ { relation=> 'circ', - column => { count => 'id' }, + column => { transform => count => colname => 'id' }, direction => 'descending', }, { relation=> 'circ-checkin_lib-aou', column => 'shortname', }, { relation=> 'circ', - column => { month_trunc => ['checkin_time'] }, + column => { transform => month_trunc => colname => 'checkin_time' }, direction => 'descending' }, { relation=> 'circ-circ_staff-au-card-ac', diff --git a/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm b/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm index d8ce225b8b..12f5355322 100644 --- a/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm +++ b/Open-ILS/src/perlmods/OpenILS/Reporter/SQLBuilder.pm @@ -156,7 +156,7 @@ sub new { $self->{_aggregate} = $col_data->{aggregate}; if (ref($self->{_column})) { - my ($trans) = keys %{ $self->{_column} }; + my $trans = $self->{_column}->{transform} || 'Bare'; my $pkg = "OpenILS::Reporter::SQLBuilder::Column::Transform::$trans"; if (UNIVERSAL::can($pkg => 'toSQL')) { $self->{_transform} = $trans; @@ -174,14 +174,9 @@ sub new { sub name { my $self = shift; if (ref($self->{_column})) { - my ($k) = keys %{$self->{_column}}; - if (ref($self->{_column}->{$k})) { - return $self->resolve_param( $self->{_column}->{$k}->[0] ); - } else { - return $self->resolve_param( $self->{_column}->{$k} ); - } + return $self->{_column}->{colname}; } else { - return $self->resolve_param( $self->{_column} ); + return $self->{_column}; } } @@ -248,8 +243,7 @@ sub toSQL { my ($func) = keys %{ $self->{_column} }; my @params; - @params = @{ $self->{_column}->{$func} } if (ref($self->{_column}->{$func})); - shift @params if (@params); + @params = @{ $self->resolve_param( $self->{_column}->{params} ) } if ($self->{_column}->{params}); my $sql = $func . '("' . $self->{_relation} . '"."' . $self->name . '"'; $sql .= ",'" . join("','", @params) . "'" if (@params); @@ -275,9 +269,9 @@ package OpenILS::Reporter::SQLBuilder::Column::Transform::substring; sub toSQL { my $self = shift; - my ($params) = values %{ $self->{_column} }; - my $start = $$params[1]; - my $len = $$params[2]; + my $params = $self->resolve_param( $self->{_column}->{params} ); + my $start = $$params[0]; + my $len = $$params[1]; return 'SUBSTRING("' . $self->{_relation} . '"."' . $self->name . "\",$start,$len)"; }