#/usr/bin/env perl

use strict;
use DBI;

### configure variables below  ###
my $dbfile='eftattr.sqlite';

### codes after here
if(-e $dbfile) {
	print STDERR "Database '$dbfile' already exists.\n";
	print STDERR "If you intended to clear up and initialize the existing database,\n";
	print STDERR "please remove '$dbfile' and try again.\n";
	exit 1;
}

my $datasourcename = "dbi:SQLite:dbname=$dbfile";
my $databasehandle = DBI->connect($datasourcename,"","");
$databasehandle->{RaiseError} = 1;
eval {
    my $create_table = $databasehandle->prepare("create table eftattr(id integer unique primary key, attr varchar);");
    $create_table->execute();
    my $create_index = $databasehandle->prepare("create index eftattr_id_index on eftattr(id);");
    $create_index->execute();
};
if($@) {
    print STDERR "Error occurred while database initialization.\n";
    print STDERR "Note that incomplete database was left.\n";
    print STDERR "ERROR MESSAGE: $DBI::errstr";
}
