quote table names that include name_sep
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 17mssql_odbc_dot_in_table_name.t
CommitLineData
385c593b 1use strict;
2use lib qw(t/lib);
3use Test::More;
4use DBI;
5
6my $DUMP_DIR;
7BEGIN {
8 $DUMP_DIR = './t/_common_dump';
9}
10
11use lib $DUMP_DIR;
12use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR";
13use File::Path;
14
15my $dsn = $ENV{DBICTEST_MSSQL_ODBC_DSN} || '';
16my $user = $ENV{DBICTEST_MSSQL_ODBC_USER} || '';
17my $password = $ENV{DBICTEST_MSSQL_ODBC_PASS} || '';
18
19if( !$dsn || !$user ) {
20 plan skip_all => 'You need to set the DBICTEST_MSSQL_ODBC_DSN, _USER, and _PASS environment variables';
21 exit;
22}
23
24plan tests => 3;
25
26my $dbh = DBI->connect($dsn, $user, $password, {
27 RaiseError => 1, PrintError => 0
28});
29
30eval { $dbh->do('DROP TABLE [test.dot]') };
31$dbh->do(q{
32 CREATE TABLE [test.dot] (
33 id INT IDENTITY NOT NULL PRIMARY KEY,
34 dat VARCHAR(8)
35 )
36});
37
38rmtree $DUMP_DIR;
39
40eval {
41 make_schema_at(
42 'TestSL::Schema',
43 { use_namespaces => 1 },
6ed0a90c 44 [ $dsn, $user, $password, ]
385c593b 45 );
46};
47
48ok !$@, 'table name with . parsed correctly';
49diag $@ if $@;
50
ff30991a 51#system qq{$^X -pi -e 's/"test\.dot"/\\\\"[test.dot]"/' t/_common_dump/TestSL/Schema/Result/TestDot.pm};
385c593b 52#diag do { local ($/, @ARGV) = (undef, "t/_common_dump/TestSL/Schema/Result/TestDot.pm"); <> };
ff30991a 53#do "t/_common_dump/TestSL/Schema/Result/TestDot.pm";
6ed0a90c 54
55eval 'use TestSL::Schema';
56ok !$@, 'loaded schema';
385c593b 57diag $@ if $@;
58
6ed0a90c 59TODO: {
60 local $TODO = q{this is really a DBIC test to check if the table is usable,
61and it doesn't work in the released version yet};
62
63 eval {
64 my $rs = TestSL::Schema->resultset('TestDot');
65 my $row = $rs->create({ dat => 'foo' });
66 $row->update({ dat => 'bar' });
67 $row = $rs->find($row->id);
68 $row->delete;
69 };
70 ok !$@, 'used table from DBIC succeessfully';
71 diag $@ if $@;
72}
73
ff30991a 74rmtree $DUMP_DIR;
385c593b 75
76$dbh->do('DROP TABLE [test.dot]');