68 |
my $sql_delete = "delete from $index"; |
my $sql_delete = "delete from $index"; |
69 |
my $sth = $self->{dbh}->prepare($sql_delete) || confess "can't prepare: $sql_delete"; |
my $sth = $self->{dbh}->prepare($sql_delete) || confess "can't prepare: $sql_delete"; |
70 |
|
|
71 |
unless ($sth->execute()) { |
if ($sth->execute()) { |
72 |
|
print STDERR "## deleted rows from table $index\n" if ($debug); |
73 |
|
} else { |
74 |
# can't delete from table, assume it doesn't exists! |
# can't delete from table, assume it doesn't exists! |
75 |
$self->{dbh}->rollback; |
$self->{dbh}->rollback; |
76 |
$self->{dbh}->do($sql) || confess "SQL: $sql ".$self->{dbh}->errstr(); |
$self->{dbh}->do($sql) || confess "SQL: $sql ".$self->{dbh}->errstr(); |
85 |
my $field = shift; |
my $field = shift; |
86 |
my $index_data = shift || print STDERR "\$index->insert($field,NULL,...)"; |
my $index_data = shift || print STDERR "\$index->insert($field,NULL,...)"; |
87 |
my $display = shift || $index_data; |
my $display = shift || $index_data; |
88 |
my $tag = shift; |
my $filter = shift; |
89 |
|
|
90 |
if (! $index_data) { |
if (! $index_data) { |
91 |
print STDERR "\$index->insert() -- no value to insert\n"; |
print STDERR "\$index->insert() -- no value to insert\n"; |
108 |
} |
} |
109 |
|
|
110 |
$self->{c}->{$uc}->{$field}->{count}++; |
$self->{c}->{$uc}->{$field}->{count}++; |
111 |
$self->{c}->{$uc}->{$field}->{tag}->{$tag}++ if ($tag); |
$self->{c}->{$uc}->{$field}->{filter}->{$filter}++ if ($filter); |
112 |
} |
} |
113 |
|
|
114 |
sub count { |
sub count { |
209 |
); |
); |
210 |
}); |
}); |
211 |
|
|
212 |
$self->delete_and_create('tags', qq{ |
$self->delete_and_create('filters', qq{ |
213 |
create table tags ( |
create table filters ( |
214 |
tag varchar(255), |
filter varchar(255), |
215 |
ord int, |
ord int, |
216 |
count int, |
count int, |
217 |
primary key (tag,ord) |
primary key (filter,ord) |
218 |
); |
); |
219 |
}); |
}); |
220 |
|
|
226 |
my $sql = "insert into index (name,ord,item,display,count) values (?,?,?,?,?)"; |
my $sql = "insert into index (name,ord,item,display,count) values (?,?,?,?,?)"; |
227 |
my $sth_index = $self->{dbh}->prepare($sql) || confess "$sql: ".$self->{dbh}->errstr(); |
my $sth_index = $self->{dbh}->prepare($sql) || confess "$sql: ".$self->{dbh}->errstr(); |
228 |
|
|
229 |
$sql = "insert into tags (tag, ord, count) values (?,?,?)"; |
$sql = "insert into filters (filter, ord, count) values (?,?,?)"; |
230 |
my $sth_tag = $self->{dbh}->prepare($sql) || confess "$sql: ".$self->{dbh}->errstr(); |
my $sth_filter = $self->{dbh}->prepare($sql) || confess "$sql: ".$self->{dbh}->errstr(); |
231 |
|
|
232 |
my $ord = 0; |
my $ord = 0; |
233 |
foreach my $key (@items) { |
foreach my $key (@items) { |
242 |
$self->{c}->{$key}->{$field}->{count}, |
$self->{c}->{$key}->{$field}->{count}, |
243 |
); |
); |
244 |
|
|
245 |
# store tags |
# store filters |
246 |
next unless ($self->{c}->{$key}->{$field}->{tag}); |
next unless ($self->{c}->{$key}->{$field}->{filter}); |
247 |
|
|
248 |
foreach my $tag (keys %{$self->{c}->{$key}->{$field}->{tag}}) { |
foreach my $filter (keys %{$self->{c}->{$key}->{$field}->{filter}}) { |
249 |
$sth_tag->execute( $tag, $ord, $self->{c}->{$key}->{$field}->{tag}->{$tag} ); |
$sth_filter->execute( $filter, $ord, $self->{c}->{$key}->{$field}->{filter}->{$filter} ); |
250 |
} |
} |
251 |
} |
} |
252 |
|
|