added insert, update, update...
|
1 |
use Test::More; |
2 | ||
3 |
eval {require DBIx::TransactionManager; 1} |
|
4 |
or plan skip_all => 'required DBIx::TransactionManager'; |
|
5 | ||
6 |
plan 'no_plan'; |
|
7 | ||
8 |
use DBIx::Custom; |
|
9 | ||
10 |
# Function for test name |
|
cleanup
|
11 |
sub test { "# $_[0]\n" } |
added insert, update, update...
|
12 | |
13 |
# Constant varialbes for test |
|
14 |
my $CREATE_TABLE = { |
|
15 |
0 => 'create table table1 (key1 char(255), key2 char(255));', |
|
16 |
}; |
|
17 | ||
18 |
my $NEW_ARGS = { |
|
19 |
0 => {data_source => 'dbi:SQLite:dbname=:memory:'} |
|
20 |
}; |
|
21 | ||
22 |
# Variables |
|
23 |
my $dbi; |
|
24 |
my $result; |
|
25 |
my $txn; |
|
26 | ||
27 |
test 'transaction'; |
|
28 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
29 |
$dbi->execute($CREATE_TABLE->{0}); |
|
30 |
{ |
|
31 |
my $txn = $dbi->txn_scope; |
|
32 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
33 |
$dbi->insert(table => 'table1', param => {key1 => 2, key2 => 3}); |
|
34 |
$txn->commit; |
|
35 |
} |
|
36 |
$result = $dbi->select(table => 'table1'); |
|
37 |
is_deeply(scalar $result->fetch_hash_all, [{key1 => 1, key2 => 2}, {key1 => 2, key2 => 3}], |
|
cleanup
|
38 |
"commit"); |
added insert, update, update...
|
39 | |
40 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0}); |
|
41 |
$dbi->execute($CREATE_TABLE->{0}); |
|
42 | ||
43 |
{ |
|
44 |
local $SIG{__WARN__} = sub {}; |
|
45 |
{ |
|
46 |
my $txn = $dbi->txn_scope; |
|
47 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2}); |
|
48 |
} |
|
49 |
} |
|
50 |
$result = $dbi->select(table => 'table1'); |
|
cleanup
|
51 |
ok(! $result->fetch_first, "rollback"); |
added insert, update, update...
|
52 |