Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the RDF-Trine CPAN distribution.

Report information
The Basics
Id: 71890
Status: patched
Priority: 0/
Queue: RDF-Trine

People
Owner: Nobody in particular
Requestors: johnw [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.136
Fixed in: (no value)



Subject: RDF::Trine::Store::DBI::Pg seems to fail due to capitalisation of table names
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
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
Subject: Pg.pm.patch
--- /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
Hi John, Thanks for the report. Sorry for the trouble you're having. I admit the postgres code hasn't gotten much attention lately, and it seems some of it has bitrotted as I don't have postgres installed on my primary development machine. I'll look into your patch and see about getting the problem fixed. Show quoted text
> Proposal > ======== > There are two strategies that immediately occur: > > * move the entire library to use only lower-case names
I don't think this can be done, because the schema is meant to be compatible with the Redland library which uses case sensitive table names on mysql. Show quoted text
> * employ SQL::Translator to generate the SQL
I'll look into this is a possible future solution, but in the short term will likely use your supplied patch as a quick-fix. thanks again, greg williams
Hi! FWIW, I have applied the patch to my tree and there's a pull request: https://github.com/kasei/perlrdf/pull/44 (I wasn't able to focus on my own stuff, so I decided to just do something :-) ) Cheers, Kjetil
I've added the tests now, and they have been merged into master by Greg, so you could check it out from github and verify it if you'd like. Kjetil
Applied in github, this will appear in the next RDF::Trine release (0.139).