Propagate quote_names setting to SQLite SQLT producer
Peter Rabbitson [Thu, 4 Jul 2013 15:15:16 +0000 (17:15 +0200)]
Changes
lib/DBIx/Class/Storage/DBI/SQLite.pm
t/86sqlt.t
t/storage/quote_names.t

diff --git a/Changes b/Changes
index 771a55e..4ab2210 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for DBIx::Class
 
+    * Fixes
+        - Setting quote_names propagates to SQL::Translator when producing
+          SQLite DDL (it is one of the few producers *NOT* quoting by default)
+
     * Misc
         - Replace $row with $result in all docs to be consistent and to
           clarify various return values
index 82c0f17..bd63417 100644 (file)
@@ -232,6 +232,10 @@ sub deployment_statements {
     $sqltargs->{producer_args}{sqlite_version} = $dver;
   }
 
+  $sqltargs->{quote_identifiers}
+    = !!$self->sql_maker->_quote_chars
+  if ! exists $sqltargs->{quote_identifiers};
+
   $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
 }
 
index 89783d3..caea89f 100644 (file)
@@ -26,7 +26,7 @@ sub DBICTest::Schema::deployment_statements {
 # Check deployment statements ctx sensitivity
 {
   my $schema = DBICTest->init_schema (no_deploy => 1);
-  my $not_first_table_creation_re = qr/CREATE TABLE fourkeys_to_twokeys/;
+  my $not_first_table_creation_re = qr/CREATE TABLE "fourkeys_to_twokeys"/;
 
   my $statements = $schema->deployment_statements;
   like (
index 87517e9..6492f25 100644 (file)
@@ -126,6 +126,14 @@ for my $db (sort {
   is $schema->storage->sql_maker->name_sep,
     $exp_name_sep,
     "$db name_sep with quote_names => 1 is $name_sep_text";
+
+  # if something was produced - it better be quoted
+  if ( my $ddl = try { $schema->deployment_statements } ) {
+
+    my $quoted_artist = $schema->storage->sql_maker->_quote('artist');
+
+    like ($ddl, qr/^CREATE\s+TABLE\s+\Q$quoted_artist/msi, "$db DDL contains expected quoted table name");
+  }
 }
 
 done_testing;