[Bast-commits] r8021 - in
DBIx-Class/0.08/branches/mssql_rno_pagination/t: . sqlahacks
frew at dev.catalyst.perl.org
frew at dev.catalyst.perl.org
Fri Dec 4 00:37:07 GMT 2009
Author: frew
Date: 2009-12-04 00:37:06 +0000 (Fri, 04 Dec 2009)
New Revision: 8021
Added:
DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/
DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes_newstyle.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42rno.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42toplimit.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker_quote.t
Removed:
DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes_newstyle.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/42rno.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/42toplimit.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker.t
DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker_quote.t
Log:
first shot at moving stuff around
Deleted: DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes.t 2009-12-04 00:33:28 UTC (rev 8020)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -1,75 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use IO::File;
-
-use lib qw(t/lib);
-use DBIC::SqlMakerTest;
-
-BEGIN {
- eval "use DBD::SQLite";
- plan $@
- ? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 7 );
-}
-
-
-use_ok('DBICTest');
-use_ok('DBIC::DebugObj');
-my $schema = DBICTest->init_schema();
-
-#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/));
-
-$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;
-
-$rs = $schema->resultset('CD')->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'
-);
-
-my $order = 'year DESC';
-$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 });
-eval { $rs->first };
-like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
-
-$schema->storage->sql_maker->quote_char([qw/[ ]/]);
-$schema->storage->sql_maker->name_sep('.');
-
-$rs = $schema->resultset('CD')->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 bracket quoting'
-);
-
-my %data = (
- name => 'Bill',
- order => '12'
-);
-
-$schema->storage->sql_maker->quote_char('`');
-$schema->storage->sql_maker->name_sep('.');
-
-is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
Deleted: DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes_newstyle.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes_newstyle.t 2009-12-04 00:33:28 UTC (rev 8020)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes_newstyle.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -1,92 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use IO::File;
-
-use lib qw(t/lib);
-use DBIC::SqlMakerTest;
-
-BEGIN {
- eval "use DBD::SQLite";
- plan $@
- ? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 7 );
-}
-
-use_ok('DBICTest');
-use_ok('DBIC::DebugObj');
-
-my $schema = DBICTest->init_schema();
-
-#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/));
-
-my $dsn = $schema->storage->_dbi_connect_info->[0];
-$schema->connection(
- $dsn,
- undef,
- undef,
- { AutoCommit => 1 },
- { quote_char => '`', name_sep => '.' },
-);
-
-my ($sql, @bind);
-$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
-$schema->storage->debug(1);
-
-my $rs;
-
-$rs = $schema->resultset('CD')->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'
-);
-
-my $order = 'year DESC';
-$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 });
-eval { $rs->first };
-like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
-
-$schema->connection(
- $dsn,
- undef,
- undef,
- { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' }
-);
-
-$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
-$schema->storage->debug(1);
-
-$rs = $schema->resultset('CD')->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 bracket quoting'
-);
-
-my %data = (
- name => 'Bill',
- order => '12'
-);
-
-$schema->connection(
- $dsn,
- undef,
- undef,
- { AutoCommit => 1, quote_char => '`', name_sep => '.' }
-);
-
-is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
Deleted: DBIx-Class/0.08/branches/mssql_rno_pagination/t/42rno.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/42rno.t 2009-12-04 00:33:28 UTC (rev 8020)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/42rno.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -1,148 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-use DBIC::SqlMakerTest;
-
-my $schema = DBICTest->init_schema;
-$schema->storage_type('::DBI::MSSQL');
-
-# Trick the sqlite DB to use Top limit emulation
-# We could test all of this via $sq->$op directly,
-# but some conditions need a $rsrc
-delete $schema->storage->_sql_maker->{_cached_syntax};
-$schema->storage->_sql_maker->limit_dialect ('RowNumberOver');
-
-my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { prefetch => 'owner', rows => 1, offset => 3 });
-
-sub default_test_order {
- my $order_by = shift;
- is_same_sql_bind(
- $rs->search ({}, {order_by => $order_by})->as_query,
- "(SELECT me__id, me__source, me__owner, me__title, me__price, owner__id, owner__name FROM
- (
- SELECT Q1.*, ROW_NUMBER() OVER( ) AS ROW_NUM FROM (
- SELECT me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name
- FROM books me JOIN owners owner ON owner.id = me.owner WHERE ( source = ? )
- ) Q1
- ) Q2
- WHERE ROW_NUM BETWEEN 4 and 4
- )",
- [ [ source => 'Library' ] ],
- );
-}
-
-sub test_order {
- my $args = shift;
-
- my $req_order = $args->{order_req}
- ? "ORDER BY $args->{order_req}"
- : ''
- ;
-
- is_same_sql_bind(
- $rs->search ({}, {order_by => $args->{order_by}})->as_query,
- "(SELECT me__id, me__source, me__owner, me__title, me__price, owner__id, owner__name FROM
- (
- SELECT Q1.*, ROW_NUMBER() OVER( ) AS ROW_NUM FROM (
- SELECT me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name
- FROM books me JOIN owners owner ON owner.id = me.owner WHERE ( source = ? )
- $req_order
- ) Q1
- ) Q2
- WHERE ROW_NUM BETWEEN 4 and 4
- )",
- [ [ source => 'Library' ] ],
- );
-}
-
-my @tests = (
- {
- order_by => \'foo DESC',
- order_req => 'foo DESC',
- order_inner => 'foo DESC',
- order_outer => 'foo ASC'
- },
- {
- order_by => { -asc => 'foo' },
- order_req => 'foo ASC',
- order_inner => 'foo ASC',
- order_outer => 'foo DESC',
- },
- {
- order_by => 'foo',
- order_req => 'foo',
- order_inner => 'foo ASC',
- order_outer => 'foo DESC',
- },
- {
- order_by => [ qw{ foo bar} ],
- order_req => 'foo, bar',
- order_inner => 'foo ASC,bar ASC',
- order_outer => 'foo DESC, bar DESC',
- },
- {
- order_by => { -desc => 'foo' },
- order_req => 'foo DESC',
- order_inner => 'foo DESC',
- order_outer => 'foo ASC',
- },
- {
- order_by => ['foo', { -desc => 'bar' } ],
- order_req => 'foo, bar DESC',
- order_inner => 'foo ASC, bar DESC',
- order_outer => 'foo DESC, bar ASC',
- },
- {
- order_by => { -asc => [qw{ foo bar }] },
- order_req => 'foo ASC, bar ASC',
- order_inner => 'foo ASC, bar ASC',
- order_outer => 'foo DESC, bar DESC',
- },
- {
- order_by => [
- { -asc => 'foo' },
- { -desc => [qw{bar}] },
- { -asc => [qw{hello sensors}]},
- ],
- order_req => 'foo ASC, bar DESC, hello ASC, sensors ASC',
- order_inner => 'foo ASC, bar DESC, hello ASC, sensors ASC',
- order_outer => 'foo DESC, bar ASC, hello DESC, sensors DESC',
- },
-);
-
-my @default_tests = ( undef, '', {}, [] );
-
-plan (tests => scalar @tests + scalar @default_tests + 1);
-
-test_order ($_) for @tests;
-default_test_order ($_) for @default_tests;
-
-
-is_same_sql_bind (
- $rs->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
-'(SELECT
-me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name FROM
- ( SELECT
- id, source, owner, title, price FROM
- ( SELECT
- TOP 1 id, source, owner, title, price FROM
- ( SELECT
- TOP 4 me.id, me.source, me.owner, me.title, me.price FROM
- books me JOIN
- owners owner ON owner.id = me.owner
- WHERE ( source = ? )
- GROUP BY title
- ORDER BY title ASC
- ) me
- ORDER BY title DESC
- ) me
- ORDER BY title
- ) me JOIN
- owners owner ON owner.id = me.owner WHERE
- ( source = ? )
- ORDER BY title)' ,
- [ [ source => 'Library' ], [ source => 'Library' ] ],
-);
Deleted: DBIx-Class/0.08/branches/mssql_rno_pagination/t/42toplimit.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/42toplimit.t 2009-12-04 00:33:28 UTC (rev 8020)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/42toplimit.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -1,152 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-use DBIC::SqlMakerTest;
-
-my $schema = DBICTest->init_schema;
-
-# Trick the sqlite DB to use Top limit emulation
-# We could test all of this via $sq->$op directly,
-# but some conditions need a $rsrc
-delete $schema->storage->_sql_maker->{_cached_syntax};
-$schema->storage->_sql_maker->limit_dialect ('Top');
-
-my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { prefetch => 'owner', rows => 1, offset => 3 });
-
-sub default_test_order {
- my $order_by = shift;
- is_same_sql_bind(
- $rs->search ({}, {order_by => $order_by})->as_query,
- "(SELECT
- TOP 1 me__id, source, owner, title, price, owner__id, name FROM
- (SELECT
- TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name
- FROM books me
- JOIN owners owner ON
- owner.id = me.owner
- WHERE ( source = ? )
- ORDER BY me__id ASC
- ) me ORDER BY me__id DESC
- )",
- [ [ source => 'Library' ] ],
- );
-}
-
-sub test_order {
- my $args = shift;
-
- my $req_order = $args->{order_req}
- ? "ORDER BY $args->{order_req}"
- : ''
- ;
-
- is_same_sql_bind(
- $rs->search ({}, {order_by => $args->{order_by}})->as_query,
- "(SELECT
- me__id, source, owner, title, price, owner__id, name FROM
- (SELECT
- TOP 1 me__id, source, owner, title, price, owner__id, name FROM
- (SELECT
- TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name FROM
- books me
- JOIN owners owner ON owner.id = me.owner
- WHERE ( source = ? )
- ORDER BY $args->{order_inner}
- ) me ORDER BY $args->{order_outer}
- ) me $req_order
- )",
- [ [ source => 'Library' ] ],
- );
-}
-
-my @tests = (
- {
- order_by => \'foo DESC',
- order_req => 'foo DESC',
- order_inner => 'foo DESC',
- order_outer => 'foo ASC'
- },
- {
- order_by => { -asc => 'foo' },
- order_req => 'foo ASC',
- order_inner => 'foo ASC',
- order_outer => 'foo DESC',
- },
- {
- order_by => 'foo',
- order_req => 'foo',
- order_inner => 'foo ASC',
- order_outer => 'foo DESC',
- },
- {
- order_by => [ qw{ foo bar} ],
- order_req => 'foo, bar',
- order_inner => 'foo ASC,bar ASC',
- order_outer => 'foo DESC, bar DESC',
- },
- {
- order_by => { -desc => 'foo' },
- order_req => 'foo DESC',
- order_inner => 'foo DESC',
- order_outer => 'foo ASC',
- },
- {
- order_by => ['foo', { -desc => 'bar' } ],
- order_req => 'foo, bar DESC',
- order_inner => 'foo ASC, bar DESC',
- order_outer => 'foo DESC, bar ASC',
- },
- {
- order_by => { -asc => [qw{ foo bar }] },
- order_req => 'foo ASC, bar ASC',
- order_inner => 'foo ASC, bar ASC',
- order_outer => 'foo DESC, bar DESC',
- },
- {
- order_by => [
- { -asc => 'foo' },
- { -desc => [qw{bar}] },
- { -asc => [qw{hello sensors}]},
- ],
- order_req => 'foo ASC, bar DESC, hello ASC, sensors ASC',
- order_inner => 'foo ASC, bar DESC, hello ASC, sensors ASC',
- order_outer => 'foo DESC, bar ASC, hello DESC, sensors DESC',
- },
-);
-
-my @default_tests = ( undef, '', {}, [] );
-
-plan (tests => scalar @tests + scalar @default_tests + 1);
-
-test_order ($_) for @tests;
-default_test_order ($_) for @default_tests;
-
-
-is_same_sql_bind (
- $rs->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
-'(SELECT
-me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name FROM
- ( SELECT
- id, source, owner, title, price FROM
- ( SELECT
- TOP 1 id, source, owner, title, price FROM
- ( SELECT
- TOP 4 me.id, me.source, me.owner, me.title, me.price FROM
- books me JOIN
- owners owner ON owner.id = me.owner
- WHERE ( source = ? )
- GROUP BY title
- ORDER BY title ASC
- ) me
- ORDER BY title DESC
- ) me
- ORDER BY title
- ) me JOIN
- owners owner ON owner.id = me.owner WHERE
- ( source = ? )
- ORDER BY title)' ,
- [ [ source => 'Library' ], [ source => 'Library' ] ],
-);
Deleted: DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker.t 2009-12-04 00:33:28 UTC (rev 8020)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -1,78 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-use Test::Exception;
-
-use lib qw(t/lib);
-use DBIC::SqlMakerTest;
-
-use_ok('DBICTest');
-
-my $schema = DBICTest->init_schema(no_deploy => 1);
-
-my $sql_maker = $schema->storage->sql_maker;
-
-
-{
- my ($sql, @bind) = $sql_maker->insert(
- 'lottery',
- {
- 'day' => '2008-11-16',
- 'numbers' => [13, 21, 34, 55, 89]
- }
- );
-
- is_same_sql_bind(
- $sql, \@bind,
- q/INSERT INTO lottery (day, numbers) VALUES (?, ?)/,
- [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ],
- 'sql_maker passes arrayrefs in insert'
- );
-
-
- ($sql, @bind) = $sql_maker->update(
- 'lottery',
- {
- 'day' => '2008-11-16',
- 'numbers' => [13, 21, 34, 55, 89]
- }
- );
-
- is_same_sql_bind(
- $sql, \@bind,
- q/UPDATE lottery SET day = ?, numbers = ?/,
- [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ],
- 'sql_maker passes arrayrefs in update'
- );
-}
-
-# make sure the cookbook caveat of { $op, \'...' } no longer applies
-{
- my ($sql, @bind) = $sql_maker->where({
- last_attempt => \ '< now() - interval "12 hours"',
- next_attempt => { '<', \ 'now() - interval "12 hours"' },
- created => [
- { '<=', \ '1969' },
- \ '> 1984',
- ],
- });
- is_same_sql_bind(
- $sql,
- \@bind,
- 'WHERE
- (created <= 1969 OR created > 1984 )
- AND last_attempt < now() - interval "12 hours"
- AND next_attempt < now() - interval "12 hours"
- ',
- [],
- );
-}
-
-# Make sure the carp/croak override in SQLA works (via SQLAHacks)
-my $file = quotemeta (__FILE__);
-throws_ok (sub {
- $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query;
-}, qr/$file/, 'Exception correctly croak()ed');
-
-done_testing;
Deleted: DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker_quote.t
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker_quote.t 2009-12-04 00:33:28 UTC (rev 8020)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker_quote.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -1,357 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-
-use lib qw(t/lib);
-use DBIC::SqlMakerTest;
-
-use_ok('DBICTest');
-
-my $schema = DBICTest->init_schema();
-
-my $sql_maker = $schema->storage->sql_maker;
-
-$sql_maker->quote_char('`');
-$sql_maker->name_sep('.');
-
-my ($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- },
- [
- {
- 'artist' => 'artist',
- '-join_type' => ''
- },
- {
- 'artist.artistid' => 'me.artist'
- }
- ],
- [
- {
- 'tracks' => 'tracks',
- '-join_type' => 'left'
- },
- {
- 'tracks.cd' => 'me.cdid'
- }
- ],
- ],
- [
- 'me.cdid',
- { count => 'tracks.cd' },
- { min => 'me.year', -as => 'me.minyear' },
- ],
- {
- 'artist.name' => 'Caterwauler McCrae',
- 'me.year' => 2001
- },
- [],
- undef,
- undef
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/
- SELECT `me`.`cdid`, COUNT( `tracks`.`cd` ), MIN( `me`.`year` ) AS `me`.`minyear`
- FROM `cd` `me`
- JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` )
- LEFT JOIN `tracks` `tracks` ON ( `tracks`.`cd` = `me`.`cdid` )
- WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )
- /,
- [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
- 'got correct SQL and bind parameters for complex select query with quoting'
-);
-
-
-($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- }
- ],
- [
- 'me.cdid',
- 'me.artist',
- 'me.title',
- 'me.year'
- ],
- undef,
- 'year DESC',
- undef,
- undef
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`/, [],
- 'scalar ORDER BY okay (single value)'
-);
-
-
-($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- }
- ],
- [
- 'me.cdid',
- 'me.artist',
- 'me.title',
- 'me.year'
- ],
- undef,
- [
- 'year DESC',
- 'title ASC'
- ],
- undef,
- undef
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`, `title ASC`/, [],
- 'scalar ORDER BY okay (multiple values)'
-);
-
-{
- ($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- }
- ],
- [
- 'me.cdid',
- 'me.artist',
- 'me.title',
- 'me.year'
- ],
- undef,
- { -desc => 'year' },
- undef,
- undef
- );
-
- is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, [],
- 'hashref ORDER BY okay (single value)'
- );
-
-
- ($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- }
- ],
- [
- 'me.cdid',
- 'me.artist',
- 'me.title',
- 'me.year'
- ],
- undef,
- [
- { -desc => 'year' },
- { -asc => 'title' }
- ],
- undef,
- undef
- );
-
- is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC, `title` ASC/, [],
- 'hashref ORDER BY okay (multiple values)'
- );
-
-}
-
-
-($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- }
- ],
- [
- 'me.cdid',
- 'me.artist',
- 'me.title',
- 'me.year'
- ],
- undef,
- \'year DESC',
- undef,
- undef
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/, [],
- 'did not quote ORDER BY with scalarref (single value)'
-);
-
-
-($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- }
- ],
- [
- 'me.cdid',
- 'me.artist',
- 'me.title',
- 'me.year'
- ],
- undef,
- [
- \'year DESC',
- \'title ASC'
- ],
- undef,
- undef
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC, title ASC/, [],
- 'did not quote ORDER BY with scalarref (multiple values)'
-);
-
-
-($sql, @bind) = $sql_maker->select(
- [ { me => 'cd' } ],
- [qw/ me.cdid me.artist me.title /],
- { cdid => \['rlike ?', [cdid => 'X'] ] },
- { group_by => 'title', having => \['count(me.artist) > ?', [ cnt => 2] ] },
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title` FROM `cd` `me` WHERE ( `cdid` rlike ? ) GROUP BY `title` HAVING count(me.artist) > ?/,
- [ [ cdid => 'X'], ['cnt' => '2'] ],
- 'Quoting works with where/having arrayrefsrefs',
-);
-
-
-($sql, @bind) = $sql_maker->select(
- [ { me => 'cd' } ],
- [qw/ me.cdid me.artist me.title /],
- { cdid => \'rlike X' },
- { group_by => 'title', having => \'count(me.artist) > 2' },
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title` FROM `cd` `me` WHERE ( `cdid` rlike X ) GROUP BY `title` HAVING count(me.artist) > 2/,
- [],
- 'Quoting works with where/having scalarrefs',
-);
-
-
-($sql, @bind) = $sql_maker->update(
- 'group',
- {
- 'order' => '12',
- 'name' => 'Bill'
- }
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/UPDATE `group` SET `name` = ?, `order` = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
- 'quoted table names for UPDATE'
-);
-
-{
- ($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- }
- ],
- [
- 'me.*'
- ],
- undef,
- [],
- undef,
- undef
- );
-
- is_same_sql_bind(
- $sql, \@bind,
- q/SELECT `me`.* FROM `cd` `me`/, [],
- 'select attr with me.* is right'
- );
-}
-
-
-$sql_maker->quote_char([qw/[ ]/]);
-
-($sql, @bind) = $sql_maker->select(
- [
- {
- 'me' => 'cd'
- },
- [
- {
- 'artist' => 'artist',
- '-join_type' => ''
- },
- {
- 'artist.artistid' => 'me.artist'
- }
- ]
- ],
- [
- {
- max => 'rank',
- -as => 'max_rank',
- },
- 'rank',
- {
- 'count' => '*',
- -as => 'cnt',
- }
- ],
- {
- 'artist.name' => 'Caterwauler McCrae',
- 'me.year' => 2001
- },
- [],
- undef,
- undef
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/SELECT MAX ( [rank] ) AS [max_rank], [rank], COUNT( * ) AS [cnt] FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
- 'got correct SQL and bind parameters for count query with bracket quoting'
-);
-
-
-($sql, @bind) = $sql_maker->update(
- 'group',
- {
- 'order' => '12',
- 'name' => 'Bill'
- }
-);
-
-is_same_sql_bind(
- $sql, \@bind,
- q/UPDATE [group] SET [name] = ?, [order] = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
- 'bracket quoted table names for UPDATE'
-);
-
-done_testing;
Copied: DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes.t (from rev 8018, DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes.t)
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes.t (rev 0)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -0,0 +1,75 @@
+use strict;
+use warnings;
+
+use Test::More;
+use IO::File;
+
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+
+BEGIN {
+ eval "use DBD::SQLite";
+ plan $@
+ ? ( skip_all => 'needs DBD::SQLite for testing' )
+ : ( tests => 7 );
+}
+
+
+use_ok('DBICTest');
+use_ok('DBIC::DebugObj');
+my $schema = DBICTest->init_schema();
+
+#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/));
+
+$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;
+
+$rs = $schema->resultset('CD')->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'
+);
+
+my $order = 'year DESC';
+$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 });
+eval { $rs->first };
+like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
+
+$schema->storage->sql_maker->quote_char([qw/[ ]/]);
+$schema->storage->sql_maker->name_sep('.');
+
+$rs = $schema->resultset('CD')->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 bracket quoting'
+);
+
+my %data = (
+ name => 'Bill',
+ order => '12'
+);
+
+$schema->storage->sql_maker->quote_char('`');
+$schema->storage->sql_maker->name_sep('.');
+
+is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
Copied: DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes_newstyle.t (from rev 8018, DBIx-Class/0.08/branches/mssql_rno_pagination/t/19quotes_newstyle.t)
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes_newstyle.t (rev 0)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/19quotes_newstyle.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -0,0 +1,92 @@
+use strict;
+use warnings;
+
+use Test::More;
+use IO::File;
+
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+
+BEGIN {
+ eval "use DBD::SQLite";
+ plan $@
+ ? ( skip_all => 'needs DBD::SQLite for testing' )
+ : ( tests => 7 );
+}
+
+use_ok('DBICTest');
+use_ok('DBIC::DebugObj');
+
+my $schema = DBICTest->init_schema();
+
+#diag('Testing against ' . join(' ', map { $schema->storage->dbh->get_info($_) } qw/17 18/));
+
+my $dsn = $schema->storage->_dbi_connect_info->[0];
+$schema->connection(
+ $dsn,
+ undef,
+ undef,
+ { AutoCommit => 1 },
+ { quote_char => '`', name_sep => '.' },
+);
+
+my ($sql, @bind);
+$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
+$schema->storage->debug(1);
+
+my $rs;
+
+$rs = $schema->resultset('CD')->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'
+);
+
+my $order = 'year DESC';
+$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 });
+eval { $rs->first };
+like($sql, qr/ORDER BY \Q${order}\E/, 'did not quote ORDER BY with scalarref');
+
+$schema->connection(
+ $dsn,
+ undef,
+ undef,
+ { AutoCommit => 1, quote_char => [qw/[ ]/], name_sep => '.' }
+);
+
+$schema->storage->debugobj(DBIC::DebugObj->new(\$sql, \@bind)),
+$schema->storage->debug(1);
+
+$rs = $schema->resultset('CD')->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 bracket quoting'
+);
+
+my %data = (
+ name => 'Bill',
+ order => '12'
+);
+
+$schema->connection(
+ $dsn,
+ undef,
+ undef,
+ { AutoCommit => 1, quote_char => '`', name_sep => '.' }
+);
+
+is($schema->storage->sql_maker->update('group', \%data), 'UPDATE `group` SET `name` = ?, `order` = ?', 'quoted table names for UPDATE');
Copied: DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42rno.t (from rev 8020, DBIx-Class/0.08/branches/mssql_rno_pagination/t/42rno.t)
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42rno.t (rev 0)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42rno.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -0,0 +1,148 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBIC::SqlMakerTest;
+
+my $schema = DBICTest->init_schema;
+$schema->storage_type('::DBI::MSSQL');
+
+# Trick the sqlite DB to use Top limit emulation
+# We could test all of this via $sq->$op directly,
+# but some conditions need a $rsrc
+delete $schema->storage->_sql_maker->{_cached_syntax};
+$schema->storage->_sql_maker->limit_dialect ('RowNumberOver');
+
+my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { prefetch => 'owner', rows => 1, offset => 3 });
+
+sub default_test_order {
+ my $order_by = shift;
+ is_same_sql_bind(
+ $rs->search ({}, {order_by => $order_by})->as_query,
+ "(SELECT me__id, me__source, me__owner, me__title, me__price, owner__id, owner__name FROM
+ (
+ SELECT Q1.*, ROW_NUMBER() OVER( ) AS ROW_NUM FROM (
+ SELECT me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name
+ FROM books me JOIN owners owner ON owner.id = me.owner WHERE ( source = ? )
+ ) Q1
+ ) Q2
+ WHERE ROW_NUM BETWEEN 4 and 4
+ )",
+ [ [ source => 'Library' ] ],
+ );
+}
+
+sub test_order {
+ my $args = shift;
+
+ my $req_order = $args->{order_req}
+ ? "ORDER BY $args->{order_req}"
+ : ''
+ ;
+
+ is_same_sql_bind(
+ $rs->search ({}, {order_by => $args->{order_by}})->as_query,
+ "(SELECT me__id, me__source, me__owner, me__title, me__price, owner__id, owner__name FROM
+ (
+ SELECT Q1.*, ROW_NUMBER() OVER( ) AS ROW_NUM FROM (
+ SELECT me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name
+ FROM books me JOIN owners owner ON owner.id = me.owner WHERE ( source = ? )
+ $req_order
+ ) Q1
+ ) Q2
+ WHERE ROW_NUM BETWEEN 4 and 4
+ )",
+ [ [ source => 'Library' ] ],
+ );
+}
+
+my @tests = (
+ {
+ order_by => \'foo DESC',
+ order_req => 'foo DESC',
+ order_inner => 'foo DESC',
+ order_outer => 'foo ASC'
+ },
+ {
+ order_by => { -asc => 'foo' },
+ order_req => 'foo ASC',
+ order_inner => 'foo ASC',
+ order_outer => 'foo DESC',
+ },
+ {
+ order_by => 'foo',
+ order_req => 'foo',
+ order_inner => 'foo ASC',
+ order_outer => 'foo DESC',
+ },
+ {
+ order_by => [ qw{ foo bar} ],
+ order_req => 'foo, bar',
+ order_inner => 'foo ASC,bar ASC',
+ order_outer => 'foo DESC, bar DESC',
+ },
+ {
+ order_by => { -desc => 'foo' },
+ order_req => 'foo DESC',
+ order_inner => 'foo DESC',
+ order_outer => 'foo ASC',
+ },
+ {
+ order_by => ['foo', { -desc => 'bar' } ],
+ order_req => 'foo, bar DESC',
+ order_inner => 'foo ASC, bar DESC',
+ order_outer => 'foo DESC, bar ASC',
+ },
+ {
+ order_by => { -asc => [qw{ foo bar }] },
+ order_req => 'foo ASC, bar ASC',
+ order_inner => 'foo ASC, bar ASC',
+ order_outer => 'foo DESC, bar DESC',
+ },
+ {
+ order_by => [
+ { -asc => 'foo' },
+ { -desc => [qw{bar}] },
+ { -asc => [qw{hello sensors}]},
+ ],
+ order_req => 'foo ASC, bar DESC, hello ASC, sensors ASC',
+ order_inner => 'foo ASC, bar DESC, hello ASC, sensors ASC',
+ order_outer => 'foo DESC, bar ASC, hello DESC, sensors DESC',
+ },
+);
+
+my @default_tests = ( undef, '', {}, [] );
+
+plan (tests => scalar @tests + scalar @default_tests + 1);
+
+test_order ($_) for @tests;
+default_test_order ($_) for @default_tests;
+
+
+is_same_sql_bind (
+ $rs->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
+'(SELECT
+me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name FROM
+ ( SELECT
+ id, source, owner, title, price FROM
+ ( SELECT
+ TOP 1 id, source, owner, title, price FROM
+ ( SELECT
+ TOP 4 me.id, me.source, me.owner, me.title, me.price FROM
+ books me JOIN
+ owners owner ON owner.id = me.owner
+ WHERE ( source = ? )
+ GROUP BY title
+ ORDER BY title ASC
+ ) me
+ ORDER BY title DESC
+ ) me
+ ORDER BY title
+ ) me JOIN
+ owners owner ON owner.id = me.owner WHERE
+ ( source = ? )
+ ORDER BY title)' ,
+ [ [ source => 'Library' ], [ source => 'Library' ] ],
+);
Copied: DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42toplimit.t (from rev 8018, DBIx-Class/0.08/branches/mssql_rno_pagination/t/42toplimit.t)
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42toplimit.t (rev 0)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/42toplimit.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -0,0 +1,152 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBIC::SqlMakerTest;
+
+my $schema = DBICTest->init_schema;
+
+# Trick the sqlite DB to use Top limit emulation
+# We could test all of this via $sq->$op directly,
+# but some conditions need a $rsrc
+delete $schema->storage->_sql_maker->{_cached_syntax};
+$schema->storage->_sql_maker->limit_dialect ('Top');
+
+my $rs = $schema->resultset ('BooksInLibrary')->search ({}, { prefetch => 'owner', rows => 1, offset => 3 });
+
+sub default_test_order {
+ my $order_by = shift;
+ is_same_sql_bind(
+ $rs->search ({}, {order_by => $order_by})->as_query,
+ "(SELECT
+ TOP 1 me__id, source, owner, title, price, owner__id, name FROM
+ (SELECT
+ TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name
+ FROM books me
+ JOIN owners owner ON
+ owner.id = me.owner
+ WHERE ( source = ? )
+ ORDER BY me__id ASC
+ ) me ORDER BY me__id DESC
+ )",
+ [ [ source => 'Library' ] ],
+ );
+}
+
+sub test_order {
+ my $args = shift;
+
+ my $req_order = $args->{order_req}
+ ? "ORDER BY $args->{order_req}"
+ : ''
+ ;
+
+ is_same_sql_bind(
+ $rs->search ({}, {order_by => $args->{order_by}})->as_query,
+ "(SELECT
+ me__id, source, owner, title, price, owner__id, name FROM
+ (SELECT
+ TOP 1 me__id, source, owner, title, price, owner__id, name FROM
+ (SELECT
+ TOP 4 me.id AS me__id, me.source, me.owner, me.title, me.price, owner.id AS owner__id, owner.name FROM
+ books me
+ JOIN owners owner ON owner.id = me.owner
+ WHERE ( source = ? )
+ ORDER BY $args->{order_inner}
+ ) me ORDER BY $args->{order_outer}
+ ) me $req_order
+ )",
+ [ [ source => 'Library' ] ],
+ );
+}
+
+my @tests = (
+ {
+ order_by => \'foo DESC',
+ order_req => 'foo DESC',
+ order_inner => 'foo DESC',
+ order_outer => 'foo ASC'
+ },
+ {
+ order_by => { -asc => 'foo' },
+ order_req => 'foo ASC',
+ order_inner => 'foo ASC',
+ order_outer => 'foo DESC',
+ },
+ {
+ order_by => 'foo',
+ order_req => 'foo',
+ order_inner => 'foo ASC',
+ order_outer => 'foo DESC',
+ },
+ {
+ order_by => [ qw{ foo bar} ],
+ order_req => 'foo, bar',
+ order_inner => 'foo ASC,bar ASC',
+ order_outer => 'foo DESC, bar DESC',
+ },
+ {
+ order_by => { -desc => 'foo' },
+ order_req => 'foo DESC',
+ order_inner => 'foo DESC',
+ order_outer => 'foo ASC',
+ },
+ {
+ order_by => ['foo', { -desc => 'bar' } ],
+ order_req => 'foo, bar DESC',
+ order_inner => 'foo ASC, bar DESC',
+ order_outer => 'foo DESC, bar ASC',
+ },
+ {
+ order_by => { -asc => [qw{ foo bar }] },
+ order_req => 'foo ASC, bar ASC',
+ order_inner => 'foo ASC, bar ASC',
+ order_outer => 'foo DESC, bar DESC',
+ },
+ {
+ order_by => [
+ { -asc => 'foo' },
+ { -desc => [qw{bar}] },
+ { -asc => [qw{hello sensors}]},
+ ],
+ order_req => 'foo ASC, bar DESC, hello ASC, sensors ASC',
+ order_inner => 'foo ASC, bar DESC, hello ASC, sensors ASC',
+ order_outer => 'foo DESC, bar ASC, hello DESC, sensors DESC',
+ },
+);
+
+my @default_tests = ( undef, '', {}, [] );
+
+plan (tests => scalar @tests + scalar @default_tests + 1);
+
+test_order ($_) for @tests;
+default_test_order ($_) for @default_tests;
+
+
+is_same_sql_bind (
+ $rs->search ({}, { group_by => 'title', order_by => 'title' })->as_query,
+'(SELECT
+me.id, me.source, me.owner, me.title, me.price, owner.id, owner.name FROM
+ ( SELECT
+ id, source, owner, title, price FROM
+ ( SELECT
+ TOP 1 id, source, owner, title, price FROM
+ ( SELECT
+ TOP 4 me.id, me.source, me.owner, me.title, me.price FROM
+ books me JOIN
+ owners owner ON owner.id = me.owner
+ WHERE ( source = ? )
+ GROUP BY title
+ ORDER BY title ASC
+ ) me
+ ORDER BY title DESC
+ ) me
+ ORDER BY title
+ ) me JOIN
+ owners owner ON owner.id = me.owner WHERE
+ ( source = ? )
+ ORDER BY title)' ,
+ [ [ source => 'Library' ], [ source => 'Library' ] ],
+);
Copied: DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker.t (from rev 8018, DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker.t)
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker.t (rev 0)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -0,0 +1,78 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+
+use_ok('DBICTest');
+
+my $schema = DBICTest->init_schema(no_deploy => 1);
+
+my $sql_maker = $schema->storage->sql_maker;
+
+
+{
+ my ($sql, @bind) = $sql_maker->insert(
+ 'lottery',
+ {
+ 'day' => '2008-11-16',
+ 'numbers' => [13, 21, 34, 55, 89]
+ }
+ );
+
+ is_same_sql_bind(
+ $sql, \@bind,
+ q/INSERT INTO lottery (day, numbers) VALUES (?, ?)/,
+ [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ],
+ 'sql_maker passes arrayrefs in insert'
+ );
+
+
+ ($sql, @bind) = $sql_maker->update(
+ 'lottery',
+ {
+ 'day' => '2008-11-16',
+ 'numbers' => [13, 21, 34, 55, 89]
+ }
+ );
+
+ is_same_sql_bind(
+ $sql, \@bind,
+ q/UPDATE lottery SET day = ?, numbers = ?/,
+ [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ],
+ 'sql_maker passes arrayrefs in update'
+ );
+}
+
+# make sure the cookbook caveat of { $op, \'...' } no longer applies
+{
+ my ($sql, @bind) = $sql_maker->where({
+ last_attempt => \ '< now() - interval "12 hours"',
+ next_attempt => { '<', \ 'now() - interval "12 hours"' },
+ created => [
+ { '<=', \ '1969' },
+ \ '> 1984',
+ ],
+ });
+ is_same_sql_bind(
+ $sql,
+ \@bind,
+ 'WHERE
+ (created <= 1969 OR created > 1984 )
+ AND last_attempt < now() - interval "12 hours"
+ AND next_attempt < now() - interval "12 hours"
+ ',
+ [],
+ );
+}
+
+# Make sure the carp/croak override in SQLA works (via SQLAHacks)
+my $file = quotemeta (__FILE__);
+throws_ok (sub {
+ $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query;
+}, qr/$file/, 'Exception correctly croak()ed');
+
+done_testing;
Copied: DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker_quote.t (from rev 8018, DBIx-Class/0.08/branches/mssql_rno_pagination/t/95sql_maker_quote.t)
===================================================================
--- DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker_quote.t (rev 0)
+++ DBIx-Class/0.08/branches/mssql_rno_pagination/t/sqlahacks/95sql_maker_quote.t 2009-12-04 00:37:06 UTC (rev 8021)
@@ -0,0 +1,357 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib qw(t/lib);
+use DBIC::SqlMakerTest;
+
+use_ok('DBICTest');
+
+my $schema = DBICTest->init_schema();
+
+my $sql_maker = $schema->storage->sql_maker;
+
+$sql_maker->quote_char('`');
+$sql_maker->name_sep('.');
+
+my ($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ },
+ [
+ {
+ 'artist' => 'artist',
+ '-join_type' => ''
+ },
+ {
+ 'artist.artistid' => 'me.artist'
+ }
+ ],
+ [
+ {
+ 'tracks' => 'tracks',
+ '-join_type' => 'left'
+ },
+ {
+ 'tracks.cd' => 'me.cdid'
+ }
+ ],
+ ],
+ [
+ 'me.cdid',
+ { count => 'tracks.cd' },
+ { min => 'me.year', -as => 'me.minyear' },
+ ],
+ {
+ 'artist.name' => 'Caterwauler McCrae',
+ 'me.year' => 2001
+ },
+ [],
+ undef,
+ undef
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/
+ SELECT `me`.`cdid`, COUNT( `tracks`.`cd` ), MIN( `me`.`year` ) AS `me`.`minyear`
+ FROM `cd` `me`
+ JOIN `artist` `artist` ON ( `artist`.`artistid` = `me`.`artist` )
+ LEFT JOIN `tracks` `tracks` ON ( `tracks`.`cd` = `me`.`cdid` )
+ WHERE ( `artist`.`name` = ? AND `me`.`year` = ? )
+ /,
+ [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
+ 'got correct SQL and bind parameters for complex select query with quoting'
+);
+
+
+($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ 'year DESC',
+ undef,
+ undef
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`/, [],
+ 'scalar ORDER BY okay (single value)'
+);
+
+
+($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ [
+ 'year DESC',
+ 'title ASC'
+ ],
+ undef,
+ undef
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year DESC`, `title ASC`/, [],
+ 'scalar ORDER BY okay (multiple values)'
+);
+
+{
+ ($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ { -desc => 'year' },
+ undef,
+ undef
+ );
+
+ is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC/, [],
+ 'hashref ORDER BY okay (single value)'
+ );
+
+
+ ($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ [
+ { -desc => 'year' },
+ { -asc => 'title' }
+ ],
+ undef,
+ undef
+ );
+
+ is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY `year` DESC, `title` ASC/, [],
+ 'hashref ORDER BY okay (multiple values)'
+ );
+
+}
+
+
+($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ \'year DESC',
+ undef,
+ undef
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC/, [],
+ 'did not quote ORDER BY with scalarref (single value)'
+);
+
+
+($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.cdid',
+ 'me.artist',
+ 'me.title',
+ 'me.year'
+ ],
+ undef,
+ [
+ \'year DESC',
+ \'title ASC'
+ ],
+ undef,
+ undef
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title`, `me`.`year` FROM `cd` `me` ORDER BY year DESC, title ASC/, [],
+ 'did not quote ORDER BY with scalarref (multiple values)'
+);
+
+
+($sql, @bind) = $sql_maker->select(
+ [ { me => 'cd' } ],
+ [qw/ me.cdid me.artist me.title /],
+ { cdid => \['rlike ?', [cdid => 'X'] ] },
+ { group_by => 'title', having => \['count(me.artist) > ?', [ cnt => 2] ] },
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title` FROM `cd` `me` WHERE ( `cdid` rlike ? ) GROUP BY `title` HAVING count(me.artist) > ?/,
+ [ [ cdid => 'X'], ['cnt' => '2'] ],
+ 'Quoting works with where/having arrayrefsrefs',
+);
+
+
+($sql, @bind) = $sql_maker->select(
+ [ { me => 'cd' } ],
+ [qw/ me.cdid me.artist me.title /],
+ { cdid => \'rlike X' },
+ { group_by => 'title', having => \'count(me.artist) > 2' },
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.`cdid`, `me`.`artist`, `me`.`title` FROM `cd` `me` WHERE ( `cdid` rlike X ) GROUP BY `title` HAVING count(me.artist) > 2/,
+ [],
+ 'Quoting works with where/having scalarrefs',
+);
+
+
+($sql, @bind) = $sql_maker->update(
+ 'group',
+ {
+ 'order' => '12',
+ 'name' => 'Bill'
+ }
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/UPDATE `group` SET `name` = ?, `order` = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
+ 'quoted table names for UPDATE'
+);
+
+{
+ ($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ }
+ ],
+ [
+ 'me.*'
+ ],
+ undef,
+ [],
+ undef,
+ undef
+ );
+
+ is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT `me`.* FROM `cd` `me`/, [],
+ 'select attr with me.* is right'
+ );
+}
+
+
+$sql_maker->quote_char([qw/[ ]/]);
+
+($sql, @bind) = $sql_maker->select(
+ [
+ {
+ 'me' => 'cd'
+ },
+ [
+ {
+ 'artist' => 'artist',
+ '-join_type' => ''
+ },
+ {
+ 'artist.artistid' => 'me.artist'
+ }
+ ]
+ ],
+ [
+ {
+ max => 'rank',
+ -as => 'max_rank',
+ },
+ 'rank',
+ {
+ 'count' => '*',
+ -as => 'cnt',
+ }
+ ],
+ {
+ 'artist.name' => 'Caterwauler McCrae',
+ 'me.year' => 2001
+ },
+ [],
+ undef,
+ undef
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/SELECT MAX ( [rank] ) AS [max_rank], [rank], COUNT( * ) AS [cnt] FROM [cd] [me] JOIN [artist] [artist] ON ( [artist].[artistid] = [me].[artist] ) WHERE ( [artist].[name] = ? AND [me].[year] = ? )/, [ ['artist.name' => 'Caterwauler McCrae'], ['me.year' => 2001] ],
+ 'got correct SQL and bind parameters for count query with bracket quoting'
+);
+
+
+($sql, @bind) = $sql_maker->update(
+ 'group',
+ {
+ 'order' => '12',
+ 'name' => 'Bill'
+ }
+);
+
+is_same_sql_bind(
+ $sql, \@bind,
+ q/UPDATE [group] SET [name] = ?, [order] = ?/, [ ['name' => 'Bill'], ['order' => '12'] ],
+ 'bracket quoted table names for UPDATE'
+);
+
+done_testing;
More information about the Bast-commits
mailing list