From: Peter Rabbitson Date: Sun, 29 Mar 2009 08:35:19 +0000 (+0000) Subject: Remove CR/LF and exec bits X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4f30591bc0678f8a5d657e79c6985606b064cd1d;p=scpubgit%2FQ-Branch.git Remove CR/LF and exec bits --- diff --git a/t/00new.t b/t/00new.t old mode 100755 new mode 100644 diff --git a/t/01generate.t b/t/01generate.t old mode 100755 new mode 100644 diff --git a/t/02where.t b/t/02where.t old mode 100755 new mode 100644 diff --git a/t/03values.t b/t/03values.t old mode 100755 new mode 100644 diff --git a/t/04modifiers.t b/t/04modifiers.t old mode 100755 new mode 100644 diff --git a/t/07subqueries.t b/t/07subqueries.t index 3c79842..d0564aa 100644 --- a/t/07subqueries.t +++ b/t/07subqueries.t @@ -1,105 +1,105 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use Test::More; - -use SQL::Abstract::Test import => ['is_same_sql_bind']; - -use SQL::Abstract; - -my $sql = SQL::Abstract->new; - -my (@tests, $sub_stmt, @sub_bind, $where); - -#1 -($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?", - 100, "foo%"); -$where = { - foo => 1234, - bar => \["IN ($sub_stmt)" => @sub_bind], - }; -push @tests, { - where => $where, - stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )", - bind => [100, "foo%", 1234], -}; - -#2 -($sub_stmt, @sub_bind) - = $sql->select("t1", "c1", {c2 => {"<" => 100}, - c3 => {-like => "foo%"}}); -$where = { - foo => 1234, - bar => \["> ALL ($sub_stmt)" => @sub_bind], - }; -push @tests, { - where => $where, - stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE ( c2 < ? AND c3 LIKE ? )) AND foo = ? )", - bind => [100, "foo%", 1234], -}; - -#3 -($sub_stmt, @sub_bind) - = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"}); -$where = { - foo => 1234, - -nest => \["EXISTS ($sub_stmt)" => @sub_bind], - }; -push @tests, { - where => $where, - stmt => " WHERE ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? )", - bind => [1, 1234], -}; - -#4 -$where = { - -nest => \["MATCH (col1, col2) AGAINST (?)" => "apples"], - }; -push @tests, { - where => $where, - stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )", - bind => ["apples"], -}; - - -#5 -($sub_stmt, @sub_bind) - = $sql->where({age => [{"<" => 10}, {">" => 20}]}); -$sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause -$where = { - lname => {-like => '%son%'}, - -nest => \["NOT ( $sub_stmt )" => @sub_bind], - }; -push @tests, { - where => $where, - stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )", - bind => [10, 20, '%son%'], -}; - -#6 -($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?", - 100, "foo%"); -$where = { - foo => 1234, - bar => { -in => \[$sub_stmt => @sub_bind] }, - }; -push @tests, { - where => $where, - stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )", - bind => [100, "foo%", 1234], -}; - - -plan tests => scalar(@tests); - -for (@tests) { - - my($stmt, @bind) = $sql->where($_->{where}, $_->{order}); - is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); -} - - - - - +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +use SQL::Abstract::Test import => ['is_same_sql_bind']; + +use SQL::Abstract; + +my $sql = SQL::Abstract->new; + +my (@tests, $sub_stmt, @sub_bind, $where); + +#1 +($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?", + 100, "foo%"); +$where = { + foo => 1234, + bar => \["IN ($sub_stmt)" => @sub_bind], + }; +push @tests, { + where => $where, + stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )", + bind => [100, "foo%", 1234], +}; + +#2 +($sub_stmt, @sub_bind) + = $sql->select("t1", "c1", {c2 => {"<" => 100}, + c3 => {-like => "foo%"}}); +$where = { + foo => 1234, + bar => \["> ALL ($sub_stmt)" => @sub_bind], + }; +push @tests, { + where => $where, + stmt => " WHERE ( bar > ALL (SELECT c1 FROM t1 WHERE ( c2 < ? AND c3 LIKE ? )) AND foo = ? )", + bind => [100, "foo%", 1234], +}; + +#3 +($sub_stmt, @sub_bind) + = $sql->select("t1", "*", {c1 => 1, c2 => \"> t0.c0"}); +$where = { + foo => 1234, + -nest => \["EXISTS ($sub_stmt)" => @sub_bind], + }; +push @tests, { + where => $where, + stmt => " WHERE ( EXISTS (SELECT * FROM t1 WHERE ( c1 = ? AND c2 > t0.c0 )) AND foo = ? )", + bind => [1, 1234], +}; + +#4 +$where = { + -nest => \["MATCH (col1, col2) AGAINST (?)" => "apples"], + }; +push @tests, { + where => $where, + stmt => " WHERE ( MATCH (col1, col2) AGAINST (?) )", + bind => ["apples"], +}; + + +#5 +($sub_stmt, @sub_bind) + = $sql->where({age => [{"<" => 10}, {">" => 20}]}); +$sub_stmt =~ s/^ where //i; # don't want "WHERE" in the subclause +$where = { + lname => {-like => '%son%'}, + -nest => \["NOT ( $sub_stmt )" => @sub_bind], + }; +push @tests, { + where => $where, + stmt => " WHERE ( NOT ( ( ( ( age < ? ) OR ( age > ? ) ) ) ) AND lname LIKE ? )", + bind => [10, 20, '%son%'], +}; + +#6 +($sub_stmt, @sub_bind) = ("SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?", + 100, "foo%"); +$where = { + foo => 1234, + bar => { -in => \[$sub_stmt => @sub_bind] }, + }; +push @tests, { + where => $where, + stmt => " WHERE ( bar IN (SELECT c1 FROM t1 WHERE c2 < ? AND c3 LIKE ?) AND foo = ? )", + bind => [100, "foo%", 1234], +}; + + +plan tests => scalar(@tests); + +for (@tests) { + + my($stmt, @bind) = $sql->where($_->{where}, $_->{order}); + is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); +} + + + + + diff --git a/t/08special_ops.t b/t/08special_ops.t index 8739ad7..5348e0e 100644 --- a/t/08special_ops.t +++ b/t/08special_ops.t @@ -1,69 +1,69 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use Test::More; - -use SQL::Abstract::Test import => ['is_same_sql_bind']; - -use SQL::Abstract; - -my $sqlmaker = SQL::Abstract->new(special_ops => [ - - # special op for MySql MATCH (field) AGAINST(word1, word2, ...) - {regex => qr/^match$/i, - handler => sub { - my ($self, $field, $op, $arg) = @_; - $arg = [$arg] if not ref $arg; - my $label = $self->_quote($field); - my ($placeholder) = $self->_convert('?'); - my $placeholders = join ", ", (($placeholder) x @$arg); - my $sql = $self->_sqlcase('match') . " ($label) " - . $self->_sqlcase('against') . " ($placeholders) "; - my @bind = $self->_bindtype($field, @$arg); - return ($sql, @bind); - } - }, - - # special op for Basis+ NATIVE - {regex => qr/^native$/i, - handler => sub { - my ($self, $field, $op, $arg) = @_; - $arg =~ s/'/''/g; - my $sql = "NATIVE (' $field $arg ')"; - return ($sql); - } - }, - -]); - -my @tests = ( - - #1 - { where => {foo => {-match => 'foo'}, - bar => {-match => [qw/foo bar/]}}, - stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )", - bind => [qw/foo bar foo/], - }, - - #2 - { where => {foo => {-native => "PH IS 'bar'"}}, - stmt => " WHERE ( NATIVE (' foo PH IS ''bar'' ') )", - bind => [], - }, - -); - - -plan tests => scalar(@tests); - -for (@tests) { - - my($stmt, @bind) = $sqlmaker->where($_->{where}, $_->{order}); - is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); -} - - - - - +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; + +use SQL::Abstract::Test import => ['is_same_sql_bind']; + +use SQL::Abstract; + +my $sqlmaker = SQL::Abstract->new(special_ops => [ + + # special op for MySql MATCH (field) AGAINST(word1, word2, ...) + {regex => qr/^match$/i, + handler => sub { + my ($self, $field, $op, $arg) = @_; + $arg = [$arg] if not ref $arg; + my $label = $self->_quote($field); + my ($placeholder) = $self->_convert('?'); + my $placeholders = join ", ", (($placeholder) x @$arg); + my $sql = $self->_sqlcase('match') . " ($label) " + . $self->_sqlcase('against') . " ($placeholders) "; + my @bind = $self->_bindtype($field, @$arg); + return ($sql, @bind); + } + }, + + # special op for Basis+ NATIVE + {regex => qr/^native$/i, + handler => sub { + my ($self, $field, $op, $arg) = @_; + $arg =~ s/'/''/g; + my $sql = "NATIVE (' $field $arg ')"; + return ($sql); + } + }, + +]); + +my @tests = ( + + #1 + { where => {foo => {-match => 'foo'}, + bar => {-match => [qw/foo bar/]}}, + stmt => " WHERE ( MATCH (bar) AGAINST (?, ?) AND MATCH (foo) AGAINST (?) )", + bind => [qw/foo bar foo/], + }, + + #2 + { where => {foo => {-native => "PH IS 'bar'"}}, + stmt => " WHERE ( NATIVE (' foo PH IS ''bar'' ') )", + bind => [], + }, + +); + + +plan tests => scalar(@tests); + +for (@tests) { + + my($stmt, @bind) = $sqlmaker->where($_->{where}, $_->{order}); + is_same_sql_bind($stmt, \@bind, $_->{stmt}, $_->{bind}); +} + + + + + diff --git a/t/09refkind.t b/t/09refkind.t index e51fcf0..1044231 100644 --- a/t/09refkind.t +++ b/t/09refkind.t @@ -1,31 +1,31 @@ -#!/usr/bin/perl - -use strict; -use warnings; -use Test::More; -use SQL::Abstract; - -plan tests => 13; - -my $obj = bless {}, "Foo::Bar"; - -is(SQL::Abstract->_refkind(undef), 'UNDEF', 'UNDEF'); - -is(SQL::Abstract->_refkind({}), 'HASHREF', 'HASHREF'); -is(SQL::Abstract->_refkind([]), 'ARRAYREF', 'ARRAYREF'); - -is(SQL::Abstract->_refkind(\{}), 'HASHREFREF', 'HASHREFREF'); -is(SQL::Abstract->_refkind(\[]), 'ARRAYREFREF', 'ARRAYREFREF'); - -is(SQL::Abstract->_refkind(\\{}), 'HASHREFREFREF', 'HASHREFREFREF'); -is(SQL::Abstract->_refkind(\\[]), 'ARRAYREFREFREF', 'ARRAYREFREFREF'); - -is(SQL::Abstract->_refkind("foo"), 'SCALAR', 'SCALAR'); -is(SQL::Abstract->_refkind(\"foo"), 'SCALARREF', 'SCALARREF'); -is(SQL::Abstract->_refkind(\\"foo"), 'SCALARREFREF', 'SCALARREFREF'); - -# objects are treated like scalars -is(SQL::Abstract->_refkind($obj), 'SCALAR', 'SCALAR'); -is(SQL::Abstract->_refkind(\$obj), 'SCALARREF', 'SCALARREF'); -is(SQL::Abstract->_refkind(\\$obj), 'SCALARREFREF', 'SCALARREFREF'); - +#!/usr/bin/perl + +use strict; +use warnings; +use Test::More; +use SQL::Abstract; + +plan tests => 13; + +my $obj = bless {}, "Foo::Bar"; + +is(SQL::Abstract->_refkind(undef), 'UNDEF', 'UNDEF'); + +is(SQL::Abstract->_refkind({}), 'HASHREF', 'HASHREF'); +is(SQL::Abstract->_refkind([]), 'ARRAYREF', 'ARRAYREF'); + +is(SQL::Abstract->_refkind(\{}), 'HASHREFREF', 'HASHREFREF'); +is(SQL::Abstract->_refkind(\[]), 'ARRAYREFREF', 'ARRAYREFREF'); + +is(SQL::Abstract->_refkind(\\{}), 'HASHREFREFREF', 'HASHREFREFREF'); +is(SQL::Abstract->_refkind(\\[]), 'ARRAYREFREFREF', 'ARRAYREFREFREF'); + +is(SQL::Abstract->_refkind("foo"), 'SCALAR', 'SCALAR'); +is(SQL::Abstract->_refkind(\"foo"), 'SCALARREF', 'SCALARREF'); +is(SQL::Abstract->_refkind(\\"foo"), 'SCALARREFREF', 'SCALARREFREF'); + +# objects are treated like scalars +is(SQL::Abstract->_refkind($obj), 'SCALAR', 'SCALAR'); +is(SQL::Abstract->_refkind(\$obj), 'SCALARREF', 'SCALARREF'); +is(SQL::Abstract->_refkind(\\$obj), 'SCALARREFREF', 'SCALARREFREF'); +