Merge 'trunk' into 'table_name_ref'
Rafael Kitover [Fri, 17 Jul 2009 08:18:24 +0000 (08:18 +0000)]
r5961@hlagh (orig r7029):  robkinyon | 2009-07-10 18:03:07 -0400
Applied patch from kados regarding use of a DateTime::Format class to validate
r5962@hlagh (orig r7030):  caelum | 2009-07-11 05:26:40 -0400
reword IC::DT doc patch
r6009@hlagh (orig r7037):  dandv | 2009-07-13 08:06:08 -0400
PK::Auto has moved into Core since 2007
r6010@hlagh (orig r7038):  dandv | 2009-07-13 08:15:13 -0400
Fixed has_many example in Intro.pod
r6011@hlagh (orig r7039):  dandv | 2009-07-13 16:58:45 -0400
Fixed run-on sentences in FAQ
r6012@hlagh (orig r7040):  dandv | 2009-07-13 17:18:11 -0400
Minor POD fixes in Example.pod
r6013@hlagh (orig r7041):  dandv | 2009-07-13 17:48:18 -0400
Favored using ->single to get the topmost result over less readable ->slice(0)
r6014@hlagh (orig r7042):  dandv | 2009-07-13 18:56:31 -0400
Minor POD fixes in Cookbook
r6015@hlagh (orig r7045):  ribasushi | 2009-07-14 07:30:55 -0400
Minor logic cleanup
r6016@hlagh (orig r7046):  ribasushi | 2009-07-14 08:07:11 -0400
grouped prefetch fix
r6023@hlagh (orig r7053):  ijw | 2009-07-15 12:55:35 -0400
Added SQLA link for more comprehensive documentation of order_by options available
r6026@hlagh (orig r7056):  caelum | 2009-07-15 18:54:22 -0400
add "smalldatetime" support to IC::DT
r6029@hlagh (orig r7059):  ribasushi | 2009-07-16 00:29:41 -0400
 r7013@Thesaurus (orig r7012):  jnapiorkowski | 2009-07-09 17:00:22 +0200
 new branch
 r7014@Thesaurus (orig r7013):  jnapiorkowski | 2009-07-09 20:06:44 +0200
 changed the way transactions are detected for replication to work with the standard way to do this, minor doc updates, fix to the force pool so you can force a particular slave, changes to the way the debugging is created
 r7015@Thesaurus (orig r7014):  jnapiorkowski | 2009-07-09 20:17:03 +0200
 more changes to the way debug output works
 r7016@Thesaurus (orig r7015):  jnapiorkowski | 2009-07-09 22:26:47 +0200
 big update to the test suite so that we now check to make sure the storage that was expected was actually used
 r7017@Thesaurus (orig r7016):  jnapiorkowski | 2009-07-09 23:23:37 +0200
 set correct number of tests, changed the debuggin output to not warn on DDL, minor change to a test resultclass so we can deploy to mysql properly
 r7018@Thesaurus (orig r7017):  jnapiorkowski | 2009-07-09 23:26:59 +0200
 corrected the number of skipped tests
 r7019@Thesaurus (orig r7018):  jnapiorkowski | 2009-07-09 23:52:22 +0200
 fixed test resultclass formatting, added a few more DBIC::Storage::DBI methods that I might need to delegate.
 r7020@Thesaurus (orig r7019):  jnapiorkowski | 2009-07-10 01:23:07 +0200
 some documention updates and changed the way we find paths for the sqlite dbfiles to use File::Spec, which I hope will solve some of the Win32 error messages
 r7023@Thesaurus (orig r7022):  jnapiorkowski | 2009-07-10 18:00:38 +0200
 pod cleanup, fixed broken pod links, and new Introduction pod
 r7024@Thesaurus (orig r7023):  jnapiorkowski | 2009-07-10 19:10:57 +0200
 updated Changes file to reflect work completed
 r7025@Thesaurus (orig r7024):  jnapiorkowski | 2009-07-10 19:37:53 +0200
 a few more Moose Type related fixes and added diag to the replication test to report the moose and types version used, to help us debug some of the moose related errors being reported
 r7058@Thesaurus (orig r7057):  ribasushi | 2009-07-16 06:28:44 +0200
 A couple of typos, and general whitespace cleanup (ick)

r6031@hlagh (orig r7062):  jnapiorkowski | 2009-07-16 11:03:32 -0400
increased Moose version requirements due to changes in the way type constraints get validated, which is not backwardly compatible
r6032@hlagh (orig r7063):  dandv | 2009-07-16 21:37:28 -0400
Minor POD grammar: it's -> its where appropriate

lib/DBIx/Class/ResultSource.pm
lib/DBIx/Class/ResultSourceProxy/Table.pm
lib/DBIx/Class/SQLAHacks.pm
lib/DBIx/Class/SQLAHacks/MySQL.pm
lib/DBIx/Class/Storage/DBI/Pg.pm
lib/SQL/Translator/Parser/DBIx/Class.pm
t/19quotes.t
t/19quotes_newstyle.t
t/76select.t
t/99dbic_sqlt_parser.t
t/lib/DBICTest/Schema/CD.pm

