/[A3C]/t/20-sql.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /t/20-sql.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 220 - (show annotations)
Sun Jun 22 14:55:55 2008 UTC (14 years ago) by dpavlin
File MIME type: application/x-troff
File size: 1361 byte(s)
display duration of SQL query
1 #!/usr/bin/env perl
2 use warnings;
3 use strict;
4
5 =head1 DESCRIPTION
6
7 test SQL module
8
9 =cut
10
11 use Jifty::Test tests => 25;
12
13 use Data::Dump qw/dump/;
14
15 use_ok('A3C::SQL');
16 use_ok('DBI');
17
18 my $query = 'select 42 as nr';
19
20 ok( my $sql = A3C::SQL->new({ query => $query }), 'new' );
21
22 isa_ok( $sql, 'A3C::SQL' );
23 is( $sql->query, $query, 'sql' );
24
25 cmp_ok( $sql->count, '==', 1, 'count' );
26
27 ok( my $duration = $sql->duration, 'duration' );
28 diag "duration: $duration";
29
30 ok( my $row = $sql->next, 'next' );
31
32 isa_ok( $row, 'A3C::SQL::row' );
33
34 ok( $row->nr, 'row has accessor' );
35
36 is( $row->nr, 42, 'nr' );
37
38 ok( ! $sql->next, 'last row' );
39
40 ok( my $dbh = DBI->connect( 'DBI:Pg:dbname=template1' ), 'dbh' );
41 ok( $sql = A3C::SQL->new({ query => "select 5 as nr", dbh => $dbh }), 'new' );
42 cmp_ok( $sql->count, '==', 1, 'count' );
43 is_deeply( [ $sql->_column_names ], [ 'nr' ], '_column_names' );
44 is_deeply( scalar $sql->_column_names, 1, 'scalar _column_names' );
45 ok( my $row2 = $sql->next, 'next' );
46 isa_ok( $row2, 'A3C::SQL::row' );
47 ok( $row2->nr, 'row has accessor' );
48 is( $row2->nr, 5, 'nr' );
49
50 ok( $sql = A3C::SQL->new({ query => "select 'èevapæiæ' as test", dbh => $dbh, encoding => 'iso-8859-2' }), 'new + encoding' );
51 cmp_ok( $sql->count, '==', 1, 'count' );
52 ok( my $row3 = $sql->next, 'next' );
53 is_deeply( $row3->test, "\x{10D}evap\x{107}i\x{107}", 'correct encoding' );
54

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26