/[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

Annotation of /t/20-sql.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 162 - (hide annotations)
Sun Jun 15 17:47:39 2008 UTC (14 years ago) by dpavlin
File MIME type: application/x-troff
File size: 1283 byte(s)
added encoding to A3C::SQL so we can connect to databases which doesn't
have default UTF-8 encoding (like strix doesn't)
1 dpavlin 78 #!/usr/bin/env perl
2     use warnings;
3     use strict;
4    
5     =head1 DESCRIPTION
6    
7     test SQL module
8    
9     =cut
10    
11 dpavlin 162 use Jifty::Test tests => 24;
12 dpavlin 78
13 dpavlin 159 use Data::Dump qw/dump/;
14    
15 dpavlin 78 use_ok('A3C::SQL');
16 dpavlin 145 use_ok('DBI');
17 dpavlin 78
18 dpavlin 145 my $query = 'select 42 as nr';
19 dpavlin 78
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 $row = $sql->next, 'next' );
28    
29     isa_ok( $row, 'A3C::SQL::row' );
30    
31 dpavlin 145 ok( $row->nr, 'row has accessor' );
32 dpavlin 78
33 dpavlin 145 is( $row->nr, 42, 'nr' );
34    
35 dpavlin 78 ok( ! $sql->next, 'last row' );
36 dpavlin 145
37     ok( my $dbh = DBI->connect( 'DBI:Pg:dbname=template1' ), 'dbh' );
38 dpavlin 162 ok( $sql = A3C::SQL->new({ query => "select 5 as nr", dbh => $dbh }), 'new' );
39 dpavlin 145 cmp_ok( $sql->count, '==', 1, 'count' );
40 dpavlin 159 is_deeply( [ $sql->_column_names ], [ 'nr' ], '_column_names' );
41     is_deeply( scalar $sql->_column_names, 1, 'scalar _column_names' );
42 dpavlin 145 ok( my $row2 = $sql->next, 'next' );
43     isa_ok( $row2, 'A3C::SQL::row' );
44     ok( $row2->nr, 'row has accessor' );
45     is( $row2->nr, 5, 'nr' );
46 dpavlin 159
47 dpavlin 162 ok( $sql = A3C::SQL->new({ query => "select 'èevapæiæ' as test", dbh => $dbh, encoding => 'iso-8859-2' }), 'new + encoding' );
48     cmp_ok( $sql->count, '==', 1, 'count' );
49     ok( my $row3 = $sql->next, 'next' );
50     is_deeply( $row3->test, "\x{10D}evap\x{107}i\x{107}", 'correct encoding' );
51    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26