cvsuser     03/11/18 13:38:10

  Modified:    App-Repository TODO
               App-Repository/lib/App Repository.pm
               App-Repository/lib/App/Repository DBI.pm
               App-Repository/t DBI-getset.t DBI-select.t
  Log:
  undef param values mean NULL instead of bind variable placeholder
  
  Revision  Changes    Path
  1.2       +26 -1     p5ee/App-Repository/TODO
  
  Index: TODO
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/TODO,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- TODO      12 Oct 2002 03:03:48 -0000      1.1
  +++ TODO      18 Nov 2003 21:38:09 -0000      1.2
  @@ -1,4 +1,29 @@
   ######################################################################
  -## File: $Id: TODO,v 1.1 2002/10/12 03:03:48 spadkins Exp $
  +## File: $Id: TODO,v 1.2 2003/11/18 21:38:09 spadkins Exp $
   ######################################################################
  +
  + o App::Repository        - Multiple (delegated) repositories
  + o App::Repository::MySQL - Shared connections between repositories
  + o App::Repository::File
  + o App::Repository        - $rep->purge(...)
  + o App::Repository::MySQL - $rep->purge(...)
  +
  + x App::Repository        - $rep->get_hash(...)
  + x App::Repository        - $rep->get_rows($tab, ..., undef)
  + x App::Repository        - $rep->get_rows($tab, ..., [])
  + x App::Repository        - $rep->get_rows($tab, undef)
  + o App::Repository        - $rep->set_rows(...)
  + o App::Repository        - $rep->maintain(...)
  + o App::Repository        - $rep->export(...)
  + o App::Repository        - $rep->import(...)
  + o App::Repository        - summaries
  + o App::Repository        - partitions
  + o App::Repository        - defaults
  + o App::Repository        - required cols
  + o App::Repository        - Read-only
  + o App::Repository        - read/write permissions
  + o App::Repository::MySQL - load primary key, alternate keys, indexes
  + o App::Repository        - ID generation
  + o App::Repository::DBI   - ID generation
  + o App::Repository::DBI   - cache, allows prepare/execute optimization
   
  
  
  
  1.8       +125 -66   p5ee/App-Repository/lib/App/Repository.pm
  
  Index: Repository.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/lib/App/Repository.pm,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -r1.7 -r1.8
  --- Repository.pm     3 Jul 2003 21:44:54 -0000       1.7
  +++ Repository.pm     18 Nov 2003 21:38:09 -0000      1.8
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Repository.pm,v 1.7 2003/07/03 21:44:54 spadkins Exp $
  +## $Id: Repository.pm,v 1.8 2003/11/18 21:38:09 spadkins Exp $
   #############################################################################
   
   package App::Repository;
  @@ -576,8 +576,28 @@
   sub get_row {
       &App::sub_entry if ($App::trace_subs);
       my ($self, $table, $params, $cols, $options) = @_;
  +
  +    my ($row, $repname, $rep);
  +    if (defined $self->{table}{$table}{repository}) {
  +        $repname = $self->{table}{$table}{repository};
  +        if ($repname ne $self->{name}) {
  +            $rep = $self->{context}->repository($repname);
  +            $row = $rep->get_row($table, $params, $cols, $options);
  +        }
  +    }
  +    if (!$row) {
       $self->_load_table_metadata($table) if (! defined 
$self->{table}{$table}{loaded});
  -    my $row = $self->_get_row($table, $params, $cols, $options);
  +        if (!defined $cols) {
  +            $cols = $self->{table}{$table}{columns};
  +        }
  +        elsif (!ref($cols)) {
  +            $cols = [ $cols ];
  +        }
  +        elsif ($#$cols == -1) {
  +            @$cols = @{$self->{table}{$table}{columns}};
  +        }
  +        $row = $self->_get_row($table, $params, $cols, $options);
  +    }
       &App::sub_exit($row) if ($App::trace_subs);
       return($row);
   }
  @@ -685,8 +705,27 @@
   sub get_rows {
       &App::sub_entry if ($App::trace_subs);
       my ($self, $table, $params, $cols, $options) = @_;
  +    my ($rows, $repname, $rep);
  +    if (defined $self->{table}{$table}{repository}) {
  +        $repname = $self->{table}{$table}{repository};
  +        if ($repname ne $self->{name}) {
  +            $rep = $self->{context}->repository($repname);
  +            $rows = $rep->get_rows($table, $params, $cols, $options);
  +        }
  +    }
  +    if (!$rows) {
       $self->_load_table_metadata($table) if (! defined 
$self->{table}{$table}{loaded});
  -    my $rows = $self->_get_rows($table, $params, $cols, $options);
  +        if (!defined $cols) {
  +            $cols = $self->{table}{$table}{columns};
  +        }
  +        elsif (!ref($cols)) {
  +            $cols = [ $cols ];
  +        }
  +        elsif ($#$cols == -1) {
  +            @$cols = @{$self->{table}{$table}{columns}};
  +        }
  +        $rows = $self->_get_rows($table, $params, $cols, $options);
  +    }
       &App::sub_exit($rows) if ($App::trace_subs);
       return($rows);
   }
  @@ -727,13 +766,13 @@
   }
   
   #############################################################################
  -# get_values()
  +# get_hash()
   #############################################################################
   
  -=head2 get_values()
  +=head2 get_hash()
   
  -    * Signature: $values = $rep->get_values ($table, $key,    $cols, $options);
  -    * Signature: $values = $rep->get_values ($table, $params, $cols, $options);
  +    * Signature: $values = $rep->get_hash ($table, $key,    $cols, $options);
  +    * Signature: $values = $rep->get_hash ($table, $params, $cols, $options);
       * Param:     $table     string
       * Param:     $cols      ARRAY,undef
       * Param:     $key       string
  @@ -745,74 +784,91 @@
   
       Sample Usage:
   
  -    $values = $rep->get_values ($table, $key,     [EMAIL PROTECTED],   \%options);
  -    $values = $rep->get_values ($table, \%params, [EMAIL PROTECTED],   \%options);
  -    $values = $rep->get_values ($table, $key,     undef,    \%options);
  -    $values = $rep->get_values ($table, \%params, undef,    \%options);
  +    $values = $rep->get_hash ($table, $key,     [EMAIL PROTECTED],   \%options);
  +    $values = $rep->get_hash ($table, \%params, [EMAIL PROTECTED],   \%options);
  +    $values = $rep->get_hash ($table, $key,     undef,    \%options);
  +    $values = $rep->get_hash ($table, \%params, undef,    \%options);
   
   tbd.
   
   =cut
   
  -sub get_values {
  +sub get_hash {
       &App::sub_entry if ($App::trace_subs);
       my ($self, $table, $params, $cols, $options) = @_;
  -    &App::sub_exit() if ($App::trace_subs);
  +    $cols = [] if (!$cols);
  +    my $row = $self->get_row($table, $params, $cols, $options);
  +    my $hash = {};
  +    my ($col, $value);
  +    if ($row && $#$row > -1) {
  +        for (my $idx = 0; $idx <= $#$cols; $idx++) {
  +            $col = $cols->[$idx];
  +            $value = $row->[$idx];
  +            $hash->{$col} = $value;
  +        }
  +    }
  +    &App::sub_exit($hash) if ($App::trace_subs);
  +    return($hash);
   }
   
   #############################################################################
  -# get_values_list()
  +# get_hashes()
   #############################################################################
   
  -=head2 get_values_list()
  +=head2 get_hashes()
   
  -    * Signature: $values_list = $rep->get_values_list ($table, $key,    $cols, 
$options);
  -    * Signature: $values_list = $rep->get_values_list ($table, $params, $cols, 
$options);
  +    * Signature: $hashes = $rep->get_hashes ($table, $key,    $cols, $options);
  +    * Signature: $hashes = $rep->get_hashes ($table, $params, $cols, $options);
       * Param:     $table        string
       * Param:     $cols         ARRAY,undef
       * Param:     $key          string
       * Param:     $params       undef,HASH
       * Param:     $options      undef,HASH
  -    * Return:    $values_list  ARRAY
  +    * Return:    $hashes       ARRAY
       * Throws:    App::Exception::Repository
       * Since:     0.50
   
       Sample Usage:
   
  -    $values_list = $rep->get_values_list ($table, $key,     [EMAIL PROTECTED],   
\%options);
  -    $values_list = $rep->get_values_list ($table, \%params, [EMAIL PROTECTED],   
\%options);
  -    $values_list = $rep->get_values_list ($table, $key,     undef,    \%options);
  -    $values_list = $rep->get_values_list ($table, \%params, undef,    \%options);
  +    $hashes = $rep->get_hashes ($table, $key,     [EMAIL PROTECTED],   \%options);
  +    $hashes = $rep->get_hashes ($table, \%params, [EMAIL PROTECTED],   \%options);
  +    $hashes = $rep->get_hashes ($table, $key,     undef,    \%options);
  +    $hashes = $rep->get_hashes ($table, \%params, undef,    \%options);
   
   tbd.
   
   =cut
   
  -sub get_values_list {
  +sub get_hashes {
       &App::sub_entry if ($App::trace_subs);
       my ($self, $table, $params, $cols, $options) = @_;
  -    my (@cols, $rows, $row, $colidx, $values, @values_list);
  -    $cols = [EMAIL PROTECTED] if (!defined $cols);
  -    $rows = $self->_get_rows($table, $params, $cols, $options);
  +    $cols = [] if (!$cols);
  +    my $rows = $self->get_rows($table, $params, $cols, $options);
  +    my $hashes = [];
  +    my ($hash, $row, $col, $value);
  +    if ($rows && $#$rows > -1) {
       foreach $row (@$rows) {
  -        $values = {};
  -        for ($colidx = 0; $colidx <= $#$cols; $colidx++) {
  -            $values->{$cols->[$colidx]} = $row->[$colidx];
  +            $hash = {};
  +            for (my $idx = 0; $idx <= $#$cols; $idx++) {
  +                $col = $cols->[$idx];
  +                $value = $row->[$idx];
  +                $hash->{$col} = $value;
           }
  -        push(@values_list, $values);
  +            push(@$hashes, $hash);
       }
  -    &App::sub_exit($rows) if ($App::trace_subs);
  -    return([EMAIL PROTECTED]);
  +    }
  +    &App::sub_exit($hashes) if ($App::trace_subs);
  +    return($hashes);
   }
   
   #############################################################################
  -# set_values()
  +# set_hash()
   #############################################################################
   
  -=head2 set_values()
  +=head2 set_hash()
   
  -    * Signature: $nrows = $rep->set_values ($table, $key,    $cols, $values, 
$options);
  -    * Signature: $nrows = $rep->set_values ($table, $params, $cols, $values, 
$options);
  +    * Signature: $nrows = $rep->set_hash ($table, $key,    $cols, $values, 
$options);
  +    * Signature: $nrows = $rep->set_hash ($table, $params, $cols, $values, 
$options);
       * Param:     $table     string
       * Param:     $key       string
       * Param:     $params    undef,HASH
  @@ -824,18 +880,18 @@
   
       Sample Usage:
   
  -    $nrows = $rep->set_values ($table, $key,     [EMAIL PROTECTED], $values, 
\%options);
  -    $nrows = $rep->set_values ($table, $key,     undef,  $values, \%options);
  -    $nrows = $rep->set_values ($table, undef,    [EMAIL PROTECTED], $values, 
\%options);
  -    $nrows = $rep->set_values ($table, undef,    undef,  $values, \%options);
  -    $nrows = $rep->set_values ($table, \%params, [EMAIL PROTECTED], $values, 
\%options);
  -    $nrows = $rep->set_values ($table, \%params, undef,  $values, \%options);
  +    $nrows = $rep->set_hash ($table, $key,     [EMAIL PROTECTED], $values, 
\%options);
  +    $nrows = $rep->set_hash ($table, $key,     undef,  $values, \%options);
  +    $nrows = $rep->set_hash ($table, undef,    [EMAIL PROTECTED], $values, 
\%options);
  +    $nrows = $rep->set_hash ($table, undef,    undef,  $values, \%options);
  +    $nrows = $rep->set_hash ($table, \%params, [EMAIL PROTECTED], $values, 
\%options);
  +    $nrows = $rep->set_hash ($table, \%params, undef,  $values, \%options);
   
   tbd.
   
   =cut
   
  -sub set_values {
  +sub set_hash {
       &App::sub_entry if ($App::trace_subs);
       my ($self, $table, $params, $cols, $values, $options) = @_;
       $self->_load_table_metadata($table) if (! defined 
$self->{table}{$table}{loaded});
  @@ -1007,13 +1063,15 @@
       $cols = $self->{table}{$table}{columns} if ($all_columns);
       $params = $self->_params_to_hashref($table, $params) if (ref($params) ne 
"HASH");
       # we only need the first row
  -    $options = {} if (!$options);
  -    if (! $options->{endrow}) {
  +    if (!$options) {
  +        $options = { endrow => 1 };
  +    }
  +    elsif (! defined $options->{endrow}) {
           $options->{endrow} = $options->{startrow} || 1;
       }
   
       my ($rows, $row, $matched_row);
  -    $rows = $self->{table}{$table}{data};
  +    $rows = $self->{table}{$table}{data};   # get data from configuration only (no 
external source)
       if ($rows && ref($rows) eq "ARRAY") {
           foreach $row (@$rows) {
               if ($self->_row_matches($row, $table, $params, $cols, $options)) {
  @@ -1078,7 +1136,7 @@
           }
           die "Tried to set_rows() and the primary key is not among the columns" if 
($keys_supplied != $#$primary_key+1);
           foreach $row (@$rows) {
  -            $nrows += $self->update_row($table, $cols, $row, [EMAIL PROTECTED]);
  +            $nrows += $self->_update($table, $cols, $row, [EMAIL PROTECTED]);
           }
       }
       elsif (ref($params) eq "ARRAY") {
  @@ -1617,7 +1675,7 @@
                   $change = $rowchange->[$rowidx];
                   next if (!defined $change);
                   if ($change eq "U") {
  -                    $self->update_row($table, $colref, $rows->[$rowidx], 
$prikeyidx);
  +                    $self->_update($table, $colref, $rows->[$rowidx], $prikeyidx);
                       $rowchange->[$rowidx] = "";
                       $nrows++;
                   }
  @@ -1703,7 +1761,7 @@
   
   sub object {
       my ($self, $table, $key) = @_;
  -    my $class = $self->{table}{$table}{objectClass} || "App::RepositoryObject";
  +    my $class = $self->{table}{$table}{object_class} || "App::RepositoryObject";
       if (! $self->{used}{$class}) {
           App->use($class);
           $self->{used}{$class} = 1;
  @@ -2021,19 +2079,10 @@
           if (! $table_def->{label}) {
               $label = $table;
               if ($self->{autolabel}) {
  -                $label =~ s/^_+//;
  -                $label =~ s/_+$//;
  -                if ($label =~ /[a-z]/ && $label =~ /[A-Z]/) {
  -                    $label =~ s/_+/ <br>/g;
  -                }
  -                else {
                       $label = lc($label);
  -                    @label = split(/_+/,$label);
  -                    foreach (@label) {
  -                        $_ = ucfirst($_);
  -                    }
  -                    $label = join(" <br>", @label);
  -                }
  +                $label =~ s/^([a-z])/uc($1)/e;
  +                $label =~ s/(_[a-z])/uc($1)/eg;
  +                $label =~ s/_+/ /g;
               }
               $table_def->{label} = $label;
           }
  @@ -2178,10 +2227,20 @@
       }
   
       # for each column in the hash (random order), add them to the end
  +    my ($label);
       foreach $column (keys %{$table_def->{column}}) {
           $column_def = $table_def->{column}{$column};
           $column_def->{name} = $column;
  -        $column_def->{label} = $column if (! $column_def->{label});
  +        if (! $column_def->{label}) {
  +            $label = $column;
  +            if ($self->{autolabel}) {
  +                $label = lc($label);
  +                $label =~ s/^([a-z])/uc($1)/e;
  +                $label =~ s/(_[a-z])/uc($1)/eg;
  +                $label =~ s/_+/ /g;
  +            }
  +            $column_def->{label} = $label;
  +        }
    
           # column has not been added to the list and it's not explicitly "hidden", 
so add it
           if (!defined $column_def->{idx} && ! $column_def->{hide}) {
  
  
  
  1.14      +47 -37    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.13
  retrieving revision 1.14
  diff -u -w -r1.13 -r1.14
  --- DBI.pm    24 Oct 2003 20:12:50 -0000      1.13
  +++ DBI.pm    18 Nov 2003 21:38:10 -0000      1.14
  @@ -1,13 +1,13 @@
   
   ######################################################################
  -## File: $Id: DBI.pm,v 1.13 2003/10/24 20:12:50 spadkins Exp $
  +## File: $Id: DBI.pm,v 1.14 2003/11/18 21:38:10 spadkins Exp $
   ######################################################################
   
   use App;
   use App::Repository;
   
   package App::Repository::DBI;
  -$VERSION = do { my @r=(q$Revision: 1.13 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  +$VERSION = do { my @r=(q$Revision: 1.14 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
   
   @ISA = ( "App::Repository" );
   
  @@ -532,7 +532,13 @@
   
               next if (!defined $column_def);  # skip if the column is unknown
               if (! defined $params->{$param}) {
  -                $value = "?";   # TODO: make this work with the "contains/matches" 
operators
  +                # $value = "?";   # TODO: make this work with the 
"contains/matches" operators
  +                if (!$sqlop || $sqlop eq "=") {
  +                    $where .= ($colnum == 0) ? "where $column is null\n" : "  and 
$column is null\n";
  +                }
  +                else {
  +                    $where .= ($colnum == 0) ? "where $column is not null\n" : "  
and $column is not null\n";
  +                }
               }
               else {
                   $value = $params->{$param};
  @@ -583,7 +589,6 @@
                       $value =~ s/'/\\'/g;
                       $value = "'$value'";
                   }
  -            }
               $dbexpr = $column_def->{dbexpr};
               if ($dbexpr && $dbexpr ne "$alias.$column") {
                   $column = $dbexpr;
  @@ -592,6 +597,7 @@
               $where .= ($colnum == 0) ? "where $column $sqlop $value\n" : "  and 
$column $sqlop $value\n";
           }
       }
  +    }
       &App::sub_exit($where) if ($App::trace_subs);
       $where;
   }
  @@ -605,23 +611,23 @@
       $cols = [$cols] if (!ref($cols));
       $options = {} if (!$options);
   
  -    my ($sql, $ordercols, $directions, $col, $colnum, $dir);
  -    $ordercols = $options->{ordercols} || [];
  -    $ordercols = [$ordercols] if (!ref($ordercols));
  -    $directions = $options->{directions};
  +    my ($sql, $order_by, $direction, $col, $colnum, $dir);
  +    $order_by = $options->{order_by} || $options->{ordercols} || [];  # {ordercols} 
is deprecated
  +    $order_by = [$order_by] if (!ref($order_by));
  +    $direction = $options->{direction} || $options->{directions};     # 
{directions} is deprecated
   
       $sql = "select\n   " . join(",\n   ", @$cols) . "\nfrom $table\n";
       $sql .= $self->_mk_where_clause($table, $params);
   
  -    if (defined $ordercols && $#$ordercols > -1) {
  -        for ($colnum = 0; $colnum <= $#$ordercols; $colnum++) {
  -            $col = $ordercols->[$colnum];
  +    if (defined $order_by && $#$order_by > -1) {
  +        for ($colnum = 0; $colnum <= $#$order_by; $colnum++) {
  +            $col = $order_by->[$colnum];
               $dir = "";
  -            if ($directions && ref($directions) eq "HASH" && defined 
$directions->{$col}) {
  -                if ($directions->{$col} =~ /^asc$/i) {
  +            if ($direction && ref($direction) eq "HASH" && defined 
$direction->{$col}) {
  +                if ($direction->{$col} =~ /^asc$/i) {
                       $dir = " asc";
                   }
  -                elsif ($directions->{$col} =~ /^desc$/i) {
  +                elsif ($direction->{$col} =~ /^desc$/i) {
                       $dir = " desc";
                   }
               }
  @@ -650,10 +656,10 @@
       $cols = [$cols] if (!ref($cols));
       $options = {} if (!$options);
   
  -    my ($ordercols, $directions, $param_order, $col, $colnum, $dir);
  -    $ordercols = $options->{ordercols} || [];
  -    $ordercols = [$ordercols] if (!ref($ordercols));
  -    $directions = $options->{directions};
  +    my ($order_by, $direction, $param_order, $col, $colnum, $dir);
  +    $order_by = $options->{order_by} || $options->{ordercols} || [];  # {ordercols} 
is deprecated
  +    $order_by = [$order_by] if (!ref($order_by));
  +    $direction = $options->{direction} || $options->{directions};     # 
{directions} is deprecated
   
       $param_order = $params->{"_order"};
       if (!defined $param_order && ref($params) eq "HASH") {
  @@ -743,8 +749,8 @@
       }
   
       if ($auto_extend) {
  -        if (defined $ordercols && ref($ordercols) eq "ARRAY") {
  -            foreach $column (@$ordercols) {          # foreach sort key
  +        if (defined $order_by && ref($order_by) eq "ARRAY") {
  +            foreach $column (@$order_by) {          # foreach sort key
                   if ($column && ! defined $columnidx{$column} && $auto_extend) {
                       push(@$cols, $column);     # add the column to the list
                       $columnidx{$column} = $#$cols;
  @@ -857,10 +863,10 @@
       # create order-by columns
       ############################################################
       my (@order_by_dbexpr, $order_by_dbexpr);
  -    if (defined $ordercols && ref($ordercols) eq "ARRAY") {
  +    if (defined $order_by && ref($order_by) eq "ARRAY") {
   
  -        for ($idx = 0; $idx <= $#$ordercols; $idx++) {
  -            $column = $ordercols->[$idx];
  +        for ($idx = 0; $idx <= $#$order_by; $idx++) {
  +            $column = $order_by->[$idx];
               $column_def = $table_def->{column}{$column};
               next if (!defined $column_def);
   
  @@ -877,11 +883,11 @@
               }
   
               if ($order_by_dbexpr) {
  -                if ($directions && ref($directions) eq "HASH" && defined 
$directions->{$column}) {
  -                    if ($directions->{$column} =~ /^asc$/i) {
  +                if ($direction && ref($direction) eq "HASH" && defined 
$direction->{$column}) {
  +                    if ($direction->{$column} =~ /^asc$/i) {
                           $order_by_dbexpr .= " asc";
                       }
  -                    elsif ($directions->{$column} =~ /^desc$/i) {
  +                    elsif ($direction->{$column} =~ /^desc$/i) {
                           $order_by_dbexpr .= " desc";
                       }
                   }
  @@ -959,7 +965,9 @@
           next if (!defined $column_def);  # skip if the column is unknown
   
           if (! defined $params->{$param}) {
  -            $paramvalue = "?";   # TODO: make this work with the "contains/matches" 
operators
  +            # $paramvalue = "?";   # TODO: make this work with the 
"contains/matches" operators
  +            $sqlop = (!$sqlop || $sqlop eq "=") ? "is" : "is not";
  +            $paramvalue = "null";
           }
           else {
               $paramvalue = $params->{$param};
  @@ -1634,7 +1642,7 @@
   
   # NOTE: everything after the first line is optional
   # @rows = $rep->_select_rows($table, [EMAIL PROTECTED],
  -#               [EMAIL PROTECTED], \%paramvalues, [EMAIL PROTECTED],
  +#               [EMAIL PROTECTED], \%paramvalues, [EMAIL PROTECTED],
   #               $startrow, $endrow,
   #               [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL 
PROTECTED], [EMAIL PROTECTED]);
   # TODO: get the $startrow/$endrow working when one/both/neither work in the SQL 
portion
  @@ -1645,7 +1653,7 @@
   
   sub _select_rows {
       &App::sub_entry if ($App::trace_subs);
  -    my ($self, $table, $cols, $params, $paramvalues, $ordercols, $startrow, $endrow,
  +    my ($self, $table, $cols, $params, $paramvalues, $order_by, $startrow, $endrow,
           $sortdircol, $keycolidx, $writeable, $columntype, $summarykeys) = @_;
       my ($sql, $param, @params, %paramvalues, @paramvalues);
   
  @@ -1662,11 +1670,11 @@
       }
   
       if ($self->{table}{$table}{rawaccess}) {
  -        $sql = $self->_mk_select_sql($table, $cols, [EMAIL PROTECTED], 
\%paramvalues, $ordercols,
  +        $sql = $self->_mk_select_sql($table, $cols, [EMAIL PROTECTED], 
\%paramvalues, $order_by,
               $startrow, $endrow, $sortdircol, $keycolidx, $writeable, $columntype, 
$summarykeys);
       }
       else {
  -        $sql = $self->_mk_select_rows_sql($table, $cols, [EMAIL PROTECTED], 
\%paramvalues, $ordercols,
  +        $sql = $self->_mk_select_rows_sql($table, $cols, [EMAIL PROTECTED], 
\%paramvalues, $order_by,
               $startrow, $endrow, $sortdircol, $keycolidx, $writeable, $columntype, 
$summarykeys);
       }
       $self->{sql} = $sql;
  @@ -1794,7 +1802,9 @@
       if (! $self->{hide_physical}) {
   
           # get a list of the physical tables from the database
  -        @tables = $dbh->tables;
  +        # in MySQL 4.0.13, the table names are surrounded by backticks (!?!)
  +        # so for safe measure, get rid of all quotes
  +        @tables = grep(s/['"`]//g, $dbh->tables);
   
           # if the DBI method doesn't work, try the DBIx method...
           if ($#tables == -1) {
  
  
  
  1.2       +23 -0     p5ee/App-Repository/t/DBI-getset.t
  
  Index: DBI-getset.t
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Repository/t/DBI-getset.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- DBI-getset.t      21 May 2003 15:43:35 -0000      1.1
  +++ DBI-getset.t      18 Nov 2003 21:38:10 -0000      1.2
  @@ -114,6 +114,29 @@
   is($state,    "CA", "get_row() 3 values w/ %crit (checking 2 of 3)");
   is($person_id,   4, "get_row() 3 values w/ %crit (checking 3 of 3)");
   
  +my ($hashes, $hash);
  +$hash = $rep->get_hash("test_person");
  +is($hash->{person_id},  1,         "get_hash() person_id");
  +is($hash->{age},        39,        "get_hash() age");
  +is($hash->{first_name}, "steve",   "get_hash() first_name");
  +is($hash->{gender},     "M",       "get_hash() gender");
  +is($hash->{state},      "GA",      "get_hash() state");
  +
  +$hash = $rep->get_hash("test_person", 1);
  +is($hash->{person_id},  1,         "get_hash(1) person_id");
  +is($hash->{age},        39,        "get_hash(1) age");
  +is($hash->{first_name}, "steve",   "get_hash(1) first_name");
  +is($hash->{gender},     "M",       "get_hash(1) gender");
  +is($hash->{state},      "GA",      "get_hash(1) state");
  +
  +$hashes = $rep->get_hashes("test_person");
  +$hash = $hashes->[0];
  +is($hash->{person_id},  1,         "get_hashes()->[0] person_id");
  +is($hash->{age},        39,        "get_hashes()->[0] age");
  +is($hash->{first_name}, "steve",   "get_hashes()->[0] first_name");
  +is($hash->{gender},     "M",       "get_hashes()->[0] gender");
  +is($hash->{state},      "GA",      "get_hashes()->[0] state");
  +
   exit(0);
   #####################################################################
   #  $rep->set_rows($table, undef,    [EMAIL PROTECTED], $rows, \%options);
  
  
  
  1.4       +12 -8     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.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- DBI-select.t      18 Jun 2003 20:28:46 -0000      1.3
  +++ DBI-select.t      18 Nov 2003 21:38:10 -0000      1.4
  @@ -87,6 +87,7 @@
       }
   }
   
  +# &test_get_rows($expect_sql,0,"_mk_select_joined_sql(): 1 col, no 
params","test_person",{},"age");
   sub test_get_rows {
       my $expected_sql = shift;
       my $expected_rows = shift;
  @@ -146,7 +147,7 @@
   select
      age
   from test_person
  -where person_id = ?
  +where person_id is null
   EOF
   $sql = $rep->_mk_select_sql("test_person",undef,"age");
   is($sql, $expect_sql, "_mk_select_sql(): by key (bind vars)");
  @@ -193,9 +194,9 @@
   select
      first_name
   from test_person
  -where first_name = ?
  -  and age = ?
  -  and birth_dt = ?
  +where first_name is null
  +  and age is null
  +  and birth_dt is null
   EOF
   $sql = $rep->_mk_select_sql("test_person",{
           "_order" => [ "first_name", "age", "birth_dt", ],
  @@ -454,7 +455,10 @@
   from
      test_person t1
   EOF
  +#$App::trace_subs = 1;
   &test_get_rows($expect_sql,0,"_mk_select_joined_sql(): 1 col, no 
params","test_person",{},"age");
  +exit(0);
  +
   &test_get_rows($expect_sql,0,"_mk_select_joined_sql(): 1 col as array, no 
params","test_person",{},["age"]);
   
   $expect_sql = <<EOF;
  @@ -480,7 +484,7 @@
   #   t1.age cn13
   #from
   #   test_person t1
  -#where t1.person_id = ?
  +#where t1.person_id is null
   #EOF
   #&test_get_rows($expect_sql,0,"_mk_select_joined_sql(): by key (bind 
vars)","test_person",undef,"age");
   
  @@ -524,9 +528,9 @@
      t1.first_name cn1
   from
      test_person t1
  -where t1.first_name = ?
  -  and t1.age = ?
  -  and t1.birth_dt = ?
  +where t1.first_name is null
  +  and t1.age is null
  +  and t1.birth_dt is null
   EOF
   &test_get_rows($expect_sql, 0, "_mk_select_joined_sql(): params (bind vars)",
       "test_person",{
  
  
  

Reply via email to