--- trunk/index_DBI_cache.pm 2004/01/31 20:57:48 206 +++ trunk2/lib/WebPac/Index.pm 2004/06/13 20:20:29 348 @@ -6,12 +6,13 @@ # library). But, that functionality is not used anyway... # -package index_DBI; +package WebPac::Index; use strict qw(vars); use vars qw($Count); use HTML::Entities; use URI::Escape; use locale; +use Carp; use DBI; @@ -36,20 +37,25 @@ sub new { my $class = shift; - my $self = {}; + my $self = {@_}; bless($self, $class); - my $dbd = shift || die "need dbi_dbd= in [global] section of configuration file"; - my $dsn = shift || die "need dbi_dsn= in [global] section of configuration file"; - my $user = shift || die "need dbi_user= in [global] section of configuration file"; - my $passwd = shift || die "need dbi_passwd= in [global] section of configuration file"; + croak "need dbd" if (! $self->{dbd}); + croak "need dsn" if (! $self->{dsn}); + croak "need user" if (! $self->{user}); + croak "need passwd" if (! $self->{passwd}); - $self->{dbd} = $dbd; - - $self->{dbh} = DBI->connect("DBI:$dbd:$dsn",$user,$passwd) || die $DBI::errstr; + $self->{dbh} = DBI->connect("DBI:$self->{dbd}:$self->{dsn}",$self->{user},$self->{passwd}) || die $DBI::errstr; $Count++; - $self->bench("connected to $dbd as $user"); + $self->bench("connected to $self->{dbd} as $self->{user}"); + + # force SQLite to support binary 0 in data (which shouldn't + # happend, but it did to me) + eval { + no warnings 'all'; + $self->{dbh}->{sqlite_handle_binary_nulls} = 1; + }; return $self; } @@ -66,7 +72,7 @@ # FIX: this is not a good way to check if table exists! 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) || warn "SQL: $sql - ".$sth->errstr(); } $sql = "create table $field ( item varchar(255), @@ -195,10 +201,10 @@ $self->{dbh}->begin_work || die $self->{dbh}->errstr(); - $self->bench("Sorting ".$Table{$table}." items in $table"); + $self->bench("Sorting ".$Table{$table}." (with duplicates) items in $table"); my @keys = sort keys %{$c_table->{$table}}; - $self->bench("Dumping data into $table"); + $self->bench("Dumping ".($#keys+1)." items into $table"); my $sql = "insert into $table (ord,item,display,count) values (?,?,?,?)"; my $sth = $self->{dbh}->prepare($sql) || die "sql: $sql; ".$self->{dbh}->errstr();