cvsuser     03/06/18 13:28:46

  Modified:    App-Repository/lib/App/Repository DBI.pm
               App-Repository/t DBI-delete.t DBI-select.t
  Log:
  added delete/update where param is a dbexpr
  
  Revision  Changes    Path
  1.9       +14 -5     p5ee/App-Repository/lib/App/Repository/DBI.pm
  
  Index: DBI.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository/DBI.pm,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- DBI.pm    18 Jun 2003 14:56:20 -0000      1.8
  +++ DBI.pm    18 Jun 2003 20:28:45 -0000      1.9
  @@ -1,13 +1,13 @@
   
   ######################################################################
  -## File: $Id: DBI.pm,v 1.8 2003/06/18 14:56:20 spadkins Exp $
  +## File: $Id: DBI.pm,v 1.9 2003/06/18 20:28:45 spadkins Exp $
   ######################################################################
   
   use App;
   use App::Repository;
   
   package App::Repository::DBI;
  -$VERSION = do { my @r=(q$Revision: 1.8 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.9 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository" );
   
  @@ -911,11 +911,12 @@
   
   sub _mk_where_clause {
       &App::sub_entry if ($App::trace_subs);
  -    my ($self, $table, $params) = @_;
  +    my ($self, $table, $params, $options) = @_;
       my ($where, $column, $colstr, $value, $colnum, $repop, $sqlop, $column_def, 
$quoted);
  -    my ($tabledef, $tabcols, %sqlop);
  +    my ($tabledef, $tabcols, %sqlop, $alias, $dbexpr);
   
       $tabledef = $self->{table}{$table};
  +    $alias    = $tabledef->{alias};
       $tabcols  = $tabledef->{column};
       %sqlop = (
           'contains' => 'like',
  @@ -959,6 +960,9 @@
                   if ($value =~ s/^!expr!//) {
                       $quoted = 0;
                   }
  +                elsif ($value =~ /,/ && ! 
$tabledef->{param}{$colstr}{no_auto_in_param}) {
  +                    $quoted = (defined $column_def->{quoted}) ? 
($column_def->{quoted}) : ($value !~ /^-?[0-9.,]+$/);
  +                }
                   else {
                       $quoted = (defined $column_def->{quoted}) ? 
($column_def->{quoted}) : ($value !~ /^-?[0-9.]+$/);
                   }
  @@ -1000,6 +1004,11 @@
                       $value = "'$value'";
                   }
               }
  +            $dbexpr = $column_def->{dbexpr};
  +            if ($dbexpr && $dbexpr ne "$alias.$column") {
  +                $column = $dbexpr;
  +                $column =~ s/$alias.//g;
  +            }
               $where .= ($colnum == 0) ? "where $column $sqlop $value\n" : "  and 
$column $sqlop $value\n";
           }
       }
  @@ -1442,7 +1451,7 @@
               elsif ($repop eq "matches") {
                   $paramvalue =~ s/\*/%/g;
                   $paramvalue =~ s/'/\\'/g;
  -                $paramvalue = "'%$paramvalue%'";
  +                $paramvalue = "'$paramvalue'";
               }
               elsif ($sqlop eq "in" || $sqlop eq "=") {
                   if ($quoted) {
  
  
  
  1.2       +27 -14    p5ee/App-Repository/t/DBI-delete.t
  
  Index: DBI-delete.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/t/DBI-delete.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- DBI-delete.t      18 Jun 2003 14:55:04 -0000      1.1
  +++ DBI-delete.t      18 Jun 2003 20:28:46 -0000      1.2
  @@ -22,7 +22,13 @@
                   dbpass => "dbuser7",
                   table => {
                       test_person => {
  +            alias => "tp",
                           primary_key => ["person_id"],
  +            column => {
  +              birth_dow => {
  +                dbexpr => "weekday(tp.birth_dt)",
  +              },
  +            },
                       },
                   },
               },
  @@ -154,6 +160,13 @@
       ["person_id","age","first_name","gender","state"],
       {ordercols=>["first_name"],});
   is_deeply($rows,$rows3,"rows after deleting 3 params");
  +
  +$expect_sql = <<EOF;
  +delete from test_person
  +where weekday(birth_dt) in (1,7)
  +EOF
  +$sql = $rep->_mk_delete_sql("test_person", { "birth_dow" => "1,7" });
  +is($sql, $expect_sql, "_mk_delete_sql(): dbexpr");
   
   $expect_sql = <<EOF;
   delete from test_person
  
  
  
  1.3       +10 -10    p5ee/App-Repository/t/DBI-select.t
  
  Index: DBI-select.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/t/DBI-select.t,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -r1.2 -r1.3
  --- DBI-select.t      18 Jun 2003 14:54:43 -0000      1.2
  +++ DBI-select.t      18 Jun 2003 20:28:46 -0000      1.3
  @@ -398,14 +398,14 @@
      first_name
   from test_person
   where first_name like '%s%'
  -  and age like '%3%'
  -  and birth_dt like '%1962%'
  +  and age like '%3'
  +  and birth_dt like '1962%'
   EOF
   $sql = $rep->_mk_select_sql("test_person",{
           "_order" => [ "first_name.matches", "age.matches", "birth_dt.matches", ],
  -        "first_name.matches" => "s",
  -        "age.matches" => "3",
  -        "birth_dt.matches" => "1962",
  +        "first_name.matches" => "*s*",
  +        "age.matches" => "*3",
  +        "birth_dt.matches" => "1962*",
       },["first_name"]);
   is($sql, $expect_sql, "_mk_select_sql(): param.matches");
   &check_select($sql,0);
  @@ -729,15 +729,15 @@
   from
      test_person t1
   where t1.first_name like '%s%'
  -  and t1.age like '%3%'
  -  and t1.birth_dt like '%1962%'
  +  and t1.age like '%3'
  +  and t1.birth_dt like '1962%'
   EOF
   &test_get_rows($expect_sql, 0, "_mk_select_joined_sql(): param.matches",
       "test_person",{
           "_order" => [ "first_name.matches", "age.matches", "birth_dt.matches", ],
  -        "first_name.matches" => "s",
  -        "age.matches" => "3",
  -        "birth_dt.matches" => "1962",
  +        "first_name.matches" => "*s*",
  +        "age.matches" => "*3",
  +        "birth_dt.matches" => "1962*",
       },["first_name"]);
   
   $expect_sql = <<EOF;
  
  
  

Reply via email to