--- trunk/index_DBI.pm 2003/01/22 22:27:19 12 +++ trunk/index_DBI.pm 2003/02/22 21:37:25 18 @@ -37,9 +37,9 @@ my $sql = "select count(*) from $field"; my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr(); # FIX: this is not a good way to check if table exists! - if (1 || $sth->execute() && $sth->fetchrow_hashref) { + if ($sth->execute() && $sth->fetchrow_hashref) { my $sql = "drop table $field"; -# my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr(); + my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr(); } $sql = "create table $field ( item varchar(255), @@ -48,8 +48,7 @@ ord int, primary key (item,ident) )"; -# $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr(); - $sth = $self->{dbh}->do($sql) || warn "SQL: $sql ".$self->{dbh}->errstr(); + $sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr(); $self->{dbh}->commit; $self->{dbh}->begin_work; @@ -59,8 +58,8 @@ my $self = shift; my $field = shift; - my $index_data = shift; - my $ident = shift; # e.g. library id + my $index_data = shift || print STDERR "\$index->insert($field,NULL,...)"; + my $ident = shift || ''; # e.g. library id if (! $index_data) { print STDERR "\$index->insert() -- no value to insert\n"; @@ -115,7 +114,7 @@ my @sql_args; - my $sql = "select $what from $field"; + my $sql = "select $what,ord from $field"; if ($where) { my $sql2 = " select ord from $field where upper($what) like upper(?)||'%'"; @@ -123,7 +122,7 @@ $sth->execute($where) || die "sql2: $sql2; ".$self->{dbh}->errstr(); if (my $row = $sth->fetchrow_hashref) { - $from_ord += $row->{ord}; + $from_ord += $row->{ord} - 1; } } $sql .= " order by ord limit $rows offset $from_ord";