/[webpac]/trunk/index_DBI.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.pm

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

revision 12 by dpavlin, Wed Jan 22 22:27:19 2003 UTC revision 19 by dpavlin, Sat Feb 22 23:47:15 2003 UTC
# Line 31  sub delete_and_create { Line 31  sub delete_and_create {
31    
32          my $field = shift;          my $field = shift;
33    
34    #print "#### delete_and_create($field)\n";
35    
36          $self->{dbh}->commit;          $self->{dbh}->commit;
         $self->{dbh}->begin_work;  
37    
38          my $sql = "select count(*) from $field";          my $sql = "select count(*) from $field";
39          my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr();          my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr();
40  # FIX: this is not a good way to check if table exists!  # FIX: this is not a good way to check if table exists!
41          if (1 || $sth->execute() && $sth->fetchrow_hashref) {          if ($sth->execute() && $sth->fetchrow_hashref) {
42                  my $sql = "drop table $field";                  my $sql = "drop table $field";
43  #               my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr();                  $self->{dbh}->begin_work;
44                    my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr();
45                    $self->{dbh}->commit;
46          }          }
47          $sql = "create table $field (          $sql = "create table $field (
48                          item varchar(255),                          item varchar(255),
# Line 48  sub delete_and_create { Line 51  sub delete_and_create {
51                          ord int,                          ord int,
52                          primary key (item,ident)                          primary key (item,ident)
53                  )";                  )";
 #       $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr();  
         $sth = $self->{dbh}->do($sql) || warn "SQL: $sql ".$self->{dbh}->errstr();  
54    
55            $self->{dbh}->begin_work;
56            $sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr();
57          $self->{dbh}->commit;          $self->{dbh}->commit;
58    
59          $self->{dbh}->begin_work;          $self->{dbh}->begin_work;
60  }  }
61    
# Line 59  sub insert { Line 63  sub insert {
63          my $self = shift;          my $self = shift;
64    
65          my $field = shift;          my $field = shift;
66          my $index_data = shift;          my $index_data = shift || print STDERR "\$index->insert($field,NULL,...)";
67          my $ident = shift;      # e.g. library id          my $ident = shift || '';        # e.g. library id
68    
69          if (! $index_data) {          if (! $index_data) {
70                  print STDERR "\$index->insert() -- no value to insert\n";                  print STDERR "\$index->insert() -- no value to insert\n";
# Line 115  sub fetch { Line 119  sub fetch {
119    
120          my @sql_args;          my @sql_args;
121    
122          my $sql = "select $what from $field";          my $sql = "select $what,ord from $field";
123    
124          if ($where) {          if ($where) {
125                  my $sql2 = " select ord from $field where upper($what) like upper(?)||'%'";                  my $sql2 = " select ord from $field where upper($what) like upper(?)||'%'";
# Line 123  sub fetch { Line 127  sub fetch {
127    
128                  $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr();                  $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr();
129                  if (my $row = $sth->fetchrow_hashref) {                  if (my $row = $sth->fetchrow_hashref) {
130                          $from_ord += $row->{ord};                          $from_ord += $row->{ord} - 1;
131                  }                  }
132          }          }
133          $sql .= " order by ord limit $rows offset $from_ord";          $sql .= " order by ord limit $rows offset $from_ord";

Legend:
Removed from v.12  
changed lines
  Added in v.19

  ViewVC Help
Powered by ViewVC 1.1.26