31 |
|
|
32 |
my $field = shift; |
my $field = shift; |
33 |
|
|
34 |
|
#print "#### delete_and_create($field)\n"; |
35 |
|
|
36 |
$self->{dbh}->commit; |
$self->{dbh}->commit; |
|
$self->{dbh}->begin_work; |
|
37 |
|
|
38 |
my $sql = "select count(*) from $field"; |
my $sql = "select count(*) from $field"; |
39 |
my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr(); |
my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr(); |
40 |
# FIX: this is not a good way to check if table exists! |
# FIX: this is not a good way to check if table exists! |
41 |
if ($sth->execute() && $sth->fetchrow_hashref) { |
if ($sth->execute() && $sth->fetchrow_hashref) { |
42 |
my $sql = "drop table $field"; |
my $sql = "drop table $field"; |
43 |
|
$self->{dbh}->begin_work; |
44 |
my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr(); |
my $sth = $self->{dbh}->do($sql) || die "SQL: $sql ".$self->{dbh}->errstr(); |
45 |
|
$self->{dbh}->commit; |
46 |
} |
} |
47 |
$sql = "create table $field ( |
$sql = "create table $field ( |
48 |
item varchar(255), |
item varchar(255), |
51 |
ord int, |
ord int, |
52 |
primary key (item,ident) |
primary key (item,ident) |
53 |
)"; |
)"; |
|
$sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr(); |
|
54 |
|
|
55 |
|
$self->{dbh}->begin_work; |
56 |
|
$sth = $self->{dbh}->do($sql); # || warn "SQL: $sql ".$self->{dbh}->errstr(); |
57 |
$self->{dbh}->commit; |
$self->{dbh}->commit; |
58 |
|
|
59 |
$self->{dbh}->begin_work; |
$self->{dbh}->begin_work; |
60 |
} |
} |
61 |
|
|
82 |
if (! $sth->fetchrow_hashref) { |
if (! $sth->fetchrow_hashref) { |
83 |
my $sql = "insert into $field (item,ident,count) values (?,?,?)"; |
my $sql = "insert into $field (item,ident,count) values (?,?,?)"; |
84 |
my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr(); |
my $sth = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr(); |
85 |
|
$index_data = substr($index_data,0,255); |
86 |
$sth->execute($index_data,$ident,1) || die "sql: $sql; ".$self->{dbh}->errstr(); |
$sth->execute($index_data,$ident,1) || die "sql: $sql; ".$self->{dbh}->errstr(); |
87 |
#print stderr "in index: $index_data\n"; |
#print stderr "in index: $index_data\n"; |
88 |
} else { |
} else { |
154 |
|
|
155 |
$self->{dbh}->begin_work || die $self->{dbh}->errstr(); |
$self->{dbh}->begin_work || die $self->{dbh}->errstr(); |
156 |
|
|
157 |
my $sql = "select oid from $table order by item"; |
my $sql = "select oid from $table order by upper(item)"; |
158 |
my $sth = $self->{dbh}->prepare($sql) || die "sql: $sql; ".$self->{dbh}->errstr(); |
my $sth = $self->{dbh}->prepare($sql) || die "sql: $sql; ".$self->{dbh}->errstr(); |
159 |
$sql = "update $table set ord=? where oid=?"; |
$sql = "update $table set ord=? where oid=?"; |
160 |
my $sth_update = $self->{dbh}->prepare($sql) || die "sql: $sql; ".$self->{dbh}->errstr(); |
my $sth_update = $self->{dbh}->prepare($sql) || die "sql: $sql; ".$self->{dbh}->errstr(); |