--- trunk/index_DBI.pm 2003/01/22 22:27:19 12 +++ trunk/index_DBI.pm 2003/02/23 07:07:33 28 @@ -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 (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(); + $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,10 +51,11 @@ 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(); + $self->{dbh}->begin_work; + $sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr(); $self->{dbh}->commit; + $self->{dbh}->begin_work; } @@ -59,8 +63,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"; @@ -78,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 { @@ -115,7 +120,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 +128,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"; @@ -149,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();