Showing 2 changed files with 71 additions and 4 deletions
+8 -1
lib/DBI/Custom.pm
... ...
@@ -225,7 +225,14 @@ sub execute {
225 225
     # Execute
226 226
     my $sth = $query->sth;
227 227
     my $ret_val = eval{$sth->execute(@$bind_values)};
228
-    croak($@) if $@;
228
+    if ($@) {
229
+        require Data::Dumper;
230
+        my $sql         = $query->{sql} || '';
231
+        my $params_dump = Data::Dumper->Dump([$params], ['*params']);
232
+        
233
+        my $message = "<Created SQL>\n$sql\n<Your parameters>$params_dump";
234
+        croak("$@$message");
235
+    }
229 236
     
230 237
     # Return resultset if select statement is executed
231 238
     if ($sth->{NUM_OF_FIELDS}) {
+63 -3
t/02-sqlite.t
... ...
@@ -25,7 +25,7 @@ our $CREATE_TABLE = {
25 25
 };
26 26
 
27 27
 our $SELECT_TMPL = {
28
-    0 => 'select key1, key2 from table1;'
28
+    0 => 'select * from table1;'
29 29
 };
30 30
 
31 31
 my $dbi;
... ...
@@ -227,11 +227,71 @@ $dbi->do("delete from table1");
227 227
 $insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}';
228 228
 $dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
229 229
 
230
-$select_tmpl = 'select * from table1';
231
-$result = $dbi->execute($select_tmpl);
230
+$result = $dbi->execute($SELECT_TMPL->{0});
232 231
 $rows = $result->fetch_all_hash;
233 232
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag");
234 233
 
234
+$dbi->do("delete from table1");
235
+$dbi->execute($insert_tmpl, {'#insert' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
236
+$result = $dbi->execute($SELECT_TMPL->{0});
237
+$rows = $result->fetch_all_hash;
238
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag #insert");
239
+
240
+
241
+$dbi->do("delete from table1");
242
+$insert_tmpl = 'insert into table1 {insert table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
243
+$dbi->execute($insert_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
244
+
245
+$result = $dbi->execute($SELECT_TMPL->{0});
246
+$rows = $result->fetch_all_hash;
247
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag with table name");
248
+
249
+$dbi->do("delete from table1");
250
+$dbi->execute($insert_tmpl, {'#insert' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}});
251
+$result = $dbi->execute($SELECT_TMPL->{0});
252
+$rows = $result->fetch_all_hash;
253
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test insert tag #insert with table name");
254
+
255
+
256
+
257
+
258
+$dbi->do("delete from table1");
259
+$insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}";
260
+$dbi->execute($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
261
+$dbi->execute($insert_tmpl, {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
262
+
263
+$update_tmpl = 'update table1 {update key1 key2 key3 key4} where {= key5}';
264
+$dbi->execute($update_tmpl, {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
265
+
266
+$result = $dbi->execute($SELECT_TMPL->{0});
267
+$rows = $result->fetch_all_hash;
268
+is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
269
+                  {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test update tag");
270
+
271
+__END__
272
+
273
+$dbi->do("delete from table1");
274
+$dbi->execute($update_tmpl, {'#update' => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
275
+$result = $dbi->execute($SELECT_TMPL->{0});
276
+$rows = $result->fetch_all_hash;
277
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test update tag #update");
278
+
279
+
280
+$dbi->do("delete from table1");
281
+$update_tmpl = 'update table1 {update table1.key1 table1.key2 table1.key3 table1.key4 table1.key5}';
282
+$dbi->execute($update_tmpl, {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}});
283
+
284
+$result = $dbi->execute($SELECT_TMPL->{0});
285
+$rows = $result->fetch_all_hash;
286
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test update tag with table name");
287
+
288
+$dbi->do("delete from table1");
289
+$dbi->execute($update_tmpl, {'#update' => {table1 => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}}});
290
+$result = $dbi->execute($SELECT_TMPL->{0});
291
+$rows = $result->fetch_all_hash;
292
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test update tag #update with table name");
293
+
294
+
235 295
 
236 296
 __END__
237 297