$self->{absbase}=Cwd::abs_path($self->{base});
my $connectstr="dbi:SQLite:dbname=$self->{dbpath}";
- my ($user, $pass)=("", "");
- if($self->{postgres})
- {
- $connectstr="dbi:Pg:dbname=id3fs";
- $user="ianb";
- $pass="foo";
- }
my $exists=-f $self->{dbpath};
- $self->{dbh}=DBI->connect($connectstr, $user, $pass,
+ $self->{dbh}=DBI->connect($connectstr, undef, undef,
{ AutoCommit=>1 } );
unless(defined($self->{dbh}))
{
{
$self->{dbh}->do($cmd);
}
- if($self->{postgres})
- {
- $self->cmd("CREATE SEQUENCE seq");
- }
- else
- {
- my %indexes=( "idx_files_id" => "files (id)",
- "idx_fxt_both" => "files_x_tags (files_id, tags_id)",
- "idx_fxt_files" => "files_x_tags (files_id)",
- "idx_fxt_tags" => "files_x_tags (tags_id)",
- "idx_tags_id" => "tags (id)",
- "idx_tags_name" => "tags (name)");
- for my $index (keys %indexes)
- {
- $self->{dbh}->do("CREATE INDEX $index ON " . $indexes{$index});
- }
- }
$self->cmd("INSERT INTO id3fs (schema_version, last_update) VALUES (?, ?)",
$SCHEMA_VERSION, time());
}
unless(defined($id))
{
my $sql="INSERT INTO $table (";
- $sql .= "id, " if($self->{postgres});
my @fields=qw(name);
if(defined($extradata))
{
}
$sql .= join(", ", @fields);
$sql .=") VALUES (";
- $sql .=") nextval('seq'), " if($self->{postgres});
$sql .= join(", ", map { "?"; } @fields);
$sql .= ");";
$id=$self->cmd_id($sql, $name, map { $extradata->{$_} || ""; } sort keys %$extradata);
sub last_insert_id
{
my $self=shift;
- if($self->{postgres})
- {
- return $self->{dbh}->last_insert_id(undef, undef, undef, undef,
- { sequence => "seq" });
- }
- else
- {
- return $self->{dbh}->last_insert_id("","","","");
- }
+ return $self->{dbh}->last_insert_id("","","","");
}
sub lookup_id
FOREIGN KEY(tags_id) REFERENCES tags(id) ON DELETE CASCADE ON UPDATE CASCADE
);
+CREATE INDEX idx_files_id ON files (id)
+
+CREATE INDEX idx_fxt_both ON files_x_tags (files_id, tags_id)
+
+CREATE INDEX idx_fxt_files ON files_x_tags (files_id)
+
+CREATE INDEX idx_fxt_tags ON files_x_tags (tags_id)
+
+CREATE INDEX idx_tags_id ON tags (id)
+
+CREATE INDEX idx_tags_name ON tags (name)
+