Merge 'trunk' into 'table_name_ref'
Rafael Kitover [Thu, 6 Aug 2009 13:48:54 +0000 (13:48 +0000)]
r9068@hlagh (orig r7198):  caelum | 2009-08-04 16:18:27 -0400
update Changes
r9075@hlagh (orig r7205):  ribasushi | 2009-08-05 02:34:25 -0400
Bump dependencies:
Test::More for the new no_plan/done_testing goodies
File::Temp as per RT#48431
r9077@hlagh (orig r7207):  ribasushi | 2009-08-05 02:36:32 -0400
 r7156@Thesaurus (orig r7153):  robkinyon | 2009-07-30 20:06:04 +0200
 Create prefetch_redux branch
 r7164@Thesaurus (orig r7161):  robkinyon | 2009-07-31 22:41:01 +0200
 Added MooseX::Traits to Makefile.PL
 r7172@Thesaurus (orig r7169):  robkinyon | 2009-08-03 05:49:59 +0200
 Added two tests and marked one todo_skip
 r7187@Thesaurus (orig r7184):  ribasushi | 2009-08-03 17:24:41 +0200
 Use goto to preserve correct error-at-line reporting
 r7189@Thesaurus (orig r7186):  ribasushi | 2009-08-04 12:34:58 +0200
 Add an extra test specifically for distinct/prefetch
 Remove duplicate test in count/prefetch

 Switch to as_query instead of debug overloading
 r7190@Thesaurus (orig r7187):  ribasushi | 2009-08-04 12:35:57 +0200
 Fix how a distinct-induced group_by is calculated, taking in consideration the new prefetch mechanism
 r7197@Thesaurus (orig r7194):  ribasushi | 2009-08-04 17:31:33 +0200
 Traits not needed by anything currently in dbic
 r7198@Thesaurus (orig r7195):  ribasushi | 2009-08-04 17:41:14 +0200
 Move around tests a bit
 r7199@Thesaurus (orig r7196):  mo | 2009-08-04 21:10:57 +0200
 prefetch-grouped fails, again
 r7204@Thesaurus (orig r7201):  ribasushi | 2009-08-04 22:50:51 +0200
 Split the search_related prefetch tests into a standalone testfile
 r7205@Thesaurus (orig r7202):  ribasushi | 2009-08-04 23:05:03 +0200
 Move norbi's test to prefetch_redux - it's the same idea
 r7209@Thesaurus (orig r7206):  ribasushi | 2009-08-05 08:35:48 +0200
 Tadaaaa (even more prefetch insanity)

r9079@hlagh (orig r7209):  ribasushi | 2009-08-05 02:38:41 -0400
 r7107@Thesaurus (orig r7104):  caelum | 2009-07-24 06:51:57 +0200
 new branch to move common mssql functionality into the base class, and other tweaks
 r7109@Thesaurus (orig r7106):  caelum | 2009-07-24 07:28:11 +0200
 moved code to ::DBI::MSSQL and added DT inflation test
 r7112@Thesaurus (orig r7109):  caelum | 2009-07-24 08:46:16 +0200
 merge in some more MSSQL code, including odbc dynamic cursor support
 r7113@Thesaurus (orig r7110):  caelum | 2009-07-24 08:49:54 +0200
 fix a warning in SQLAHacks
 r7114@Thesaurus (orig r7111):  caelum | 2009-07-24 09:22:33 +0200
 add placeholder support detection for mssql through dbd::sybase
 r7118@Thesaurus (orig r7115):  caelum | 2009-07-24 16:39:06 +0200
 minor doc clarification
 r7122@Thesaurus (orig r7119):  caelum | 2009-07-25 16:10:30 +0200
 move placeholder support detection into ::Sybase::Base
 r7123@Thesaurus (orig r7120):  caelum | 2009-07-25 16:12:01 +0200
 add a comment
 r7127@Thesaurus (orig r7124):  caelum | 2009-07-26 18:04:29 +0200
 SAVEPOINT methods for MSSQL
 r7140@Thesaurus (orig r7137):  caelum | 2009-07-30 10:12:45 +0200
 better tests for "smalldatetime" support in MSSQL
 r7142@Thesaurus (orig r7139):  caelum | 2009-07-30 13:29:19 +0200
 MSSQL GUID support
 r7147@Thesaurus (orig r7144):  caelum | 2009-07-30 15:38:33 +0200
 update sqlite test schema
 r7150@Thesaurus (orig r7147):  caelum | 2009-07-30 16:26:47 +0200
 make sure the new mssql insert method works on an un-reblessed storage
 r7151@Thesaurus (orig r7148):  caelum | 2009-07-30 16:55:35 +0200
 better rebless check for insert
 r7154@Thesaurus (orig r7151):  caelum | 2009-07-30 18:57:22 +0200
 add missing file
 r7155@Thesaurus (orig r7152):  caelum | 2009-07-30 19:00:40 +0200
 fix syntax error
 r7163@Thesaurus (orig r7160):  caelum | 2009-07-31 15:52:41 +0200
 fix a bug in _determine_driver
 r7166@Thesaurus (orig r7163):  caelum | 2009-08-01 18:10:23 +0200
 default collist for storage _resolve_column_info
 r7182@Thesaurus (orig r7179):  caelum | 2009-08-03 13:42:31 +0200
 check that dynamic cursors are functional if enabled
 r7184@Thesaurus (orig r7181):  ribasushi | 2009-08-03 14:23:37 +0200
 Adjust expected sql to match the new 'Track' table definition
 r7186@Thesaurus (orig r7183):  ribasushi | 2009-08-03 15:16:10 +0200
 Simplify code and add some comments
 r7200@Thesaurus (orig r7197):  caelum | 2009-08-04 21:31:16 +0200
 update oracle tests for new "track" table
 r7203@Thesaurus (orig r7200):  caelum | 2009-08-04 22:39:57 +0200
 update Changes

