use warnings;
use Test::More;
use Test::Exception;
+use DBIx::Class::Optional::Dependencies;
use DBIx::Class::Schema::Loader 'make_schema_at';
use DBIx::Class::Schema::Loader::Utils qw/slurp_file split_name/;
use Try::Tiny;
my ($table, $col) = @_;
return (
qq{ CREATE SEQUENCE ${table}_${col}_seq START WITH 1 INCREMENT BY 1},
- qq{
+ qq{
CREATE OR REPLACE TRIGGER ${table}_${col}_trigger
BEFORE INSERT ON ${table}
FOR EACH ROW
vendor => 'Oracle',
auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY',
auto_inc_cb => $auto_inc_cb,
- auto_inc_drop_cb => $auto_inc_drop_cb,
+ auto_inc_drop_cb => $auto_inc_drop_cb,
preserve_case_mode_is_exclusive => 1,
quote_char => '"',
+ default_is_deferrable => 0,
+ default_on_delete_clause => 'NO ACTION',
+ default_on_update_clause => 'NO ACTION',
dsn => $dsn,
user => $user,
password => $password,
'int' => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
'smallint' => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
+ # very long DEFAULT throws an ORA-24345
+ "number(15) DEFAULT to_number(decode(substrb(userenv('CLIENT_INFO'),1,1),' ',null,substrb(userenv('CLIENT_INFO'),1,10)))" => {
+ data_type => 'numeric', size => [15,0], original => { data_type => 'number' },
+ default_value => \"to_number(decode(substrb(userenv('CLIENT_INFO'),1,1),' ',null,substrb(userenv('CLIENT_INFO'),1,10)))"
+ },
+
'decimal' => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
'dec' => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
'numeric' => { data_type => 'integer', original => { data_type => 'number', size => [38,0] } },
},
extra => {
create => [
- q{
+ q{
CREATE TABLE oracle_loader_test1 (
id NUMBER(11),
value VARCHAR2(100)
},
q{ COMMENT ON TABLE oracle_loader_test1 IS 'oracle_loader_test1 table comment' },
q{ COMMENT ON COLUMN oracle_loader_test1.value IS 'oracle_loader_test1.value column comment' },
+ # 4 through 8 are used for the multi-schema tests
+ q{
+ create table oracle_loader_test9 (
+ id int primary key
+ )
+ },
+ q{
+ create table oracle_loader_test10 (
+ id int primary key,
+ nine_id int,
+ foreign key (nine_id) references oracle_loader_test9(id)
+ on delete set null deferrable
+ )
+ },
],
- drop => [qw/oracle_loader_test1/],
- count => 3 + 30 * 2,
+ drop => [qw/oracle_loader_test1 oracle_loader_test9 oracle_loader_test10/],
+ count => 7 + 31 * 2,
run => sub {
my ($monikers, $classes);
($schema, $monikers, $classes) = @_;
like $code, qr/^=head2 value\n\n(.+:.+\n)+\noracle_loader_test1\.value column comment\n\n/m,
'column comment and attrs';
+ # test on delete/update fk clause introspection
+ ok ((my $rel_info = $schema->source('OracleLoaderTest10')->relationship_info('nine')),
+ 'got rel info');
+
+ is $rel_info->{attrs}{on_delete}, 'SET NULL',
+ 'ON DELETE clause introspected correctly';
+
+ is $rel_info->{attrs}{on_update}, 'NO ACTION',
+ 'ON UPDATE clause set to NO ACTION by default';
+
+ is $rel_info->{attrs}{is_deferrable}, 1,
+ 'DEFERRABLE clause introspected correctly';
+
SKIP: {
- skip 'Set the DBICTEST_ORA_EXTRAUSER_DSN, _USER and _PASS environment variables to run the cross-schema relationship tests', 6 * 2
+ skip 'Set the DBICTEST_ORA_EXTRAUSER_DSN, _USER and _PASS environment variables to run the cross-schema relationship tests', 31 * 2
unless $ENV{DBICTEST_ORA_EXTRAUSER_DSN};
$extra_schema = $schema->clone;
)
EOF
- $dbh1->do($_) for $auto_inc_cb->('oracle_loader_test4', 'id');
+ $dbh1->do($_) for $auto_inc_cb->(lc "${schema1}.oracle_loader_test4", 'id');
$dbh1->do("GRANT ALL ON oracle_loader_test4 TO $schema2");
$dbh1->do("GRANT ALL ON oracle_loader_test4_id_seq TO $schema2");
is try { $rsrc->column_info('id')->{is_auto_increment} }, 1,
'column in schema1';
+ is try { $rsrc->column_info('id')->{sequence} }, lc "${schema1}.oracle_loader_test4_id_seq",
+ 'sequence in schema1';
+
is try { $rsrc->column_info('value')->{data_type} }, 'varchar2',
'column in schema1';
if( !$dsn || !$user ) {
$tester->skip_tests('You need to set the DBICTEST_ORA_DSN, _USER, and _PASS environment variables');
}
+elsif (!DBIx::Class::Optional::Dependencies->req_ok_for ('rdbms_oracle')) {
+ $tester->skip_tests('You need to install ' . DBIx::Class::Optional::Dependencies->req_missing_for ('rdbms_oracle'));
+}
else {
$tester->run_tests();
}