Showing 2 changed files with 13 additions and 5 deletions
+4 -3
lib/DBI/Custom.pm
... ...
@@ -604,11 +604,11 @@ sub select {
604 604
     
605 605
     my $columns          = ref $_[0] eq 'ARRAY' ? shift : [];
606 606
     my $where_params     = ref $_[0] eq 'HASH'  ? shift : {};
607
-    my $append_statement = shift unless ref $_[0] || '';
607
+    my $append_statement = $_[0] && !ref $_[0]  ? shift : '';
608 608
     my $query_edit_cb    = shift if ref $_[0] eq 'CODE';
609 609
     
610 610
     # Check rest argument
611
-    croak($self->_select_usage) unless @_;
611
+    croak($self->_select_usage) if @_;
612 612
     
613 613
     # SQL template for select statement
614 614
     my $template = 'select ';
... ...
@@ -618,13 +618,14 @@ sub select {
618 618
         foreach my $column (@$columns) {
619 619
             $template .= "$column, ";
620 620
         }
621
-        $template .= s/, $/ /;
621
+        $template =~ s/, $/ /;
622 622
     }
623 623
     else {
624 624
         $template .= '* ';
625 625
     }
626 626
     
627 627
     # Join table
628
+    $template .= 'from ';
628 629
     foreach my $table (@$tables) {
629 630
         $template .= "$table, ";
630 631
     }
+9 -2
t/02-sqlite.t
... ...
@@ -632,8 +632,15 @@ $dbi = DBI::Custom->new($NEW_ARGS->{0});
632 632
 $dbi->do($CREATE_TABLE->{0});
633 633
 $dbi->insert('table1', {key1 => 1, key2 => 2});
634 634
 $dbi->insert('table1', {key1 => 3, key2 => 4});
635
-
636
-$rows = $dbi->select('table1')->fetch_hash_all;
635
+$rows = $dbi->select('table1')->fetch_all_hash;
637 636
 is_deeply($rows, [{key1 => 1, key2 => 2},
638 637
                   {key1 => 3, key2 => 4}], "$test : table");
639 638
 
639
+$rows = $dbi->select('table1', ['key1'])->fetch_all_hash;
640
+is_deeply($rows, [{key1 => 1}, {key1 => 3}], "$test : table and columns and where key");
641
+
642
+$rows = $dbi->select('table1', {key1 => 1})->fetch_all_hash;
643
+is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : table and columns and where key");
644
+
645
+$rows = $dbi->select('table1', ['key1'], {key1 => 3})->fetch_all_hash;
646
+is_deeply($rows, [{key1 => 3}], "$test : table and columns and where key");