8 use SQL::Abstract::Test import => ['is_same_sql_bind'];
12 given => \'colA DESC',
13 expects => ' ORDER BY colA DESC',
14 expects_quoted => ' ORDER BY colA DESC',
18 expects => ' ORDER BY colA',
19 expects_quoted => ' ORDER BY `colA`',
21 { # it may look odd, but this is the desired behaviour (mst)
23 expects => ' ORDER BY colA DESC',
24 expects_quoted => ' ORDER BY `colA DESC`',
27 given => [qw/colA colB/],
28 expects => ' ORDER BY colA, colB',
29 expects_quoted => ' ORDER BY `colA`, `colB`',
31 { # it may look odd, but this is the desired behaviour (mst)
32 given => ['colA ASC', 'colB DESC'],
33 expects => ' ORDER BY colA ASC, colB DESC',
34 expects_quoted => ' ORDER BY `colA ASC`, `colB DESC`',
37 given => {-asc => 'colA'},
38 expects => ' ORDER BY colA ASC',
39 expects_quoted => ' ORDER BY `colA` ASC',
42 given => {-desc => 'colB'},
43 expects => ' ORDER BY colB DESC',
44 expects_quoted => ' ORDER BY `colB` DESC',
47 given => [{-asc => 'colA'}, {-desc => 'colB'}],
48 expects => ' ORDER BY colA ASC, colB DESC',
49 expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC',
52 given => ['colA', {-desc => 'colB'}],
53 expects => ' ORDER BY colA, colB DESC',
54 expects_quoted => ' ORDER BY `colA`, `colB` DESC',
68 given => [{-desc => [ qw/colA colB/ ] }],
69 expects => ' ORDER BY colA DESC, colB DESC',
70 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC',
73 given => [{-desc => [ qw/colA colB/ ] }, {-asc => 'colC'}],
74 expects => ' ORDER BY colA DESC, colB DESC, colC ASC',
75 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC',
78 given => [{-desc => [ qw/colA colB/ ] }, {-asc => [ qw/colC colD/ ] }],
79 expects => ' ORDER BY colA DESC, colB DESC, colC ASC, colD ASC',
80 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` ASC, `colD` ASC',
83 given => [{-desc => [ qw/colA colB/ ] }, {-desc => 'colC' }],
84 expects => ' ORDER BY colA DESC, colB DESC, colC DESC',
85 expects_quoted => ' ORDER BY `colA` DESC, `colB` DESC, `colC` DESC',
88 given => [{ -asc => 'colA' }, { -desc => [qw/colB/] }, { -asc => [qw/colC colD/] }],
89 expects => ' ORDER BY colA ASC, colB DESC, colC ASC, colD ASC',
90 expects_quoted => ' ORDER BY `colA` ASC, `colB` DESC, `colC` ASC, `colD` ASC',
93 given => { -desc => \['colA LIKE ?', 'test'] },
94 expects => ' ORDER BY colA LIKE ? DESC',
95 expects_quoted => ' ORDER BY colA LIKE ? DESC',
99 given => \['colA LIKE ? DESC', 'test'],
100 expects => ' ORDER BY colA LIKE ? DESC',
101 expects_quoted => ' ORDER BY colA LIKE ? DESC',
105 given => [ { -asc => \['colA'] }, { -desc => \['colB LIKE ?', 'test'] }, { -asc => \['colC LIKE ?', 'tost'] }],
106 expects => ' ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
107 expects_quoted => ' ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
108 bind => [qw/test tost/],
112 my $sql = SQL::Abstract->new;
113 my $sqlq = SQL::Abstract->new({quote_char => '`'});
115 for my $case (@cases) {
118 ($stat, @bind) = $sql->where(undef, $case->{given});
126 ($stat, @bind) = $sqlq->where(undef, $case->{given});
130 $case->{expects_quoted},
136 sub { $sql->_order_by({-desc => 'colA', -asc => 'colB' }) },
137 qr/hash passed .+ must have exactly one key/,
138 'Undeterministic order exception',
142 sub { $sql->_order_by([ {-desc => 'colA', -asc => 'colB' } ]) },
143 qr/hash passed .+ must have exactly one key/,
144 'Undeterministic order exception',
148 sub { $sql->_order_by({-desc => [ qw/colA colB/ ], -asc => [ qw/colC colD/ ] }) },
149 qr/hash passed .+ must have exactly one key/,
150 'Undeterministic order exception',