Showing 2 changed files with 47 additions and 19 deletions
+2 -2
lib/DBI/Custom.pm
... ...
@@ -283,8 +283,8 @@ sub fetch_all {
283 283
     my $self = shift;
284 284
     
285 285
     my $rows = [];
286
-    while(my %row = $self->fetch) {
287
-        push @$rows, {%row};
286
+    while(my @row = $self->fetch) {
287
+        push @$rows, [@row];
288 288
     }
289 289
     return wantarray ? @$rows : $rows;
290 290
 }
+45 -17
t/02-sqlite.t
... ...
@@ -69,55 +69,75 @@ $t->new->create_table1->insert({k1 => 1, k2 => 2}, {k1 => 3, k2 => 4})->test(sub
69 69
     my @rows;
70 70
     my $rows;
71 71
     
72
-    # Simple query array ref
72
+    #----------
73 73
     $r = $dbi->query("select k1, k2 from t1");
74 74
     
75 75
     @rows = ();
76 76
     while (my $row = $r->fetch) {
77 77
         push @rows, [@$row];
78 78
     }
79
-    is_deeply(\@rows, [[1, 2], [3, 4]], 'Simple query array ref');
80
-
81
-
82
-    # Simple query array
79
+    is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch');
80
+    
81
+    
82
+    #----------
83 83
     $r = $dbi->query("select k1, k2 from t1");
84 84
     
85 85
     @rows = ();
86 86
     while (my @row = $r->fetch) {
87 87
         push @rows, [@row];
88 88
     }
89
-    is_deeply(\@rows, [[1, 2], [3, 4]], 'Simple query array');
89
+    is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch list context');
90 90
     
91 91
     
92
-    # Simple query hash ref
92
+    #-----------
93 93
     $r = $dbi->query("select k1, k2 from t1;");
94 94
     
95 95
     @rows = ();
96 96
     while (my $row = $r->fetch_hash) {
97 97
         push @rows, {%$row};
98 98
     }
99
-    is_deeply(\@rows, [{k1 => 1, k2 => 2}, {k1 => 3, k2 => 4}], 'Simple query hash ref');
99
+    is_deeply(\@rows, [{k1 => 1, k2 => 2}, {k1 => 3, k2 => 4}], 'fetch_hash');
100 100
     
101
-
102
-    # Simple query hash
101
+    
102
+    #-----------
103 103
     $r = $dbi->query("select k1, k2 from t1;");
104 104
     
105 105
     @rows = ();
106 106
     while (my %row = $r->fetch_hash) {
107 107
         push @rows, {%row};
108 108
     }
109
-    is_deeply(\@rows, [{k1 => 1, k2 => 2}, {k1 => 3, k2 => 4}], 'Simple query hash ref');
109
+    is_deeply(\@rows, [{k1 => 1, k2 => 2}, {k1 => 3, k2 => 4}], 'fetch hash list context');
110 110
     
111 111
     
112
-    # Simple query array ref all
112
+    #-----------
113 113
     $r = $dbi->query("select k1, k2 from t1");
114 114
     
115 115
     $rows = $r->fetch_all;
116
-    is_deeply($rows, [[1, 2], [3, 4]], 'Simple query array');
116
+    is_deeply($rows, [[1, 2], [3, 4]], 'fetch_all');
117 117
     
118 118
     
119
+    #------------
120
+    $r = $dbi->query("select k1, k2 from t1");
121
+    
122
+    @rows = $r->fetch_all;
123
+    is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch_all list context');
124
+    
125
+    
126
+    #------------
127
+    $r = $dbi->query("select k1, k2 from t1");
128
+    
129
+    @rows = $r->fetch_all_hash;
130
+    is_deeply($rows, [[1, 2], [3, 4]], 'fetch_all_hash');
119 131
     
120 132
     
133
+    #-------------
134
+    $r = $dbi->query("select k1, k2 from t1");
135
+    
136
+    @rows = $r->fetch_all;
137
+    is_deeply(\@rows, [[1, 2], [3, 4]], 'fetch_all_hash list context');
138
+    
139
+    
140
+    #---------------------------------------------------------------------
121 141
     $dbi->fetch_filter(sub {
122 142
         my ($key, $value) = @_;
123 143
         if ($key eq 'k1' && $value == 1 ) {
... ...
@@ -126,12 +146,20 @@ $t->new->create_table1->insert({k1 => 1, k2 => 2}, {k1 => 3, k2 => 4})->test(sub
126 146
         return $value;
127 147
     });
128 148
     
149
+    #-----------------------------------
129 150
     $r = $dbi->query("select k1, k2 from t1");
130 151
     
131
-    my $row = $r->fetch;
132
-    my @values = @$row;
133
-    $r->finish;
152
+    $rows = $r->fetch_all;
153
+    
154
+    is_deeply($rows, [[3, 2], [3, 4]], 'fetch_filter array');
134 155
     
135
-    is_deeply(\@values, [3, 2]);
156
+    
157
+    #----------------------------------
158
+    $r = $dbi->query("select k1, k2 from t1");
159
+    
160
+    $rows = $r->fetch_all_hash;
161
+    
162
+    is_deeply($rows, [{k1 => 3, k2 => 2}, {k1 => 3, k2 => 4}], 'fetch_filter hash');
163
+
136 164
 });
137 165