Author: spadkins
Date: Mon Feb 25 12:54:42 2008
New Revision: 10825

Modified:
   p5ee/trunk/App-Repository/CHANGES
   p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
   p5ee/trunk/App-Repository/t/DBI-getset.t

Log:
enable param substitutions in dbexpr's

Modified: p5ee/trunk/App-Repository/CHANGES
==============================================================================
--- p5ee/trunk/App-Repository/CHANGES   (original)
+++ p5ee/trunk/App-Repository/CHANGES   Mon Feb 25 12:54:42 2008
@@ -3,6 +3,7 @@
 #########################################
 
 0.966 (not yet released)
+ x App::Repository::mk_select_joined_sql(): enable param substitutions in 
dbexpr's
  x App::Repository::get_rows()/get_row(): use query caching if turned on for 
the table ({cache_name} => "name_of_shared_datastore")
  x App::Repository::create_temporary_object_set(): can create a temporary 
object set with data, not bound to the database
  x App::Repository::create_temporary_object_domain(): can create a temporary 
object domain with data, not bound to the database

Modified: p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm
==============================================================================
--- p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm (original)
+++ p5ee/trunk/App-Repository/lib/App/Repository/DBI.pm Mon Feb 25 12:54:42 2008
@@ -1116,6 +1116,13 @@
         }
 
         ############################################################
+        # allow param substitutions in dbexpr
+        ############################################################
+        if ($dbexpr =~ /{/) {
+            $dbexpr = $self->substitute($dbexpr, $params);
+        }
+
+        ############################################################
         # accumulate select expressions and their aliases
         ############################################################
         if ($is_summary) {

Modified: p5ee/trunk/App-Repository/t/DBI-getset.t
==============================================================================
--- p5ee/trunk/App-Repository/t/DBI-getset.t    (original)
+++ p5ee/trunk/App-Repository/t/DBI-getset.t    Mon Feb 25 12:54:42 2008
@@ -41,6 +41,11 @@
                 table => {
                     test_person => {
                         primary_key => ["person_id"],
+                        column => {
+                            years_older => {
+                                dbexpr => "age-{base_age:0}",
+                            },
+                        },
                     },
                 },
             },
@@ -229,6 +234,16 @@
 is($#$hashes+1, 1, "get_hashes not_matches (?A)");
 
 #print $rep->{sql};
+
+#####################################################################
+# dbexpr with substitutions
+#####################################################################
+my ($years_older);
+$years_older = $rep->get("test_person", {person_id => 1}, "years_older");
+is($years_older, 41, "get() years_older [$years_older] base_age is undef");
+$years_older = $rep->get("test_person", {person_id => 1, base_age => 20}, 
"years_older");
+is($years_older, 21, "get() years_older [$years_older] base_age = 20");
+
 exit(0);
 #####################################################################
 #  $rep->set_rows($table, undef,    [EMAIL PROTECTED], $rows, \%options);

Reply via email to