DBIx-Custom / t / dbi-custom-sqlite.t /
Newer Older
69 lines | 1.832kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
use Test::More;
2
use strict;
3
use warnings;
4
use utf8;
5

            
6
BEGIN {
7
    eval { require DBD::SQLite; 1 }
8
        or plan skip_all => 'DBD::SQLite required';
9
    eval { DBD::SQLite->VERSION >= 1.25 }
10
        or plan skip_all => 'DBD::SQLite >= 1.25 required';
11

            
12
    plan 'no_plan';
13
    use_ok('DBIx::Custom::SQLite');
14
}
15

            
16
# Function for test name
17
my $test;
18
sub test {
19
    $test = shift;
20
}
21

            
22
# Constant varialbes for test
23
my $CREATE_TABLE = {
24
    0 => 'create table table1 (key1 char(255), key2 char(255));',
25
    1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));',
26
    2 => 'create table table2 (key1 char(255), key3 char(255));'
27
};
28

            
29

            
30
# Variables for tests
31
my $dbi;
32
my $ret_val;
33
my $rows;
34
my $db_file;
35

            
36
test 'connect_memory';
37
$dbi = DBIx::Custom::SQLite->new;
38
$dbi->connect_memory;
39
$ret_val = $dbi->do($CREATE_TABLE->{0});
40
ok(defined $ret_val, $test);
41
$dbi->utf8_filter_on;
42
$dbi->insert('table1', {key1 => 'あ', key2 => 2});
43
$rows = $dbi->select('table1', {key1 => 'あ'})->fetch_hash_all;
44
is_deeply($rows, [{key1 => 'あ', key2 => 2}], "$test : select rows");
45

            
46
test 'connect_memory error';
47
eval{$dbi->connect_memory};
48
like($@, qr/Already connected/, "$test : already connected");
49

            
50
test 'reconnect_memory';
51
$dbi = DBIx::Custom::SQLite->new;
52
$dbi->reconnect_memory;
53
$ret_val = $dbi->do($CREATE_TABLE->{0});
54
ok(defined $ret_val, "$test : connect first");
55
$dbi->reconnect_memory;
56
$ret_val = $dbi->do($CREATE_TABLE->{2});
57
ok(defined $ret_val, "$test : connect first");
58

            
59
test 'connect';
60
$db_file  = 't/test.db';
61
unlink $db_file if -f $db_file;
62
$dbi = DBIx::Custom::SQLite->new(database => $db_file);
63
$dbi->connect;
64
ok(-f $db_file, "$test : database file");
65
$ret_val = $dbi->do($CREATE_TABLE->{0});
66
ok(defined $ret_val, "$test : database");
67
$dbi->disconnect;
68
unlink $db_file if -f $db_file;
69