X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F19quotes.t;h=646131b07558f34c5c1459676f302cdec4081644;hb=9c0df5f32b68e23c670c89ce6cdbff60b4bd0ed0;hp=ad44bcb55086b3ca0a69b67af0fdc7c5abd651fd;hpb=296ef183e78c6c74e2b33995f9187abb0165081c;p=dbsrgits%2FDBIx-Class.git diff --git a/t/19quotes.t b/t/19quotes.t index ad44bcb..646131b 100644 --- a/t/19quotes.t +++ b/t/19quotes.t @@ -14,52 +14,58 @@ BEGIN { use lib qw(t/lib); use_ok('DBICTest'); -DBICTest->init_schema(); +my $schema = DBICTest->init_schema(); -DBICTest->schema->storage->sql_maker->quote_char("'"); -DBICTest->schema->storage->sql_maker->name_sep('.'); +my $orig_debugcb = $schema->storage->debugcb; +my $orig_debug = $schema->storage->debug; -my $rs = DBICTest::CD->search( - { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, - { join => 'artist' }); +diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/)); -cmp_ok( $rs->count, '==', 1, "join with fields quoted"); +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -$rs = DBICTest::CD->search({}, - { 'order_by' => 'year DESC'}); -{ - my $warnings = ''; - local $SIG{__WARN__} = sub { $warnings .= $_[0] }; - my $first = eval{ $rs->first() }; - like( $warnings, qr/ORDER BY terms/, "Problem with ORDER BY quotes" ); -} +my $sql = ''; + +$schema->storage->debugcb(sub { $sql = $_[1] }); +$schema->storage->debug(1); + +my $rs; + +$rs = $schema->resultset('CD')->search( + { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, + { join => 'artist' }); +eval { $rs->count }; +like($sql, qr/\QSELECT COUNT( * ) FROM `cd` `me` JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` ) WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )\E/, 'got correct SQL for count query with quoting'); my $order = 'year DESC'; -$rs = DBICTest::CD->search({}, +$rs = $schema->resultset('CD')->search({}, + { 'order_by' => $order }); +eval { $rs->first }; +like($sql, qr/ORDER BY `\Q${order}\E`/, 'quoted ORDER BY with DESC (should use a scalarref anyway)'); + +$rs = $schema->resultset('CD')->search({}, { 'order_by' => \$order }); -{ - my $warnings = ''; - local $SIG{__WARN__} = sub { $warnings .= $_[0] }; - my $first = $rs->first(); - ok( $warnings !~ /ORDER BY terms/, - "No problem handling ORDER by scalaref" ); -} +eval { $rs->first }; +like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref'); -DBICTest->schema->storage->sql_maker->quote_char([qw/[ ]/]); -DBICTest->schema->storage->sql_maker->name_sep('.'); +$schema->storage->sql_maker->quote_char([qw/[ ]/]); +$schema->storage->sql_maker->name_sep('.'); -$rs = DBICTest::CD->search( +$rs = $schema->resultset('CD')->search( { 'me.year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, { join => 'artist' }); -cmp_ok($rs->count,'==', 1,"join quoted with brackets."); +eval { $rs->count }; +like($sql, qr/\QSELECT COUNT( * ) FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )\E/, 'got correct SQL for count query with bracket quoting'); my %data = ( name => 'Bill', order => '12' ); -DBICTest->schema->storage->sql_maker->quote_char('`'); -DBICTest->schema->storage->sql_maker->name_sep('.'); +$schema->storage->sql_maker->quote_char('`'); +$schema->storage->sql_maker->name_sep('.'); -cmp_ok(DBICTest->schema->storage->sql_maker->update('group', \%data), 'eq', 'UPDATE `group` SET `name` = ?, `order` = ?', "quoted table names for UPDATE"); +is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE'); +$schema->storage->debugcb($orig_debugcb); +$schema->storage->debug($orig_debug);