r9081@hlagh (orig r7211):  ribasushi | 2009-08-05 02:40:39 -0400
 r7213@Thesaurus (orig r7210):  ribasushi | 2009-08-05 08:40:20 +0200
 Really sanify _resolve_column_info

r9083@hlagh (orig r7213):  ribasushi | 2009-08-05 04:19:37 -0400
Reminder about discard_changes and friends
r9084@hlagh (orig r7214):  ribasushi | 2009-08-05 04:26:20 -0400
Reformat and fill-in changes
r9085@hlagh (orig r7215):  caelum | 2009-08-05 04:37:12 -0400
rename connect_call_use_mars to connect_call_use_MARS
r9086@hlagh (orig r7216):  ribasushi | 2009-08-05 04:38:14 -0400
Silence a TODO test
r9087@hlagh (orig r7217):  caelum | 2009-08-05 04:46:11 -0400
minor Changes update
r9097@hlagh (orig r7227):  castaway | 2009-08-05 08:57:52 -0400
Minty's conversion of cookbook "arbitrary sql" to use ResultSource::View, plus some examples in ::View itself.
Some style tweaks of mine

r9098@hlagh (orig r7228):  ribasushi | 2009-08-05 09:41:28 -0400
Dynamically load necessary table classes
r9103@hlagh (orig r7233):  caelum | 2009-08-05 13:49:51 -0400
fix rounding issues in mssql money tests
r9104@hlagh (orig r7234):  caelum | 2009-08-05 14:09:03 -0400
better money value comparison in tests
r9106@hlagh (orig r7236):  frew | 2009-08-05 14:53:32 -0400
whitespace jfklds;ajfklds;a
r9107@hlagh (orig r7237):  frew | 2009-08-05 14:54:41 -0400
Fix testing bug.  Windows only.

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 1b93f4e..d7f20b4 100644 (file)
@@ -584,7 +584,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 929c300..db82b47 100644 (file)
@@ -5,6 +5,9 @@ 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');
 
 __PACKAGE__->mk_classdata('table_alias'); # FIXME: Doesn't actually do
@@ -76,7 +79,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)) {
 
     my $table_class = $class->table_class;
     $class->ensure_class_loaded($table_class);
index c03adbb..61ff365 100644 (file)
@@ -329,12 +329,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];
@@ -354,7 +352,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,
@@ -370,7 +368,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, @_);
 }
 
@@ -378,7 +376,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, @_);
 }
 
@@ -584,6 +582,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 bbae42d..5bbd302 100644 (file)
@@ -29,7 +29,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;
@@ -43,7 +43,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;
@@ -57,7 +57,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);
@@ -83,3 +83,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',