[svn:p5ee] r8083 - p5ee/trunk/App-Repository/bin

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Fri Nov 17 20:30:26 2006
New Revision: 8083

Modified:
   p5ee/trunk/App-Repository/bin/dbget

Log:
support --totals and --subtotal_columns options

Modified: p5ee/trunk/App-Repository/bin/dbget
==============================================================================
--- p5ee/trunk/App-Repository/bin/dbget	(original)
+++ p5ee/trunk/App-Repository/bin/dbget	Fri Nov 17 20:30:26 2006
@@ -3,7 +3,7 @@
 use Date::Format;
 
 use App::Options (
-    options => [ qw(dbhost dbname dbuser dbpass repository table params columns headings compact verbose) ],
+    options => [ qw(dbhost dbname dbuser dbpass repository table params columns headings compact subtotal_columns totals verbose) ],
     option => {
         repository => {
             default => "default",
@@ -26,6 +26,12 @@
         compact => {
             description => "Trim titles to make compact table",
         },
+        subtotal_columns => {
+            description => "Print sub-totals at the end",
+        },
+        totals => {
+            description => "Print totals at the end",
+        },
         verbose => {
             default => 1,
             description => "Verbose level",
@@ -52,7 +58,21 @@
     my $params   = { split(/[=>\|]+/, $App::options{params}) };
     my $headings = $App::options{headings} ? [ split(/,/, $App::options{headings}) ] : [];
     my $verbose  = $App::options{verbose};
-    my $rows     = $db->get_rows($table, $params, $columns);
+    my $rows     = $db->get_rows($table, $params, $columns, {extend_columns => 1});
+    my ($subtotal_rows, $total_rows);
+    if ($App::options{subtotal_columns}) {
+        my $subtotal_columns = [ split(/,/, $App::options{subtotal_columns}) ];
+        $subtotal_rows = $db->summarize_rows($table, $rows, $columns, $subtotal_columns);
+    }
+    if ($App::options{totals}) {
+        $total_rows = $db->summarize_rows($table, $rows, $columns);
+    }
+    if ($subtotal_rows) {
+        push(@$rows, @$subtotal_rows);
+    }
+    if ($total_rows) {
+        push(@$rows, @$total_rows);
+    }
     my $formats  = [];
     &print_table($rows, $columns, $formats, { compact => $App::options{compact}, headings => $headings });
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.