DBIx::Class::Schema::Loader currently supports only the DBI storage type. It
has explicit support for L<DBD::Pg>, L<DBD::mysql>, L<DBD::DB2>,
-L<DBD::SQLite>, L<DBD::Sybase>, L<DBD::ODBC> (for MSSQL) and L<DBD::Oracle>.
-Other DBI drivers may function to a greater or lesser degree with this loader,
-depending on how much of the DBI spec they implement, and how standard their
-implementation is.
+L<DBD::SQLite>, L<DBD::Sybase> (for Sybase ASE and MSSSQL), L<DBD::ODBC> (for
+MSSQL) and L<DBD::Oracle>. Other DBI drivers may function to a greater or
+lesser degree with this loader, depending on how much of the DBI spec they
+implement, and how standard their implementation is.
Patches to make other DBDs work correctly welcome.
--- /dev/null
+package DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault;
+
+use strict;
+use warnings;
+use Class::C3;
+
+our $VERSION = '0.05000';
+
+=head1 NAME
+
+DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault -- Loader Component
+to parse quoted default constants and functions
+
+=head1 DESCRIPTION
+
+If C<COLUMN_DEF> from L<DBI/column_info> returns character constants quoted,
+then we need to remove the quotes. This also allows distinguishing between
+default functions without information schema introspection.
+
+=cut
+
+sub _columns_info_for {
+ my $self = shift;
+ my ($table) = @_;
+
+ my $result = $self->next::method(@_);
+
+ while (my ($col, $info) = each %$result) {
+ if (my $def = $info->{default_value}) {
+ $def =~ s/^\s+//;
+ $def =~ s/\s+\z//;
+
+ if ($def =~ /^["'](.*?)['"]\z/) {
+ $info->{default_value} = $1;
+ }
+ else {
+ $info->{default_value} = $def =~ /^\d/ ? $def : \$def;
+ }
+ }
+ }
+
+ return $result;
+}
+
+1;
+
+=head1 SEE ALSO
+
+L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
+L<DBIx::Class::Schema::Loader::DBI>
+
+=head1 AUTHOR
+
+See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
+
+=head1 LICENSE
+
+This library is free software; you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
use strict;
use warnings;
-use base 'DBIx::Class::Schema::Loader::DBI';
+use base qw/
+ DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
+ DBIx::Class::Schema::Loader::DBI
+/;
use Carp::Clan qw/^DBIx::Class/;
use Class::C3;
use strict;
use lib qw(t/lib);
use dbixcsl_common_tests;
+use Test::More;
+use Test::Exception;
my $dsn = $ENV{DBICTEST_ORA_DSN} || '';
my $user = $ENV{DBICTEST_ORA_USER} || '';
dsn => $dsn,
user => $user,
password => $password,
+ extra => {
+ create => [
+ q{
+ CREATE TABLE oracle_loader_test1 (
+ id INTEGER PRIMARY KEY,
+ a_varchar VARCHAR2(100) DEFAULT 'foo',
+ an_int INTEGER DEFAULT 42,
+ a_double DOUBLE PRECISION DEFAULT 10.555,
+ a_date DATE DEFAULT sysdate
+ )
+ },
+ ],
+ drop => [ qw/ oracle_loader_test1 / ],
+ count => 5,
+ run => sub {
+ my ($schema, $monikers, $classes) = @_;
+
+ my $rsrc = $schema->resultset($monikers->{oracle_loader_test1})
+ ->result_source;
+
+ is $rsrc->column_info('a_varchar')->{default_value},
+ 'foo',
+ 'constant character default';
+
+ is $rsrc->column_info('an_int')->{default_value},
+ 42,
+ 'constant integer default';
+
+ is $rsrc->column_info('a_double')->{default_value},
+ 10.555,
+ 'constant numeric default';
+
+ my $function_default =
+ $rsrc->column_info('a_date')->{default_value};
+
+ ok ((ref $function_default eq 'SCALAR'),
+ 'default_value for function default is a scalar ref')
+ or diag "default_value is: ", $function_default
+ ;
+
+ eval { is $$function_default,
+ 'sysdate',
+ 'default_value for function default is correct' };
+ },
+ },
);
if( !$dsn || !$user ) {