--- trunk/index_DBI.pm 2003/02/22 21:37:25 18 +++ trunk/index_DBI.pm 2003/03/15 19:37:07 37 @@ -31,15 +31,18 @@ my $field = shift; +#print "#### delete_and_create($field)\n"; + $self->{dbh}->commit; - $self->{dbh}->begin_work; 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 ($sth->execute() && $sth->fetchrow_hashref) { my $sql = "drop table $field"; + $self->{dbh}->begin_work; my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr(); + $self->{dbh}->commit; } $sql = "create table $field ( item varchar(255), @@ -48,9 +51,11 @@ ord int, primary key (item,ident) )"; - $sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr(); + $self->{dbh}->begin_work; + $sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr(); $self->{dbh}->commit; + $self->{dbh}->begin_work; } @@ -77,6 +82,7 @@ if (! $sth->fetchrow_hashref) { my $sql = "insert into $field (item,ident,count) values (?,?,?)"; my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr(); + $index_data = substr($index_data,0,255); $sth->execute($index_data,$ident,1) || die "sql: $sql; ".$self->{dbh}->errstr(); #print stderr "in index: $index_data\n"; } else { @@ -131,7 +137,7 @@ $sth->execute() || die "execute: $sql; ".$self->{dbh}->errstr(); my @arr; while (my $row = $sth->fetchrow_hashref) { - $row->{item} = HTML::Entities::encode($row->{item}); + $row->{item} = HTML::Entities::encode($row->{item},'<>&"'); push @arr,$row; } return @arr; @@ -148,7 +154,7 @@ $self->{dbh}->begin_work || die $self->{dbh}->errstr(); - my $sql = "select oid from $table order by item"; + my $sql = "select oid from $table order by upper(item)"; my $sth = $self->{dbh}->prepare($sql) || die "sql: $sql; ".$self->{dbh}->errstr(); $sql = "update $table set ord=? where oid=?"; my $sth_update = $self->{dbh}->prepare($sql) || die "sql: $sql; ".$self->{dbh}->errstr();