my $dbh = $self->schema->storage->dbh;
my @tables = $dbh->tables(undef, $self->db_schema, $table, $type);
- s/\Q$self->{_quoter}\E//g for @tables;
- s/^.*\Q$self->{_namesep}\E// for @tables;
+ my $qt = qr/\Q$self->{_quoter}\E/;
+
+ if ($self->{_quoter} && $tables[0] =~ /$qt/) {
+ s/.* $qt (?= .* $qt)//xg for @tables;
+ } else {
+ s/^.*\Q$self->{_namesep}\E// for @tables;
+ }
+ s/$qt//g for @tables;
return @tables;
}
$self->next::method(@_);
}
+sub _quote_table_name {
+ my ($self, $table) = @_;
+
+ my $qt = $self->schema->storage->sql_maker->quote_char;
+
+ if (ref $qt) {
+ return $qt->[0] . $table . $qt->[1];
+ }
+
+ return $qt . $table . $qt;
+}
+
# Returns an arrayref of column names
sub _table_columns {
my ($self, $table) = @_;
my $dbh = $self->schema->storage->dbh;
if($self->{db_schema}) {
- $table = $self->{db_schema} . $self->{_namesep} . $table;
+ $table = $self->{db_schema} . $self->{_namesep} .
+ $self->_quote_table_name($table);
+ } else {
+ $table = $self->_quote_table_name($table);
}
- my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0'));
+ my $sth = $dbh->prepare($self->schema->storage->sql_maker->select(\$table, undef, \'1 = 0'));
$sth->execute;
my $retval = \@{$sth->{NAME_lc}};
$sth->finish;
--- /dev/null
+use strict;
+use lib qw(t/lib);
+use Test::More;
+use DBI;
+
+my $DUMP_DIR;
+BEGIN {
+ $DUMP_DIR = './t/_common_dump';
+}
+
+use lib $DUMP_DIR;
+use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR";
+use File::Path;
+
+my $dsn = $ENV{DBICTEST_MSSQL_ODBC_DSN} || '';
+my $user = $ENV{DBICTEST_MSSQL_ODBC_USER} || '';
+my $password = $ENV{DBICTEST_MSSQL_ODBC_PASS} || '';
+
+if( !$dsn || !$user ) {
+ plan skip_all => 'You need to set the DBICTEST_MSSQL_ODBC_DSN, _USER, and _PASS environment variables';
+ exit;
+}
+
+plan tests => 3;
+
+my $dbh = DBI->connect($dsn, $user, $password, {
+ RaiseError => 1, PrintError => 0
+});
+
+eval { $dbh->do('DROP TABLE [test.dot]') };
+$dbh->do(q{
+ CREATE TABLE [test.dot] (
+ id INT IDENTITY NOT NULL PRIMARY KEY,
+ dat VARCHAR(8)
+ )
+});
+
+rmtree $DUMP_DIR;
+
+eval {
+ make_schema_at(
+ 'TestSL::Schema',
+ { use_namespaces => 1 },
+ [ $dsn, $user, $password, { quote_char => [qw/[ ]/], name_sep => '.' }]
+ );
+};
+
+ok !$@, 'table name with . parsed correctly';
+diag $@ if $@;
+
+eval 'use TestSL::Schema';
+ok !$@, 'loaded schema';
+diag $@ if $@;
+
+## this doesn't work either
+#system qq{$^X -pi -e 's/"test\.dot"/\\\\"test.dot"/' t/_common_dump/TestSL/Schema/Result/TestDot.pm};
+
+#diag do { local ($/, @ARGV) = (undef, "t/_common_dump/TestSL/Schema/Result/TestDot.pm"); <> };
+
+eval {
+ TestSL::Schema->resultset('TestDot')->create({ dat => 'foo' });
+};
+ok !$@, 'used table from DBIC succeessfully';
+diag $@ if $@;
+
+rmtree $DUMP_DIR;
+
+$dbh->do('DROP TABLE [test.dot]');