root/lang/perl/Filter-SQL/trunk/t/01-simple.t @ 22663

Revision 22663, 2.0 kB (checked in by kazuho, 5 years ago)

0.10 release (SELECT AS HASH)

  • Property svn:executable set to *
Line 
1#! /usr/bin/perl
2
3use strict;
4use warnings;
5use Filter::SQL;
6use Test::More;
7
8BEGIN {
9    if (! $ENV{FILTER_SQL_DBI}) {
10        plan skip_all => 'Set FILTER_SQL_DBI to run these tests';
11    } else {
12        plan tests => 35;
13    }
14};
15
16ok(ref Filter::SQL->dbh);
17
18is(SELECT ROW 1;, 1);
19is(SELECT ROW "test";, 'test');
20is(SELECT ROW 'test';, 'test');
21is(SELECT ROW "foo'a";, "foo'a");
22my $a = 'foo';
23is(SELECT ROW $a;, 'foo');
24$a = "foo'a";
25is(SELECT ROW $a;, $a);
26is(SELECT ROW ${a};, $a);
27is(SELECT ROW "hoge$a";, "hoge$a");
28is(SELECT ROW 'hoge$a';, 'hoge$a');
29$a = [ 5 ];
30is(SELECT ROW $a->[0+0]+1;, 6);
31$a = { foo => 3 };
32is(SELECT ROW $a->{foo}-1;, 2);
33
34is(SELECT ROW {1 + 2};, 3);
35
36ok(EXEC CREATE TEMPORARY TABLE filter_sql_t (v INT NOT NULL););
37
38is_deeply(
39    [ SELECT ROW * FROM filter_sql_t; ],
40    [],
41);
42is_deeply(
43    { SELECT ROW AS HASH * FROM filter_sql_t; },
44    {},
45);
46
47is_deeply(
48    scalar(SELECT ROW * FROM filter_sql_t;),
49    undef,
50);
51
52for (my $n = 0; $n < 3; $n++) {
53    ok(INSERT INTO filter_sql_t (v) VALUES ($n););
54}
55
56is_deeply(
57    scalar(SELECT ROW * FROM filter_sql_t;),
58    0,
59);
60
61is_deeply(
62    [ SELECT ROW * FROM filter_sql_t; ],
63    [ 0 ],
64);
65
66is_deeply(
67    { SELECT ROW AS HASH * FROM filter_sql_t; },
68    { v => 0 },
69);
70
71my $sth = EXEC SELECT v FROM filter_sql_t;;
72ok($sth);
73is_deeply(
74    $sth->fetchall_arrayref,
75    [ [ 0 ], [ 1 ], [ 2 ], ],
76);
77
78is_deeply(
79    [ SELECT * FROM filter_sql_t; ],
80    [ [ 0 ], [ 1 ], [ 2 ], ],
81);
82is_deeply(
83    [ SELECT AS HASH * FROM filter_sql_t; ],
84    [ { v => 0 }, { v => 1 }, { v => 2 }, ],
85);
86is(SELECT ROW COUNT(*) FROM filter_sql_t;, 3);
87
88ok(EXEC DROP TEMPORARY TABLE filter_sql_t;);
89
90ok(EXEC CREATE TEMPORARY TABLE filter_sql_t (
91    S INT NOT NULL,
92    Q INT NOT NULL,
93    G INT NOT NULL
94););
95ok(INSERT INTO filter_sql_t (`s`,`q`,`g`) VALUES (11,21,31););
96ok(DELETE FROM filter_sql_t;);
97ok(INSERT INTO filter_sql_t (s,q,g) VALUES (11,21,31););
98is_deeply(
99    [ SELECT ROW s,1,2,g FROM filter_sql_t; ],
100    [ 11,1,2,31 ],
101);
102is_deeply(
103    [ SELECT ROW q,1,g FROM filter_sql_t; ],
104    [ 21,1,31 ],
105);
Note: See TracBrowser for help on using the browser.