/[webpac]/trunk/index_DBI_cache.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/index_DBI_cache.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 94 by dpavlin, Sun Jul 13 19:30:28 2003 UTC revision 127 by dpavlin, Thu Sep 4 14:56:41 2003 UTC
# Line 138  sub fetch { Line 138  sub fetch {
138          my $sql = "select $what,ord from $field";          my $sql = "select $what,ord from $field";
139    
140          if ($where) {          if ($where) {
141                  my $sql2 = " select ord from $field where upper($what) like upper(?)||'%'";                  my $sql2 = "select ord from $field where upper($what) like upper(?)||'%'";
142                  my $sth = $self->{dbh}->prepare($sql2) || die "sql2: $sql2; ".$self->{dbh}->errstr();                  my $sth = $self->{dbh}->prepare($sql2) || die "sql2: $sql2; ".$self->{dbh}->errstr();
143    
144                  $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr();                  $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr();
145                  if (my $row = $sth->fetchrow_hashref) {                  if (my $row = $sth->fetchrow_hashref) {
146                          $from_ord += $row->{ord} - 1;                          $from_ord += $row->{ord} - 1;
147                    } else {
148                            # if no match is found when searching from beginning
149                            # of word in index, try substring match anywhere
150                            $sql2 = "select ord from $field where upper($what) like '%'||upper(?)||'%'";
151                            $sth = $self->{dbh}->prepare($sql2) || die "sql2: $sql2; ".$self->{dbh}->errstr();
152                            $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr();
153                            if (my $row = $sth->fetchrow_hashref) {
154                                    $from_ord += $row->{ord} - 1;
155                            }
156                  }                  }
157          }          }
158          $sql .= " order by ord limit $rows offset $from_ord";          $sql .= " order by ord limit $rows offset $from_ord";
# Line 178  sub close { Line 187  sub close {
187    
188                  my $ord = 0;                  my $ord = 0;
189                  foreach my $key (@keys) {                  foreach my $key (@keys) {
190                          $sth->execute($ord++,                          $sth->execute(++$ord,
191                                  $c_table->{$table}->{$key},                                  $c_table->{$table}->{$key},
192                                  $c_count->{$table}->{$key}                                  $c_count->{$table}->{$key}
193                          );                          );

Legend:
Removed from v.94  
changed lines
  Added in v.127

  ViewVC Help
Powered by ViewVC 1.1.26