Newer Older
61 lines | 1.611kb
packing
yuki-kimoto authored on 2009-11-12
1
use Test::More 'no_plan';
2
use strict;
3
use warnings;
4
use utf8;
5

            
6
use DBIx::Custom::SQLite;
7

            
8
# Function for test name
9
my $test;
10
sub test {
11
    $test = shift;
12
}
13

            
14
# Constant varialbes for test
15
my $CREATE_TABLE = {
16
    0 => 'create table table1 (key1 char(255), key2 char(255));',
17
    1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));',
18
    2 => 'create table table2 (key1 char(255), key3 char(255));'
19
};
20

            
21

            
22
# Variables for tests
23
my $dbi;
24
my $ret_val;
25
my $rows;
26
my $db_file;
27

            
28
test 'connect_memory';
29
$dbi = DBIx::Custom::SQLite->new;
30
$dbi->connect_memory;
31
$ret_val = $dbi->do($CREATE_TABLE->{0});
32
ok(defined $ret_val, $test);
Various change
yuki-kimoto authored on 2009-11-12
33
$dbi->utf8_filter_on;
packing
yuki-kimoto authored on 2009-11-12
34
$dbi->insert('table1', {key1 => 'あ', key2 => 2});
rename fetch_all_hash to fet...
yuki-kimoto authored on 2009-11-15
35
$rows = $dbi->select('table1', {key1 => 'あ'})->fetch_hash_all;
packing
yuki-kimoto authored on 2009-11-12
36
is_deeply($rows, [{key1 => 'あ', key2 => 2}], "$test : select rows");
37

            
38
test 'connect_memory error';
39
eval{$dbi->connect_memory};
40
like($@, qr/Already connected/, "$test : already connected");
41

            
42
test 'reconnect_memory';
43
$dbi = DBIx::Custom::SQLite->new;
44
$dbi->reconnect_memory;
45
$ret_val = $dbi->do($CREATE_TABLE->{0});
46
ok(defined $ret_val, "$test : connect first");
47
$dbi->reconnect_memory;
48
$ret_val = $dbi->do($CREATE_TABLE->{2});
49
ok(defined $ret_val, "$test : connect first");
50

            
51
test 'connect';
52
$db_file  = 't/test.db';
53
unlink $db_file if -f $db_file;
54
$dbi = DBIx::Custom::SQLite->new(database => $db_file);
55
$dbi->connect;
56
ok(-f $db_file, "$test : database file");
57
$ret_val = $dbi->do($CREATE_TABLE->{0});
58
ok(defined $ret_val, "$test : database");
59
$dbi->disconnect;
60
unlink $db_file if -f $db_file;
61