[prev] [thread] [next] [Date index for 2005/02/13]
I wanted to make some changes in CDBI::Loader, see if I could
make mixed-case relationship names work.
I decided that more thorough testing was in order to know if I broke
anything. I also wanted to test against the forthcoming release of DBD::Pg
.
While the main part of my test script does work (tests 1..10 pass), it
hangs at the finish
using DBD::Pg 1.32, Postgresql 7.3.8-3 (SuSE-supplied RPM on SuSE 9.0).
ps ax shows
postgres: dhudes test [local] DROP TABLE waiting
postgres: dhudes test [local] idle in transaction
Of even more interest is that DBD::Pg developer release breaks existing
Class::DBI applications (as well as the developer release requiring a
minor tweak to Class::DBI::Loader::Pg for the version checking).
The new DBD::Pg returns table names qualified by the schema.
So 'artist' becomes 'public.artist' .
attempting to get a table 'artist' won't work (with Postgresql 7.3.8 at
least).
Here's my test script for Class::DBI::Loader for postgresql databases:
use strict;
my $numtests;
BEGIN {
$numtests =10;
}
use Test::More tests => $numtests;
use Class::DBI::Loader qw/debug/;
use DBI;
my $dbh;
my $database = $ENV{PG_NAME};
my $user = $ENV{PG_USER};
my $password = $ENV{PG_PASS};
SKIP: {
eval { require Class::DBI::Pg; };
skip "Class::DBI::Pg is not installed", $numtests if $@;
skip
'You need to set the PG_NAME, PG_USER and PG_PASS environment variables',
$numtests
unless ( $database && $user );
my $dsn = "dbi:Pg:dbname=$database";
$dbh = DBI->connect(
$dsn, $user,
$password,
{
RaiseError => 1,
PrintError => 1,
AutoCommit => 1
}
);
#setup the Class:DBI example
$dbh->do(<<'SQL');
CREATE TABLE Artist (
artistid SERIAL PRIMARY KEY,
name VARCHAR(64)
)
SQL
$dbh->do(<<'SQL');
CREATE TABLE CD (
cdid SERIAL PRIMARY KEY,
artist INTEGER NOT NULL,
title VARCHAR(64),
year INTEGER,
FOREIGN KEY (artist) references Artist(artistid) ON DELETE CASCADE
)
SQL
$dbh->do(<<'SQL');
CREATE TABLE Track (
trackid SERIAL NOT NULL PRIMARY KEY,
cd INTEGER ,
position INTEGER,
TITLE VARCHAR(64),
FOREIGN KEY (cd) REFERENCES CD(cdid) ON DELETE CASCADE
)
SQL
my $loader = Class::DBI::Loader->new(
dsn => $dsn,
user => $user,
password => $password,
namespace => 'Music',
relationships => 1
);
my @classes = $loader->classes;
my @tables = $loader->tables;
use Data::Dumper;
# diag( Dumper(@classes));
diag( Dumper(@tables));
is( $loader->find_class("artist"),"Music::Artist");
is( $loader->find_class("cd"),"Music::Cd");
isnt( $loader->find_class("Track"),"Music::Track");
is ( $loader->find_class("track"),"Music::Track");
my $artist = Music::Artist->create(
{
#artistid => 1,
name => 'U2'
});
ok(defined $artist);
is($artist->name,"U2");
is($artist->artistid,1);
my $cd = $artist->add_to_cds({
# cdid => 1,
title => 'October',
year => 1980,
});
# Oops, got it wrong.
$cd->year(1981);
$cd->update;
is($cd->year,1981);
my $track = $cd->add_to_tracks( {
position =>1,
title =>"Life is Random"
});
is($track->position,1);
ok($cd->delete);
}
END {
if ($dbh) {
$dbh->do("DROP TABLE Track CASCADE;");
$dbh->do("DROP TABLE CD CASCADE;");
$dbh->do("DROP TABLE Artist CASCADE;");
$dbh->disconnect;
}
}
_______________________________________________
Dbdpg-general mailing list
Dbdpg-general@xxxxx.xxxxxxxxxx.xxx
http://gborg.postgresql.org/mailman/listinfo/dbdpg-general
|
Expanded test for Class::DBI::Loader (fwd)
|
Generated at 17:31 on 15 Feb 2005 by mariachi v0.52