Diff for /db/prgsrc/db.cgi between versions 1.13 and 1.14

version 1.13, 2001/01/26 12:09:32 version 1.14, 2001/05/16 23:49:01
Line 5  use CGI ':all'; Line 5  use CGI ':all';
 use strict;  use strict;
 use Time::Local;  use Time::Local;
 use POSIX qw(locale_h);  use POSIX qw(locale_h);
   my $debug=1; #added by R7
 my ($PWD) = `pwd`;  my ($PWD) = `pwd`;
 chomp $PWD;  chomp $PWD;
 my ($SRCPATH) = "$PWD/../dimrub/src";  my ($SRCPATH) = "$PWD/../dimrub/src";
Line 105  sub GetTours { Line 105  sub GetTours {
   
 # Returns list of QuestionId's, that have the search string in them.  # Returns list of QuestionId's, that have the search string in them.
 sub Search {  sub Search {
         my ($dbh, $sstr) = @_;          my ($dbh, $sstr, $metod) = @_;
         my (@arr, @Questions, @fields);          my (@arr, @Questions, @fields);
         my (@sar, $i, $sth);          my (@sar, $i, $sth,$where);
   
 #       push @fields, 'Question';  #       push @fields, 'Question';
         foreach (qw/Question Answer Sources Authors Comments/) {  
   ###Simple and advanced query processing. Added by R7
           if ($metod eq 'simple' || $metod eq 'advanced') 
           {
           foreach (qw/Question Answer Sources Authors Comments/) {
                 if (param($_)) {                  if (param($_)) {
                         push @fields, "IFNULL($_, '')";                          push @fields, $_; 
                 }                  }
         }          }
   
         @sar = split " ", $sstr;             @fields=(qw/Question Answer Sources Authors Comments/) unless scalar @fields;
         for $i (0 .. $#sar) {             my $fields=join ",", @fields;
              my $q=new Text::Query($sstr,
                    -parse => 'Text::Query::'. 
                      (($metod eq 'simple') ? 'ParseSimple':'ParseAdvanced'),
                    -solve => 'Text::Query::SolveSQL',
                    -build => 'Text::Query::BuildSQLMySQL',
                    -fields_searched => $fields);
   
              $where=      $$q{'matchexp'};
              my $query= "SELECT Questionid FROM Questions
                   WHERE $where";
              print br."Query is: $query".br if $debug;
   
              $sth = $dbh->prepare($query);
            } else
   ######   
            {
   
   
             foreach (qw/Question Answer Sources Authors Comments/) {
                   if (param($_)) {
                           push @fields, "IFNULL($_, '')";
                   }
             }
   
             @sar = split " ", $sstr;
             for $i (0 .. $#sar) {
                 $sar[$i] = $dbh->quote("%${sar[$i]}%");                  $sar[$i] = $dbh->quote("%${sar[$i]}%");
         }            }
   
         my($f) = "CONCAT(" . join(',', @fields) . ")";            my($f) = "CONCAT(" . join(',', @fields) . ")";
         if (param('all') eq 'yes') {            if (param('all') eq 'yes') {
                 $sstr = join " AND $f LIKE ", @sar;                  $sstr = join " AND $f LIKE ", @sar;
         } else {            } else {
                 $sstr = join " OR $f LIKE ", @sar;                  $sstr = join " OR $f LIKE ", @sar;
         }            }
                   
         $sth = $dbh->prepare("SELECT QuestionId FROM Questions            $sth = $dbh->prepare("SELECT QuestionId FROM Questions
                 WHERE $f LIKE $sstr ORDER BY QuestionId");                  WHERE $f LIKE $sstr ORDER BY QuestionId");
   
           } #else -- processing old-style query (R7)
   
         $sth->execute;          $sth->execute;
         while (@arr = $sth->fetchrow) {          while (@arr = $sth->fetchrow) {
                 push @Questions, $arr[0];                  push @Questions, $arr[0];
Line 155  sub NoCase { Line 187  sub NoCase {
 }  }
   
 sub PrintSearch {  sub PrintSearch {
         my ($dbh, $sstr) = @_;          my ($dbh, $sstr, $metod) = @_;
    my (@Questions) = &Search($dbh, $sstr);          my (@Questions) = &Search($dbh, $sstr,$metod);
         my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);          my ($output, $i, $suffix, $hits) = ('', 0, '', $#Questions + 1);
   
         if ($hits =~ /1.$/  || $hits =~ /[5-90]$/) {          if ($hits =~ /1.$/  || $hits =~ /[5-90]$/) {
Line 635  EOT Line 667  EOT
                         print &PrintRandom($dbh, $type, $qnum, $text);                          print &PrintRandom($dbh, $type, $qnum, $text);
                 }                  }
         } elsif (param('sstr')) {          } elsif (param('sstr')) {
                 &PrintSearch($dbh, param('sstr'));                  &PrintSearch($dbh, param('sstr'), param('metod'));
         } elsif (param('all')) {          } elsif (param('all')) {
                 print &PrintAll($dbh, 0);                  print &PrintAll($dbh, 0);
         } elsif (param('from_year') && param('to_year')) {          } elsif (param('from_year') && param('to_year')) {

Removed from v.1.13  
changed lines
  Added in v.1.14


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>