Merge 'trunk' into 'grouped_has_many_join'
Peter Rabbitson [Thu, 20 Aug 2009 15:48:55 +0000 (15:48 +0000)]
r7346@Thesaurus (orig r7343):  robkinyon | 2009-08-19 21:44:48 +0200
Applied doc patch by spb
r7347@Thesaurus (orig r7344):  ribasushi | 2009-08-20 07:50:49 +0200
Fix a weird-ass sqlt invocation in deployment_statements()
r7348@Thesaurus (orig r7345):  ribasushi | 2009-08-20 08:19:07 +0200
Apply pod patch by arthas (slightly modified)
r7353@Thesaurus (orig r7350):  abraxxa | 2009-08-20 15:07:29 +0200
pod patch for 'Tracing SQL' examples

lib/DBIx/Class/InflateColumn/DateTime.pm
lib/DBIx/Class/Manual/Cookbook.pod
lib/DBIx/Class/Storage/DBI.pm
t/86sqlt.t
t/lib/sqlite.sql

index 7e50807..a7a13a6 100644 (file)
@@ -18,6 +18,7 @@ columns to be of the datetime, timestamp or date datatype.
   __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/);
   __PACKAGE__->add_columns(
     starts_when => { data_type => 'datetime' }
+    create_date => { data_type => 'date' }
   );
 
 NOTE: You B<must> load C<InflateColumn::DateTime> B<before> C<Core>. See
@@ -69,6 +70,16 @@ one your code should continue to work without modification (though note
 that this feature is new as of 0.07, so it may not be perfect yet - bug
 reports to the list very much welcome).
 
+If the data_type of a field is C<date>, C<datetime> or C<timestamp> (or
+a derivative of these datatypes, e.g. C<timestamp with timezone>, this
+module will automatically call the appropriate parse/format method for
+deflation/inflation as defined in the storage class. For instance, for
+a C<datetime> field the methods C<parse_datetime> and C<format_datetime>
+would be called on deflation/inflation. If the storage class does not
+provide a specialized inflator/deflator, C<[parse|format]_datetime> will
+be used as a fallback. See L<DateTime::Format> for more information on
+date formatting.
+
 For more help with using components, see L<DBIx::Class::Manual::Component/USING>.
 
 =cut
index 51a8a33..94805c2 100644 (file)
@@ -1522,13 +1522,13 @@ customers as above.
 If the database contains column names with spaces and/or reserved words, they
 need to be quoted in the SQL queries. This is done using:
 
- __PACKAGE__->storage->sql_maker->quote_char([ qw/[ ]/] );
- __PACKAGE__->storage->sql_maker->name_sep('.');
+ $schema->storage->sql_maker->quote_char([ qw/[ ]/] );
+ $schema->storage->sql_maker->name_sep('.');
 
 The first sets the quote characters. Either a pair of matching
 brackets, or a C<"> or C<'>:
 
- __PACKAGE__->storage->sql_maker->quote_char('"');
+ $schema->storage->sql_maker->quote_char('"');
 
 Check the documentation of your database for the correct quote
 characters to use. C<name_sep> needs to be set to allow the SQL
@@ -1547,6 +1547,17 @@ L<DBIx::Class::Schema/connect>:
   }
  )
 
+In some cases, quoting will be required for all users of a schema. To enforce
+this, you can also overload the C<connect> method for your schema class:
+
+ sub connect {
+     my $self = shift;
+     my $rv = $self->next::method( @_ );
+     $rv->storage->sql_maker->quote_char([ qw/[ ]/ ]);
+     $rv->storage->sql_maker->name_sep('.');
+     return $rv;
+ }
+
 =head2 Setting limit dialect for SQL::Abstract::Limit
 
 In some cases, SQL::Abstract::Limit cannot determine the dialect of