index 89b8eda..55e99ad 100644 (file)
@@ -484,7 +484,10 @@ optional constraint name.
 sub name_unique_constraint {
   my ($self, $cols) = @_;
 
-  return join '_', $self->name, @$cols;
+  my $name = $self->name;
+  $name = $$name if ref $name;
+
+  return join '_', $name, @$cols;
 }
 
 =head2 unique_constraints
index a983ce1..b39e0b6 100644 (file)
@@ -6,6 +6,7 @@ use warnings;
 use base qw/DBIx::Class::ResultSourceProxy/;
 
 use DBIx::Class::ResultSource::Table;
+use Scalar::Util ();
 
 __PACKAGE__->mk_classdata(table_class => 'DBIx::Class::ResultSource::Table');
 
@@ -75,7 +76,8 @@ Gets or sets the table name.
 sub table {
   my ($class, $table) = @_;
   return $class->result_source_instance->name unless $table;
-  unless (ref $table) {
+
+  unless (Scalar::Util::blessed($table) && $table->isa($class->table_class)) {
     $table = $class->table_class->new({
         $class->can('result_source_instance') ?
           %{$class->result_source_instance||{}} : (),
index a1e6d1c..15f1a94 100644 (file)
@@ -328,12 +328,10 @@ sub select {
 
   $self->{"${_}_bind"} = [] for (qw/having from order/);
 
-  if (ref $table eq 'SCALAR') {
-    $table = $$table;
-  }
-  elsif (not ref $table) {
+  if (not ref($table) or ref($table) eq 'SCALAR') {
     $table = $self->_quote($table);
   }
+
   local $self->{rownum_hack_count} = 1
     if (defined $rest[0] && $self->{limit_dialect} eq 'RowNum');
   @rest = (-1) unless defined $rest[0];
@@ -353,7 +351,7 @@ sub select {
 sub insert {
   my $self = shift;
   my $table = shift;
-  $table = $self->_quote($table) unless ref($table);
+  $table = $self->_quote($table);
 
   # SQLA will emit INSERT INTO $table ( ) VALUES ( )
   # which is sadly understood only by MySQL. Change default behavior here,
@@ -369,7 +367,7 @@ sub insert {
 sub update {
   my $self = shift;
   my $table = shift;
-  $table = $self->_quote($table) unless ref($table);
+  $table = $self->_quote($table);
   $self->SUPER::update($table, @_);
 }
 
@@ -377,7 +375,7 @@ sub update {
 sub delete {
   my $self = shift;
   my $table = shift;
-  $table = $self->_quote($table) unless ref($table);
+  $table = $self->_quote($table);
   $self->SUPER::delete($table, @_);
 }
 
@@ -583,6 +581,7 @@ sub _join_condition {
 sub _quote {
   my ($self, $label) = @_;
   return '' unless defined $label;
+  return $$label if ref($label) eq 'SCALAR';
   return "*" if $label eq '*';
   return $label unless $self->{quote_char};
   if(ref $self->{quote_char} eq "ARRAY"){
index 9b4d0be..687a793 100644 (file)
@@ -12,7 +12,7 @@ sub insert {
   my $self = shift;
 
   my $table = $_[0];
-  $table = $self->_quote($table) unless ref($table);
+  $table = $self->_quote($table);
 
   if (! $_[1] or (ref $_[1] eq 'HASH' and !keys %{$_[1]} ) ) {
     return "INSERT INTO ${table} () VALUES ()"
index 3935a49..b113a97 100644 (file)
@@ -52,8 +52,16 @@ sub get_autoinc_seq {
   my ($self,$source,$col) = @_;
 
   my @pri = $source->primary_columns;
-  my ($schema,$table) = $source->name =~ /^(.+)\.(.+)$/ ? ($1,$2)
-    : (undef,$source->name);
+
+  my $schema;
+  my $table = $source->name;
+
+  if (ref $table eq 'SCALAR') {
+    $table = $$table;
+  }
+  elsif ($table =~ /^(.+)\.(.+)$/) {
+    ($schema, $table) = ($1, $2);
+  }
 
   $self->dbh_do('_dbh_get_autoinc_seq', $schema, $table, @pri);
 }
index 9f45d1b..2740760 100644 (file)
@@ -81,9 +81,7 @@ sub parse {
     {
         my $source = $dbicschema->source($moniker);
         my $table_name = $source->name;
-
-        # Skip custom query sources
-        next if ref $table_name;
+        $table_name = $$table_name if ref $table_name eq 'SCALAR';  #sqlt currently does not do quoting right anyway
 
         # Its possible to have multiple DBIC sources using the same table
         next if $tables{$table_name};
@@ -141,6 +139,7 @@ sub parse {
 
             my $othertable = $source->related_source($rel);
             my $rel_table = $othertable->name;
+            $rel_table = $$rel_table if ref $rel_table eq 'SCALAR';  #sqlt currently does not do quoting right anyway
 
             my $reverse_rels = $source->reverse_relationship_info($rel);
             my ($otherrelname, $otherrelationship) = each %{$reverse_rels};
@@ -259,6 +258,7 @@ sub parse {
     {
         my $source = $dbicschema->source($moniker);
         my $view_name = $source->name;
+        $view_name = $$view_name if ref $view_name eq 'SCALAR';  #sqlt currently does not do quoting right anyway
 
         # Skip custom query sources
         next if ref $view_name;
index c4768c8..8750d5a 100644 (file)
@@ -36,7 +36,7 @@ $rs = $schema->resultset('CD')->search(
 eval { $rs->count };
 is_same_sql_bind(
   $sql, \@bind,
-  "SELECT COUNT( * ) FROM `cd` `me`  JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
+  "SELECT COUNT( * ) FROM cd `me`  JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
   'got correct SQL for count query with quoting'
 );
 
@@ -60,7 +60,7 @@ $rs = $schema->resultset('CD')->search(
 eval { $rs->count };
 is_same_sql_bind(
   $sql, \@bind,
-  "SELECT COUNT( * ) FROM [cd] [me]  JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"],
+  "SELECT COUNT( * ) FROM cd [me]  JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"],
   'got correct SQL for count query with bracket quoting'
 );
 
index f0c34a9..3e7595a 100644 (file)
@@ -42,7 +42,7 @@ $rs = $schema->resultset('CD')->search(
 eval { $rs->count };
 is_same_sql_bind(
   $sql, \@bind,
-  "SELECT COUNT( * ) FROM `cd` `me`  JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
+  "SELECT COUNT( * ) FROM cd `me`  JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )", ["'Caterwauler McCrae'", "'2001'"],
   'got correct SQL for count query with quoting'
 );
 
@@ -73,7 +73,7 @@ $rs = $schema->resultset('CD')->search(
 eval { $rs->count };
 is_same_sql_bind(
   $sql, \@bind,
-  "SELECT COUNT( * ) FROM [cd] [me]  JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"],
+  "SELECT COUNT( * ) FROM cd [me]  JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )", ["'Caterwauler McCrae'", "'2001'"],
   'got correct SQL for count query with bracket quoting'
 );
 
index bee69e6..7560d2c 100644 (file)
@@ -64,6 +64,7 @@ my $cds = $schema->resultset ('CD')->search ({}, { order_by => 'me.cdid'}); # ma
 cmp_ok ($cds->count, '>', 2, 'Initially populated with more than 2 CDs');
 
 my $table = $cds->result_source->name;
+$table = $$table if ref $table eq 'SCALAR';
 my $subsel = $cds->search ({}, {
     columns => [qw/cdid title/],
     from => \ "(SELECT cdid, title FROM $table LIMIT 2) me",
index 9968a82..d95f698 100644 (file)
@@ -16,6 +16,7 @@ BEGIN {
 my $schema = DBICTest->init_schema();
 # Dummy was yanked out by the sqlt hook test
 # YearXXXXCDs are views
+
 my @sources = grep { $_ ne 'Dummy' && $_ !~ /^Year\d{4}CDs$/ } 
                 $schema->sources;
 
@@ -25,7 +26,7 @@ plan tests => ( @sources * 3);
        my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
 
        foreach my $source (@sources) {
-               my $table = $sqlt_schema->get_table($schema->source($source)->from);
+               my $table = get_table($sqlt_schema, $schema, $source);
 
                my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
                my @indices = $table->get_indices;
@@ -39,7 +40,7 @@ plan tests => ( @sources * 3);
        my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 1 } } });
 
        foreach my $source (@sources) {
-               my $table = $sqlt_schema->get_table($schema->source($source)->from);
+               my $table = get_table($sqlt_schema, $schema, $source);
 
                my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
                my @indices = $table->get_indices;
@@ -53,7 +54,7 @@ plan tests => ( @sources * 3);
        my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { add_fk_index => 0 } } });
 
        foreach my $source (@sources) {
-               my $table = $sqlt_schema->get_table($schema->source($source)->from);
+               my $table = get_table($sqlt_schema, $schema, $source);
 
                my @indices = $table->get_indices;
                my $index_count = scalar(@indices);
@@ -79,3 +80,12 @@ sub create_schema {
        $sqlt->parser('SQL::Translator::Parser::DBIx::Class');
        return $sqlt->translate({ data => $schema }) or die $sqlt->error;
 }
+
+sub get_table {
+    my ($sqlt_schema, $schema, $source) = @_;
+
+    my $table_name = $schema->source($source)->from;
+    $table_name    = $$table_name if ref $table_name;
+
+    return $sqlt_schema->get_table($table_name);
+}
index 80af1df..1463d00 100644 (file)
@@ -3,7 +3,10 @@ package # hide from PAUSE
 
 use base qw/DBICTest::BaseResult/;
 
-__PACKAGE__->table('cd');
+# this tests table name as scalar ref
+# DO NOT REMOVE THE \
+__PACKAGE__->table(\'cd');
+
 __PACKAGE__->add_columns(
   'cdid' => {
     data_type => 'integer',