use ID3FS::File;
our $SCHEMA_VERSION=1;
-
my $dbfile=".id3fs";
sub new
$self->{me}=$me;
my $exists=-f $self->{dbpath};
- die("$me: $self->{dbpath}: not found. use --init to create.\n") if(!$exists && !$init);
- die("$me: --init used but $self->{dbpath} exists.\n") if($exists && $init);
- $self->{dbh}=DBI->connect("dbi:SQLite:dbname=$self->{dbpath}","","",
+ $self->{postgres}=0;
+
+ unless($self->{postgres})
+ {
+ die("$me: $self->{dbpath}: not found. use --init to create.\n") if(!$exists && !$init);
+ die("$me: --init used but $self->{dbpath} exists.\n") if($exists && $init);
+ }
+
+ my $connectstr="dbi:SQLite:dbname=$self->{dbpath}";
+ my ($user, $pass)=("", "");
+ if($self->{postgres})
+ {
+ $connectstr="dbi:Pg:dbname=id3fs";
+ $user="ianb";
+ $pass="foo";
+ }
+ $self->{dbh}=DBI->connect($connectstr, $user, $pass,
{ AutoCommit=>1 } );
unless(defined($self->{dbh}))
{
{
$self->{dbh}->do($cmd);
}
+ if($self->{postgres})
+ {
+ $self->cmd("CREATE SEQUENCE seq");
+ }
$self->cmd("INSERT INTO id3fs (schema_version) VALUES (?)", $SCHEMA_VERSION);
}
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;
- return $self->{dbh}->last_insert_id("","","","");
+ if($self->{postgres})
+ {
+ return $self->{dbh}->last_insert_id(undef, undef, undef, undef,
+ { sequence => "seq" });
+ }
+ else
+ {
+ return $self->{dbh}->last_insert_id("","","","");
+ }
}
__DATA__
CREATE TABLE id3fs (
- schema_version
+ schema_version INTEGER
);
CREATE TABLE files (
id INTEGER PRIMARY KEY,
- name
+ name text
);
CREATE TABLE artists (
id INTEGER PRIMARY KEY,
- name
+ name text
);
CREATE TABLE albums (
id INTEGER PRIMARY KEY,
- name
+ name text
);
CREATE TABLE tags (
id INTEGER PRIMARY KEY,
- name
+ name text
);
CREATE TABLE tagvals (
id INTEGER PRIMARY KEY,
- name
+ name text
);
CREATE TABLE files_x_tags (
- files_id,
- tags_id
+ files_id INTEGER,
+ tags_id INTEGER
);
CREATE TABLE tags_x_tagvals (
- tags_id,
- tagvals_id
+ tags_id INTEGER,
+ tagvals_id INTEGER
);
CREATE TABLE files_x_artists (
- files_id,
- artists_id
+ files_id INTEGER,
+ artists_id INTEGER
);
CREATE TABLE artists_x_albums (
- artists_id,
- albums_id
+ artists_id INTEGER,
+ albums_id INTEGER
);