Author: spadkins
Date: Sun Apr 20 18:13:10 2008
New Revision: 11124

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

Log:
updated to support cache control

Modified: p5ee/trunk/App-Repository/bin/dbget
==============================================================================
--- p5ee/trunk/App-Repository/bin/dbget (original)
+++ p5ee/trunk/App-Repository/bin/dbget Sun Apr 20 18:13:10 2008
@@ -15,7 +15,6 @@
             description => "Table name (i.e. --table=customer)",
         },
         params => {
-            required => 1,
             description => "List of params (var=value pairs) (i.e. 
--params=\"last_name=Jones|first_name=Mike\")",
         },
         columns => {
@@ -43,6 +42,9 @@
         cache_refresh => {
             description => "Skip any cached values for the table but save the 
results in the cache",
         },
+        hashkey => {
+            description => "hash key to get params from the cache",
+        },
         log_cache => {
             description => "Log cache activity",
         },
@@ -68,17 +70,40 @@
     my $context  = App->context();
     my $db       = $context->repository($App::options{repository});
     my $table    = $App::options{table};
-    my ($columns);
-    if ($App::options{columns}) {
-        $columns  = [ split(/,/, $App::options{columns}) ];
+    my $verbose  = $App::options{verbose};
+    my ($columns, $params, $headings, $get_options, $cache_rows);
+    if ($table && $App::options{hashkey}) {
+        my $hashkey = $App::options{hashkey};
+        my $table_def = $db->get_table_def($table);
+        my $cache_name = $table_def->{cache_name};
+        if ($cache_name) {
+            my $cache = $context->shared_datastore($cache_name);
+            my $ref = $cache->get_ref($hashkey);
+            if (!$ref) {
+                warn "Nothing in the [$cache_name] cache for table [$table] 
with hashkey [$hashkey]\n";
+            }
+            else {
+                ($table, $params, $columns, $cache_rows, $get_options) = @$ref;
+                $get_options->{cache_skip} = 1;
+                print $db->dump([$table, $params, $columns, $get_options]) if 
($verbose);
+            }
+        }
+        else {
+            warn "cache_name option is not set on table $table";
+        }
     }
     else {
-        $columns  = $db->_get_default_columns($table);
+        if ($App::options{columns}) {
+            $columns  = [ split(/,/, $App::options{columns}) ];
+        }
+        else {
+            $columns  = $db->_get_default_columns($table);
+        }
+        die "Must supply the --params option\n" if (! defined 
$App::options{params});
+        $params   = { split(/[=>\|]+/, $App::options{params}) };
+        $headings = $App::options{headings} ? [ split(/,/, 
$App::options{headings}) ] : [];
+        $get_options = { extend_columns => 1 };
     }
-    my $params   = { split(/[=>\|]+/, $App::options{params}) };
-    my $headings = $App::options{headings} ? [ split(/,/, 
$App::options{headings}) ] : [];
-    my $verbose  = $App::options{verbose};
-    my $get_options = { extend_columns => 1 };
     $get_options->{cache_skip} = 1 if ($App::options{cache_skip});
     $get_options->{cache_refresh} = 1 if ($App::options{cache_refresh});
     my $rows     = $db->get_rows($table, $params, $columns, $get_options);

Reply via email to