Work around patch
=================
I've attached a diff -u patch script of a work-around ... I've replaced
the init method within RDF::Trine::Store::DBI::Pg with a copy of the
RDF::Trine::Store::DBI init method, and changed the table names ... this
is probably not the most elegant of solutions, but it was quick to
implement :)
On Mon Oct 24 09:11:41 2011, JOHNW wrote:
Show quoted text> Symptoms
> ========
> It may be that I don't know enough about how the author sets up their
> postgres database; however the database table creation works and the
> library runs on first use, and fails their after (stoping and starting
> the code that runs RDF::Trine). The only way to successfully run the
> code a second time is to drop the tables and start again.
>
>
> Diagnosis
> =========
> The _table_exists method doesn't find any of the tables, as it is
> looking for the title-case version of the table names, and postgres has
> created the lower-case named tables.
>
> When the tables are renamed to be fully-lower-case, then _table_exists
> method correctly works: however the other SQL statements fail.
>
>
> Proposal
> ========
> There are two strategies that immediately occur:
>
> * move the entire library to use only lower-case names
> * employ SQL::Translator to generate the SQL
>
> My gut feeling is that SQL::Translator is the stronger solution as it
> will cope better with corner-cases.
>
> I'm happy and able to help with whatever the desired solution is, but I
> feel that it's the maintainer's right to choose. I like the look of
> RDF::Trine - it looks like it will be a great solution to an aspect of
> my current project :)
>
>
> Extra Info
> ==========
> /usr/lib/postgresql/8.4/bin/postgres --version
> postgres (PostgreSQL) 8.4.9
--- /usr/local/share/perl/5.10.1/RDF/Trine/Store/DBI/Pg.pm 2011-10-24 14:59:32.000000000 +0100
+++ /tmp/new.sql 2011-10-24 15:05:22.000000000 +0100
@@ -75,6 +75,60 @@
return $col;
}
+sub init {
+ my $self = shift;
+ my $dbh = $self->dbh;
+ my $name = $self->model_name;
+ my $id = RDF::Trine::Store::DBI::_mysql_hash( $name );
+ my $l = Log::Log4perl->get_logger("rdf.trine.store.dbi");
+
+ unless ($self->_table_exists("literals")) {
+ $dbh->begin_work;
+ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return undef };
+ CREATE TABLE literals (
+ ID NUMERIC(20) PRIMARY KEY,
+ Value text NOT NULL,
+ Language text NOT NULL DEFAULT '',
+ Datatype text NOT NULL DEFAULT ''
+ );
+END
+ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return undef };
+ CREATE TABLE resources (
+ ID NUMERIC(20) PRIMARY KEY,
+ URI text NOT NULL
+ );
+END
+ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return undef };
+ CREATE TABLE bnodes (
+ ID NUMERIC(20) PRIMARY KEY,
+ Name text NOT NULL
+ );
+END
+ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return undef };
+ CREATE TABLE models (
+ ID NUMERIC(20) PRIMARY KEY,
+ Name text NOT NULL
+ );
+END
+
+ $dbh->commit or warn $dbh->errstr;
+ }
+
+ unless ($self->_table_exists("statements${id}")) {
+ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); return undef };
+ CREATE TABLE statements${id} (
+ Subject NUMERIC(20) NOT NULL,
+ Predicate NUMERIC(20) NOT NULL,
+ Object NUMERIC(20) NOT NULL,
+ Context NUMERIC(20) NOT NULL DEFAULT 0,
+ PRIMARY KEY (Subject, Predicate, Object, Context)
+ );
+END
+# $dbh->do( "DELETE FROM Models WHERE ID = ${id}") || do { $l->trace( $dbh->errstr ); $dbh->rollback; return undef };
+ $dbh->do( "INSERT INTO Models (ID, Name) VALUES (${id}, ?)", undef, $name );
+ }
+
+}
1; # Magic true value required at end of module