DBIx-Custom / t / dbix-custom-sqlite.t /
Newer Older
77 lines | 2.251kb
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;
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
35
my $id;
packaging one directory
yuki-kimoto authored on 2009-11-16
36

            
37
test 'connect_memory';
update document
yuki-kimoto authored on 2010-05-27
38
$dbi = DBIx::Custom::SQLite->connect(database => ':memory:');
rename query() to execute()
yuki-kimoto authored on 2010-05-01
39
$ret_val = $dbi->execute($CREATE_TABLE->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
40
ok(defined $ret_val, $test);
removed register_format()
yuki-kimoto authored on 2010-05-26
41
$dbi->insert(table => 'table1', param => {key1 => 'a', key2 => 2});
42
$rows = $dbi->select(table => 'table1', where => {key1 => 'a'})->fetch_hash_all;
fix tests
yuki-kimoto authored on 2010-02-11
43
is_deeply($rows, [{key1 => 'a', key2 => 2}], "$test : select rows");
packaging one directory
yuki-kimoto authored on 2009-11-16
44

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

            
49
test 'reconnect_memory';
50
$dbi = DBIx::Custom::SQLite->new;
51
$dbi->reconnect_memory;
rename query() to execute()
yuki-kimoto authored on 2010-05-01
52
$ret_val = $dbi->execute($CREATE_TABLE->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
53
ok(defined $ret_val, "$test : connect first");
54
$dbi->reconnect_memory;
rename query() to execute()
yuki-kimoto authored on 2010-05-01
55
$ret_val = $dbi->execute($CREATE_TABLE->{2});
packaging one directory
yuki-kimoto authored on 2009-11-16
56
ok(defined $ret_val, "$test : connect first");
57

            
58
test 'connect';
59
$db_file  = 't/test.db';
60
unlink $db_file if -f $db_file;
61
$dbi = DBIx::Custom::SQLite->new(database => $db_file);
62
$dbi->connect;
63
ok(-f $db_file, "$test : database file");
rename query() to execute()
yuki-kimoto authored on 2010-05-01
64
$ret_val = $dbi->execute($CREATE_TABLE->{0});
packaging one directory
yuki-kimoto authored on 2009-11-16
65
ok(defined $ret_val, "$test : database");
66
$dbi->disconnect;
67
unlink $db_file if -f $db_file;
68

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
69
test 'last_insert_rowid';
70
$dbi = DBIx::Custom::SQLite->new;
71
$dbi->connect_memory;
rename query() to execute()
yuki-kimoto authored on 2010-05-01
72
$ret_val = $dbi->execute($CREATE_TABLE->{0});
removed register_format()
yuki-kimoto authored on 2010-05-26
73
$dbi->insert({table => 'table1', param => {key1 => 1, key2 => 2}});
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
74
is($dbi->last_insert_rowid, 1, "$test: first");
removed register_format()
yuki-kimoto authored on 2010-05-26
75
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
76
is($dbi->last_insert_rowid, 2, "$test: second");
77
$dbi->disconnect;