From: Rafael Kitover Date: Mon, 29 Jun 2009 20:56:45 +0000 (+0000) Subject: changed CD to ->table(\"cd") X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=cebb7ccee80463aaa1141011a8290a5f75ee77a2;p=dbsrgits%2FDBIx-Class-Historic.git changed CD to ->table(\"cd") --- diff --git a/lib/DBIx/Class/SQLAHacks/MySQL.pm b/lib/DBIx/Class/SQLAHacks/MySQL.pm index 9b4d0be..687a793 100644 --- a/lib/DBIx/Class/SQLAHacks/MySQL.pm +++ b/lib/DBIx/Class/SQLAHacks/MySQL.pm @@ -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 ()" diff --git a/t/19quotes.t b/t/19quotes.t index c4768c8..8750d5a 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -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' ); diff --git a/t/19quotes_newstyle.t b/t/19quotes_newstyle.t index f0c34a9..3e7595a 100644 --- a/t/19quotes_newstyle.t +++ b/t/19quotes_newstyle.t @@ -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' ); diff --git a/t/19table_name_ref.t b/t/19table_name_ref.t deleted file mode 100644 index d98e8a7..0000000 --- a/t/19table_name_ref.t +++ /dev/null @@ -1,45 +0,0 @@ -use strict; -use warnings; - -use Test::More; -use IO::File; - -use lib qw(t/lib); -use DBICTest; -use DBIC::SqlMakerTest; -use DBIC::DebugObj; - -plan tests => 2; - -my $schema = DBICTest->init_schema(); - -$schema->storage->sql_maker->quote_char('`'); -$schema->storage->sql_maker->name_sep('.'); - -my ($sql, @bind); -$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)), -$schema->storage->debug(1); - -my $rs; - -# ->table(\'cd') should NOT be quoted -$rs = $schema->resultset('CDTableRef')->search( - { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, - { join => 'artist' }); -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'"], - 'got correct SQL for count query with quoting' -); - -# check that the table works -eval { - $rs = $schema->resultset('CDTableRef'); - $rs->create({ cdid => 6, artist => 3, title => 'mtfnpy', year => 2009 }); - my $row = $rs->find(6); - $row->update({ title => 'bleh' }); - $row->delete; -}; -ok !$@, 'operations on scalarref table name work'; -diag $@ if $@; diff --git a/t/lib/DBICTest/Schema.pm b/t/lib/DBICTest/Schema.pm index b9521ef..b03d090 100644 --- a/t/lib/DBICTest/Schema.pm +++ b/t/lib/DBICTest/Schema.pm @@ -11,7 +11,6 @@ __PACKAGE__->load_classes(qw/ BindType Employee CD - CDTableRef FileColumn Genre Link diff --git a/t/lib/DBICTest/Schema/CD.pm b/t/lib/DBICTest/Schema/CD.pm index ec6ab24..8bcbcee 100644 --- a/t/lib/DBICTest/Schema/CD.pm +++ b/t/lib/DBICTest/Schema/CD.pm @@ -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', diff --git a/t/lib/DBICTest/Schema/CDTableRef.pm b/t/lib/DBICTest/Schema/CDTableRef.pm deleted file mode 100644 index 239d294..0000000 --- a/t/lib/DBICTest/Schema/CDTableRef.pm +++ /dev/null @@ -1,45 +0,0 @@ -package # hide from PAUSE - DBICTest::Schema::CDTableRef; - -use base qw/DBICTest::BaseResult/; -use DBIx::Class::ResultSource::View; - -__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); -__PACKAGE__->table(\'cd'); -__PACKAGE__->result_source_instance->is_virtual(0); - -__PACKAGE__->add_columns( - 'cdid' => { - data_type => 'integer', - is_auto_increment => 1, - }, - 'artist' => { - data_type => 'integer', - }, - 'title' => { - data_type => 'varchar', - size => 100, - }, - 'year' => { - data_type => 'varchar', - size => 100, - }, - 'genreid' => { - data_type => 'integer', - is_nullable => 1, - }, - 'single_track' => { - data_type => 'integer', - is_nullable => 1, - is_foreign_key => 1, - } -); -__PACKAGE__->set_primary_key('cdid'); -__PACKAGE__->add_unique_constraint([ qw/artist title/ ]); - -__PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist', - 'artist', { - is_deferrable => 1, -}); - -1;