also moved some of the final "DROP TABLE" stuff into END blocks to drop them more reliably
plan tests => 5;
-DBICTest::Schema->compose_namespace('MySQLTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
-my $dbh = MySQLTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
$dbh->do("DROP TABLE IF EXISTS artist;");
#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
-MySQLTest::Artist->load_components('PK::Auto');
+# This is in Core now, but it's here just to test that it doesn't break
+$schema->class('Artist')->load_components('PK::Auto');
# test primary key handling
-my $new = MySQLTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
ok($new->artistid, "Auto-PK worked");
# test LIMIT support
for (1..6) {
- MySQLTest::Artist->create({ name => 'Artist ' . $_ });
+ $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
}
-my $it = MySQLTest::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
{ rows => 3,
offset => 2,
order_by => 'artistid' }
$test_type_info->{charfield}->{data_type} = 'VARCHAR';
}
- my $type_info = MySQLTest->schema->storage->columns_info_for('artist');
+ my $type_info = $schema->storage->columns_info_for('artist');
is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
}
# clean up our mess
-$dbh->do("DROP TABLE artist");
+END {
+ $dbh->do("DROP TABLE artist") if $dbh;
+}
use warnings;
use base 'DBIx::Class';
- __PACKAGE__->load_components(qw/PK::Auto Core/);
+ __PACKAGE__->load_components(qw/Core/);
__PACKAGE__->table('casecheck');
__PACKAGE__->add_columns(qw/id name NAME uc_name/);
__PACKAGE__->column_info_from_storage(1);
plan tests => 8;
DBICTest::Schema->load_classes( 'Casecheck' );
-DBICTest::Schema->compose_namespace('PgTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
-my $dbh = PgTest->schema->storage->dbh;
-PgTest->schema->source("Artist")->name("testschema.artist");
+my $dbh = $schema->storage->dbh;
+$schema->source("Artist")->name("testschema.artist");
$dbh->do("CREATE SCHEMA testschema;");
$dbh->do("CREATE TABLE testschema.artist (artistid serial PRIMARY KEY, name VARCHAR(100), charfield CHAR(10));");
ok ( $dbh->do('CREATE TABLE testschema.casecheck (id serial PRIMARY KEY, "name" VARCHAR(1), "NAME" VARCHAR(2), "UC_NAME" VARCHAR(3));'), 'Creation of casecheck table');
-PgTest::Artist->load_components('PK::Auto');
+# This is in Core now, but it's here just to test that it doesn't break
+$schema->class('Artist')->load_components('PK::Auto');
-my $new = PgTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
is($new->artistid, 1, "Auto-PK worked");
-$new = PgTest::Artist->create({ name => 'bar' });
+$new = $schema->resultset('Artist')->create({ name => 'bar' });
is($new->artistid, 2, "Auto-PK worked");
};
-my $type_info = PgTest->schema->storage->columns_info_for('testschema.artist');
+my $type_info = $schema->storage->columns_info_for('testschema.artist');
my $artistid_defval = delete $type_info->{artistid}->{default_value};
like($artistid_defval,
qr/^nextval\('([^\.]*\.){0,1}artist_artistid_seq'::(?:text|regclass)\)/,
is_deeply($type_info, $test_type_info,
'columns_info_for - column data types');
-my $name_info = PgTest::Casecheck->column_info( 'name' );
+my $name_info = $schema->source('Casecheck')->column_info( 'name' );
is( $name_info->{size}, 1, "Case sensitive matching info for 'name'" );
-my $NAME_info = PgTest::Casecheck->column_info( 'NAME' );
+my $NAME_info = $schema->source('Casecheck')->column_info( 'NAME' );
is( $NAME_info->{size}, 2, "Case sensitive matching info for 'NAME'" );
-my $uc_name_info = PgTest::Casecheck->column_info( 'uc_name' );
+my $uc_name_info = $schema->source('Casecheck')->column_info( 'uc_name' );
is( $uc_name_info->{size}, 3, "Case insensitive matching info for 'uc_name'" );
-$dbh->do("DROP TABLE testschema.artist;");
-$dbh->do("DROP TABLE testschema.casecheck;");
-$dbh->do("DROP SCHEMA testschema;");
+END {
+ if($dbh) {
+ $dbh->do("DROP TABLE testschema.artist;");
+ $dbh->do("DROP TABLE testschema.casecheck;");
+ $dbh->do("DROP SCHEMA testschema;");
+ }
+}
plan tests => 6;
-DBICTest::Schema->compose_namespace('OraTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
-my $dbh = OraTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
eval {
$dbh->do("DROP SEQUENCE artist_seq");
END;
});
-OraTest::Artist->load_components('PK::Auto');
-OraTest::CD->load_components('PK::Auto::Oracle');
-OraTest::Track->load_components('PK::Auto::Oracle');
+# This is in Core now, but it's here just to test that it doesn't break
+$schema->class('Artist')->load_components('PK::Auto');
+# These are compat shims for PK::Auto...
+$schema->class('CD')->load_components('PK::Auto::Oracle');
+$schema->class('Track')->load_components('PK::Auto::Oracle');
# test primary key handling
-my $new = OraTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
is($new->artistid, 1, "Oracle Auto-PK worked");
# test join with row count ambiguity
-my $cd = OraTest::CD->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' });
-my $track = OraTest::Track->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' });
-my $tjoin = OraTest::Track->search({ 'me.title' => 'Track1'},
+my $cd = $schema->resultset('CD')->create({ cdid => 1, artist => 1, title => 'EP C', year => '2003' });
+my $track = $schema->resultset('Track')->create({ trackid => 1, cd => 1, position => 1, title => 'Track1' });
+my $tjoin = $schema->resultset('Track')->search({ 'me.title' => 'Track1'},
{ join => 'cd',
rows => 2 }
);
is($tjoin->next->title, 'Track1', "ambiguous column ok");
# check count distinct with multiple columns
-my $other_track = OraTest::Track->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' });
-my $tcount = OraTest::Track->search(
+my $other_track = $schema->resultset('Track')->create({ trackid => 2, cd => 1, position => 1, title => 'Track2' });
+my $tcount = $schema->resultset('Track')->search(
{},
{
select => [{count => {distinct => ['position', 'title']}}],
# test LIMIT support
for (1..6) {
- OraTest::Artist->create({ name => 'Artist ' . $_ });
+ $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
}
-my $it = OraTest::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
{ rows => 3,
offset => 2,
order_by => 'artistid' }
is( $it->next, undef, "next past end of resultset ok" );
# clean up our mess
-$dbh->do("DROP SEQUENCE artist_seq");
-$dbh->do("DROP TABLE artist");
-$dbh->do("DROP TABLE cd");
-$dbh->do("DROP TABLE track");
+END {
+ if($dbh) {
+ $dbh->do("DROP SEQUENCE artist_seq");
+ $dbh->do("DROP TABLE artist");
+ $dbh->do("DROP TABLE cd");
+ $dbh->do("DROP TABLE track");
+ }
+}
plan tests => 6;
-DBICTest::Schema->compose_namespace('DB2Test' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
-my $dbh = DB2Test->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
$dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
$dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10));");
-#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
-
-DB2Test::Artist->load_components('PK::Auto');
+# This is in core, just testing that it still loads ok
+$schema->class('Artist')->load_components('PK::Auto');
# test primary key handling
-my $new = DB2Test::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
ok($new->artistid, "Auto-PK worked");
# test LIMIT support
for (1..6) {
- DB2Test::Artist->create({ name => 'Artist ' . $_ });
+ $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
}
-my $it = DB2Test::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
{ rows => 3,
order_by => 'artistid'
}
};
-my $type_info = DB2Test->schema->storage->columns_info_for('artist');
+my $type_info = $schema->storage->columns_info_for('artist');
is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
-
-
# clean up our mess
-$dbh->do("DROP TABLE artist");
-
+END {
+ $dbh->do("DROP TABLE artist") if $dbh;
+}
plan tests => 6;
-DBICTest::Schema->compose_namespace('DB2Test' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
-my $dbh = DB2Test->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
$dbh->do("DROP TABLE artist", { RaiseError => 0, PrintError => 0 });
$dbh->do("CREATE TABLE artist (artistid INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(255), charfield CHAR(10))");
-DB2Test::Artist->load_components('PK::Auto');
+# Just to test loading, already in Core
+$schema->class('Artist')->load_components('PK::Auto');
# test primary key handling
-my $new = DB2Test::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
ok($new->artistid, "Auto-PK worked");
# test LIMIT support
for (1..6) {
- DB2Test::Artist->create({ name => 'Artist ' . $_ });
+ $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
}
-my $it = DB2Test::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
{ rows => 3,
order_by => 'artistid'
}
};
-my $type_info = DB2Test->schema->storage->columns_info_for('artist');
+my $type_info = $schema->storage->columns_info_for('artist');
is_deeply($type_info, $test_type_info, 'columns_info_for - column data types');
-
-
# clean up our mess
-$dbh->do("DROP TABLE artist");
+END {
+ $dbh->do("DROP TABLE artist") if $dbh;
+}
$storage_type = '::DBI::Sybase::MSSQL' if $dsn =~ /^dbi:Sybase:/;
# Add more for others in the future when they exist (ODBC? ADO? JDBC?)
-DBICTest::Schema->storage_type($storage_type);
-DBICTest::Schema->compose_namespace( 'MSSQLTest' => $dsn, $user, $pass );
+my $schema = DBICTest::Schema->clone;
+$schema->storage_type($storage_type);
+$schema->connection($dsn, $user, $pass);
-my $dbh = MSSQLTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
$dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL
DROP TABLE artist");
$dbh->do("CREATE TABLE artist (artistid INT IDENTITY PRIMARY KEY, name VARCHAR(255));");
-MSSQLTest::Artist->load_components('PK::Auto::MSSQL');
+# Just to test compat shim, Auto is in Core
+$schema->class('Artist')->load_components('PK::Auto::MSSQL');
# Test PK
-my $new = MSSQLTest::Artist->create( { name => 'foo' } );
+my $new = $schema->resultset('Artist')->create( { name => 'foo' } );
ok($new->artistid, "Auto-PK worked");
# Test LIMIT
for (1..6) {
- MSSQLTest::Artist->create( { name => 'Artist ' . $_ } );
+ $schema->resultset('Artist')->create( { name => 'Artist ' . $_ } );
}
-my $it = MSSQLTest::Artist->search( { },
+my $it = $schema->resultset('Artist')->search( { },
{ rows => 3,
offset => 2,
order_by => 'artistid'
$it->next;
is( $it->next, undef, "next past end of resultset ok" );
+# clean up our mess
+END {
+ $dbh->do("IF OBJECT_ID('artist', 'U') IS NOT NULL DROP TABLE artist")
+ if $dbh;
+}
$INC{'DBIx/Class/Storage/DBI/MySQLNoBindVars.pm'} = 1;
}
-DBICTest::Schema->storage(undef); # just in case?
-DBICTest::Schema->storage_type('::DBI::MySQLNoBindVars');
-DBICTest::Schema->compose_namespace('MySQLTest' => $dsn, $user, $pass);
+my $schema = DBICTest::Schema->clone;
+$schema->storage_type('::DBI::MySQLNoBindVars');
+$schema->connection($dsn, $user, $pass);
-my $dbh = MySQLTest->schema->storage->dbh;
+my $dbh = $schema->storage->dbh;
$dbh->do("DROP TABLE IF EXISTS artist;");
$dbh->do("CREATE TABLE artist (artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), charfield CHAR(10));");
-#'dbi:mysql:host=localhost;database=dbic_test', 'dbic_test', '');
-
-MySQLTest::Artist->load_components('PK::Auto');
+$schema->class('Artist')->load_components('PK::Auto');
# test primary key handling
-my $new = MySQLTest::Artist->create({ name => 'foo' });
+my $new = $schema->resultset('Artist')->create({ name => 'foo' });
ok($new->artistid, "Auto-PK worked");
# test LIMIT support
for (1..6) {
- MySQLTest::Artist->create({ name => 'Artist ' . $_ });
+ $schema->resultset('Artist')->create({ name => 'Artist ' . $_ });
}
-my $it = MySQLTest::Artist->search( {},
+my $it = $schema->resultset('Artist')->search( {},
{ rows => 3,
offset => 2,
order_by => 'artistid' }
is( $it->next, undef, "next past end of resultset ok" );
# clean up our mess
-$dbh->do("DROP TABLE artist");
+END {
+ $dbh->do("DROP TABLE artist");
+}