# Koha modules
use C4::Database;
-#use C4::Catalogue;
-use C4::Acquisitions;
-use C4::Output;
-my %tables;
+my %existingtables; # tables already in database
my %types;
+my $table;
+
+#-------------------
+# Defines
+
+# Tables to add if they don't exist
+my %requiretables=(
+ shelfcontents=>"( shelfnumber int not null,
+ itemnumber int not null,
+ flags int)",
+ bookshelf=>"( shelfnumber int auto_increment primary key,
+ shelfname char(255))",
+ z3950queue=>"( id int auto_increment primary key,
+ term text,
+ type char(10),
+ startdate int,
+ enddate int,
+ done smallint,
+ results longblob,
+ numrecords int,
+ servers text,
+ identifier char(30))",
+ z3950results=>"( id int auto_increment primary key,
+ queryid int,
+ server char(255),
+ startdate int,
+ enddate int,
+ results longblob,
+ numrecords int,
+ numdownloaded int,
+ highestseen int,
+ active smallint)",
+ branchrelations=>"( branchcode varchar(4),
+ categorycode varchar(4))",
+);
#-------------------
# Initialize
my $sth=$dbh->prepare("show tables");
$sth->execute;
while (my ($table) = $sth->fetchrow) {
- $tables{$table}=1;
+ $existingtables{$table}=1;
}
# Now add any missing tables
-
-# Add tables for virtual bookshelf management
-unless ($tables{'shelfcontents'}) {
- print "Adding shelfcontents table...\n";
- my $sti=$dbh->prepare("create table shelfcontents (
- shelfnumber int not null,
- itemnumber int not null,
- flags int)");
- $sti->execute;
-}
-unless ($tables{'bookshelf'}) {
- print "Adding bookshelf table...\n";
- my $sti=$dbh->prepare("create table bookshelf (
- shelfnumber int auto_increment primary key,
- shelfname char(255))");
- $sti->execute;
-}
-
-# Add tables required by Z-3950 scripts
-
-unless ($tables{'z3950queue'}) {
- print "Adding z3950queue table...\n";
- my $sti=$dbh->prepare("create table z3950queue (
- id int auto_increment primary key,
- term text,
- type char(10),
- startdate int,
- enddate int,
- done smallint,
- results longblob,
- numrecords int,
- servers text,
- identifier char(30))");
- $sti->execute;
-}
-
-unless ($tables{'z3950results'}) {
- print "Adding z3950results table...\n";
- my $sti=$dbh->prepare("create table z3950results (
- id int auto_increment primary key,
- queryid int,
- server char(255),
- startdate int,
- enddate int,
- results longblob,
- numrecords int,
- numdownloaded int,
- highestseen int,
- active smallint)");
- $sti->execute;
-}
-unless ($tables{'z3950servers'}) {
+foreach $table ( keys %requiretables ) {
+ unless ($existingtables{$table} ) {
+ print "Adding $table table...\n";
+ my $sth=$dbh->prepare(
+ "create table $table $requiretables{$table}" );
+ $sth->execute;
+ if ($sth->err) {
+ print "Error : $sth->errstr \n";
+ $sth->finish;
+ } # if error
+ } # unless exists
+} # foreach
+exit;
+
+unless ($existingtables{'z3950servers'}) {
print "Adding z3950servers table...\n";
my $sti=$dbh->prepare("create table z3950servers (
host char(255),
$sti->execute;
}
-# Create new branchrelations table if it doesnt already exist....
-unless ($tables{'branchrelations'} ) {
- print "creating branchrelations table\n";
- my $sth=$dbh->prepare("create table branchrelations (
- branchcode varchar(4),
- categorycode varchar(4))");
- $sth->execute;
-}
-
#---------------------------------
# Columns