/[webpac]/branches/tehnika/index_DBI_filter.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 /branches/tehnika/index_DBI_filter.pm

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

revision 696 by dpavlin, Thu Jan 27 21:17:47 2005 UTC revision 697 by dpavlin, Sun Mar 13 02:03:30 2005 UTC
# Line 11  use strict qw(vars); Line 11  use strict qw(vars);
11  use vars qw($Count);  use vars qw($Count);
12  use HTML::Entities;  use HTML::Entities;
13  use URI::Escape;  use URI::Escape;
 use locale;  
14  use Carp;  use Carp;
   
15  use DBI;  use DBI;
16    use locale;
17    
18  # bench time  # bench time
19  my $bench_time = time();  my $bench_time = time();
# Line 103  sub insert { Line 102  sub insert {
102    
103          if (! $self->{c}->{$uc}->{$field}) {          if (! $self->{c}->{$uc}->{$field}) {
104  #print stderr "in index: $index_data\n";  #print stderr "in index: $index_data\n";
105                  $self->{c}->{$uc}->{$field}->{item} = $index_data;                  $self->{c}->{$uc}->{$field}->{item} = lc($index_data);
106                  $self->{c}->{$uc}->{$field}->{display} = $display;                  $self->{c}->{$uc}->{$field}->{display} = $display;
107          }          }
108    
# Line 121  sub count { Line 120  sub count {
120    
121          my $tables_sql = 'data';          my $tables_sql = 'data';
122          my $where_sql = '';          my $where_sql = '';
123          my @sql_args = ( $field, $where );          my @sql_args = ( $field, lc($where) );
124    
125          if ($filter) {          if ($filter) {
126                  $tables_sql .= ",filters";                  $tables_sql .= ",filters";
# Line 135  sub count { Line 134  sub count {
134          my $sql = qq{          my $sql = qq{
135                  select count(*)                  select count(*)
136                  from $tables_sql                  from $tables_sql
137                  where name = ? and upper(item) like upper(?)||'%'                  where name = ? and item like ?||'%'
138                  $where_sql                  $where_sql
139          };          };
140    
# Line 181  sub fetch { Line 180  sub fetch {
180          my $tables_sql = 'data';          my $tables_sql = 'data';
181          my $where_sql = '';          my $where_sql = '';
182    
183          my @sql_args = ( $field, $where );          my @sql_args = ( $field, lc($where) );
184    
185          if ($filter) {          if ($filter) {
186                  $tables_sql .= ",filters";                  $tables_sql .= ",filters";
# Line 196  sub fetch { Line 195  sub fetch {
195                  my $sql2 = qq{                  my $sql2 = qq{
196                          select data.ord as ord                          select data.ord as ord
197                          from $tables_sql                          from $tables_sql
198                          where name = ? and upper(item) like upper(?)||'%'                          where name = ? and item like ?||'%'
199                          $where_sql                          $where_sql
200                            order by data.ord
201                  };                  };
202                  my $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();                  my $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
203    
204                  $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();                  $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
205                  if (my $row = $sth->fetchrow_hashref) {                  if (my $row = $sth->fetchrow_hashref) {
206                          $from_ord += $row->{ord} - 1;                          $from_ord = $row->{ord} - 1;
207                  } else {                  } else {
208                          # if no match is found when searching from beginning                          # if no match is found when searching from beginning
209                          # of word in index, try substring match anywhere                          # of word in index, try substring match anywhere
210                          $sql2 = qq{                          $sql2 = qq{
211                                  select data.ord as ord                                  select data.ord as ord
212                                  from $tables_sql                                  from $tables_sql
213                                  where name = ? and upper(item) like '% '||upper(?)||'%'                                  where name = ? and item like '%'||?||'%'
214                                  $where_sql                                  $where_sql
215                                    order by data.ord
216                          };                          };
217                    
218                          $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();                          $sth = $self->{dbh}->prepare($sql2) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
219                          $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();                          $sth->execute(@sql_args) || confess "sql2: $sql2; ".$self->{dbh}->errstr();
220    
221                          if (my $row = $sth->fetchrow_hashref) {                          if (my $row = $sth->fetchrow_hashref) {
222                                  $from_ord += $row->{ord} - 1;                                  $from_ord = $row->{ord} - 1;
223                          }                          }
224                  }                  }
225          }          }

Legend:
Removed from v.696  
changed lines
  Added in v.697

  ViewVC Help
Powered by ViewVC 1.1.26