Showing 2 changed files with 22 additions and 24 deletions
+1
lib/DBI/Custom.pm
... ...
@@ -170,6 +170,7 @@ sub create_query {
170 170
 
171 171
 sub execute {
172 172
     my ($self, $query, $params)  = @_;
173
+    $params ||= {};
173 174
     
174 175
     # Create query if First argument is template
175 176
     if (!ref $query) {
+21 -24
t/02-sqlite.t
... ...
@@ -28,6 +28,7 @@ my $sql;
28 28
 my $result;
29 29
 my @rows;
30 30
 my $rows;
31
+my $query;
31 32
 
32 33
 
33 34
 # Prepare table
... ...
@@ -39,66 +40,62 @@ $sth->execute(1, 2);
39 40
 $sth->execute(3, 4);
40 41
 
41 42
 
42
-__END__
43
-$result = $dbi->execute("select key1, key2 from table1");
43
+test 'DBI::Custom::Result test';
44
+$tmpl = "select key1, key2 from table1";
45
+$query = $dbi->create_query($tmpl);
46
+$result = $dbi->execute($query);
44 47
 
45 48
 @rows = ();
46 49
 while (my $row = $result->fetch) {
47 50
     push @rows, [@$row];
48 51
 }
49
-is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch');
52
+is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch scalar context");
50 53
 
51 54
 
52
-$result = $dbi->execute("select key1, key2 from table1");
53
-
55
+$result = $dbi->execute($query);
54 56
 @rows = ();
55 57
 while (my @row = $result->fetch) {
56 58
     push @rows, [@row];
57 59
 }
58
-is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch list context');
60
+is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch list context");
59 61
 
60 62
 
61
-$result = $dbi->execute("select key1, key2 from table1;");
62
-
63
+$result = $dbi->execute($query);
63 64
 @rows = ();
64 65
 while (my $row = $result->fetch_hash) {
65 66
     push @rows, {%$row};
66 67
 }
67
-is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'fetch_hash');
68
-
68
+is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch_hash scalar context");
69 69
 
70
-$result = $dbi->execute("select key1, key2 from table1;");
71 70
 
71
+$result = $dbi->execute($query);
72 72
 @rows = ();
73 73
 while (my %row = $result->fetch_hash) {
74 74
     push @rows, {%row};
75 75
 }
76
-is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], 'fetch hash list context');
76
+is_deeply(\@rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : fetch hash list context");
77 77
 
78 78
 
79
-$result = $dbi->execute("select key1, key2 from table1");
80
-
79
+$result = $dbi->execute($query);
81 80
 $rows = $result->fetch_all;
82
-is_deeply($rows, [[1, 2], [3, 4]], 'fetch_all');
81
+is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all scalar context");
83 82
 
84 83
 
85
-$result = $dbi->execute("select key1, key2 from table1");
86
-
84
+$result = $dbi->execute($query);
87 85
 @rows = $result->fetch_all;
88
-is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch_all list context');
86
+is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all list context");
89 87
 
90 88
 
91
-$result = $dbi->execute("select key1, key2 from table1");
92
-
89
+$result = $dbi->execute($query);
93 90
 @rows = $result->fetch_all_hash;
94
-is_deeply($rows, [[1, 2], [3, 4]], 'fetch_all_hash');
91
+is_deeply($rows, [[1, 2], [3, 4]], "$test : fetch_all_hash scalar context");
95 92
 
96 93
 
97
-$result = $dbi->execute("select key1, key2 from table1");
98
-
94
+$result = $dbi->execute($query);
99 95
 @rows = $result->fetch_all;
100
-is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch_all_hash list context');
96
+is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_all_hash list context");
101 97
 
98
+__END__
102 99
 
103 100
 $dbi->fetch_filter(sub {
104 101
     my ($key, $value, $type, $sth, $i) = @_;