index b8f3ebb..e08ff9c 100644 (file)
@@ -2303,18 +2303,18 @@ sub deployment_statements {
       . $self->_check_sqlt_message . q{'})
           if !$self->_check_sqlt_version;
 
-  require SQL::Translator::Parser::DBIx::Class;
-  eval qq{use SQL::Translator::Producer::${type}};
-  $self->throw_exception($@) if $@;
-
   # sources needs to be a parser arg, but for simplicty allow at top level
   # coming in
   $sqltargs->{parser_args}{sources} = delete $sqltargs->{sources}
       if exists $sqltargs->{sources};
 
-  my $tr = SQL::Translator->new(%$sqltargs);
-  SQL::Translator::Parser::DBIx::Class::parse( $tr, $schema );
-  return "SQL::Translator::Producer::${type}"->can('produce')->($tr);
+  my $tr = SQL::Translator->new(
+    producer => "SQL::Translator::Producer::${type}",
+    %$sqltargs,
+    parser => 'SQL::Translator::Parser::DBIx::Class',
+    data => $schema,
+  );
+  return $tr->translate;
 }
 
 sub deploy {
index 467fed3..65f2dc8 100644 (file)
@@ -8,9 +8,29 @@ use DBICTest;
 eval "use SQL::Translator";
 plan skip_all => 'SQL::Translator required' if $@;
 
-my $schema = DBICTest->init_schema;
+my $schema = DBICTest->init_schema (no_deploy => 1);
+
+# replace the sqlt calback with a custom version ading an index
+$schema->source('Track')->sqlt_deploy_callback(sub {
+  my ($self, $sqlt_table) = @_;
+
+  is (
+    $sqlt_table->schema->translator->producer_type,
+    join ('::', 'SQL::Translator::Producer', $schema->storage->sqlt_type),
+    'Production type passed to translator object',
+  );
+
+  if ($schema->storage->sqlt_type eq 'SQLite' ) {
+    $sqlt_table->add_index( name => 'track_title', fields => ['title'] )
+      or die $sqlt_table->error;
+  }
+
+  $self->default_sqlt_deploy_hook($sqlt_table);
+});
+
+$schema->deploy; # do not remove, this fires the is() test in the callback above
+
 
-plan tests => 133;
 
 my $translator = SQL::Translator->new( 
   parser_args => {
@@ -26,16 +46,6 @@ my $translator = SQL::Translator->new(
     my $relinfo = $schema->source('Artist')->relationship_info ('cds');
     local $relinfo->{attrs}{on_delete} = 'restrict';
 
-    $schema->source('Track')->sqlt_deploy_callback(sub {
-      my ($self, $sqlt_table) = @_;
-
-      if ($schema->storage->sqlt_type eq 'SQLite' ) {
-        $sqlt_table->add_index( name => 'track_title', fields => ['title'] )
-          or die $sqlt_table->error;
-      }
-
-      $self->default_sqlt_deploy_hook($sqlt_table);
-    });
 
     $translator->parser('SQL::Translator::Parser::DBIx::Class');
     $translator->producer('SQLite');
@@ -45,6 +55,7 @@ my $translator = SQL::Translator->new(
     ok($output, "SQLT produced someoutput")
       or diag($translator->error);
 
+
     like (
       $warn,
       qr/SQLT attribute .+? was supplied for relationship .+? which does not appear to be a foreign constraint/,
@@ -443,3 +454,5 @@ sub test_unique {
   is( $got->name, $expected->{name},
       "name parameter correct for `$desc'" );
 }
+
+done_testing;
index 86e345e..1938e87 100644 (file)
@@ -1,6 +1,6 @@
 -- 
 -- Created by SQL::Translator::Producer::SQLite
--- Created on Wed Aug 12 16:10:43 2009
+-- Created on Thu Aug 20 07:47:13 2009
 -- 
 
 
@@ -16,6 +16,8 @@ CREATE TABLE artist (
   charfield char(10)
 );
 
+CREATE INDEX artist_name_hookidx ON artist (name);
+
 --
 -- Table: bindtype_test
 --