automatically turn on quoting for MySQL (RT#60469)
Rafael Kitover [Thu, 26 May 2011 20:54:46 +0000 (16:54 -0400)]
Changes
lib/DBIx/Class/Schema/Loader/DBI/mysql.pm
t/10_02mysql_common.t
t/lib/dbixcsl_common_tests.pm

diff --git a/Changes b/Changes
index 0258327..ec8d49f 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - automatically turn on quoting for MySQL (RT#60469)
         - become utf8-aware (RT#67920)
         - handle duplicate relationship names (RT#64041)
         - fix a bug in Sybase ASE foreign key detection
index 8489e30..4712fdf 100644 (file)
@@ -22,6 +22,9 @@ See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
 sub _setup {
     my $self = shift;
 
+    $self->schema->storage->sql_maker->quote_char("`");
+    $self->schema->storage->sql_maker->name_sep(".");
+
     $self->next::method(@_);
 
     if (not defined $self->preserve_case) {
index e414380..9f1a366 100644 (file)
@@ -20,6 +20,7 @@ my $tester = dbixcsl_common_tests->new(
     connect_info_opts=> { on_connect_call => 'set_strict_mode' },
     loader_options   => { preserve_case => 1 },
     skip_rels        => $test_innodb ? 0 : $skip_rels_msg,
+    quote_char       => '`',
     no_inline_rels   => 1,
     no_implicit_rels => 1,
     data_types  => {
@@ -127,21 +128,24 @@ my $tester = dbixcsl_common_tests->new(
     extra => {
         create => [
             q{
-                CREATE TABLE mysql_loader_test1 (
+                CREATE TABLE `mysql_loader-test1` (
                     id INT AUTO_INCREMENT PRIMARY KEY,
                     value varchar(100)
                 )
             },
             q{
-                CREATE VIEW mysql_loader_test2 AS SELECT * FROM mysql_loader_test1
+                CREATE VIEW mysql_loader_test2 AS SELECT * FROM `mysql_loader-test1`
             },
         ],
         pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ],
-        drop => [ 'mysql_loader_test1', ],
-        count => 1,
+        drop => [ 'mysql_loader-test1', ],
+        count => 2,
         run => sub {
             my ($schema, $monikers, $classes) = @_;
 
+            is $monikers->{'mysql_loader-test1'}, 'MysqlLoaderTest1',
+                'table with dash correctly monikerized';
+
             my $rsrc = $schema->resultset($monikers->{mysql_loader_test2})->result_source;
 
             is $rsrc->column_info('value')->{data_type}, 'varchar',
index 40e8da8..6e86008 100644 (file)
@@ -211,7 +211,7 @@ sub setup_schema {
 
     my %loader_opts = (
         constraint              =>
-          qr/^(?:\S+\.)?(?:(?:$self->{vendor}|extra)_?)?loader_?test[0-9]+(?!.*_)/i,
+          qr/^(?:\S+\.)?(?:(?:$self->{vendor}|extra)[_-]?)?loader[_-]?test[0-9]+(?!.*_)/i,
         relationships           => 1,
         additional_classes      => 'TestAdditional',
         additional_base_classes => 'TestAdditionalBase',