/[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 162 - (show annotations)
Sun Jun 15 17:47:39 2008 UTC (15 years, 9 months 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 #!/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 => 24;
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 $row = $sql->next, 'next' );
28
29 isa_ok( $row, 'A3C::SQL::row' );
30
31 ok( $row->nr, 'row has accessor' );
32
33 is( $row->nr, 42, 'nr' );
34
35 ok( ! $sql->next, 'last row' );
36
37 ok( my $dbh = DBI->connect( 'DBI:Pg:dbname=template1' ), 'dbh' );
38 ok( $sql = A3C::SQL->new({ query => "select 5 as nr", dbh => $dbh }), 'new' );
39 cmp_ok( $sql->count, '==', 1, 'count' );
40 is_deeply( [ $sql->_column_names ], [ 'nr' ], '_column_names' );
41 is_deeply( scalar $sql->_column_names, 1, 'scalar _column_names' );
42 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
47 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