Permalink
Browse files

[Pg] make fetching of hashes a "bit" simpler

  • Loading branch information...
1 parent 26983c0 commit ecdc343fb27d4aaf7c363a6118598ecbd24014f5 @moritz moritz committed Apr 27, 2012
Showing with 12 additions and 36 deletions.
  1. +6 −0 lib/DBDish.pm6
  2. +6 −36 lib/DBDish/Pg.pm6
View
@@ -54,6 +54,12 @@ role DBDish::StatementHandle does DBDish::ErrorHandling {
method fetchrow() { ... }
method execute(*@) { ... }
+ method fetchrow-hash() {
+ hash self.column_names Z=> self.fetchrow;
+ }
+
+ method fetchrow_hashref { $.fetchrow-hash }
+
method allrows {
gather while self.fetchrow -> @row {
take @row.item;
View
@@ -197,44 +197,14 @@ class DBDish::Pg::StatementHandle does DBDish::StatementHandle {
return @row_array;
}
- method fetchrow_hashref () {
- my $row_hashref;
- my %row_hash;
-
- return if $!current_row >= $!row_count;
-
- unless defined $!field_count {
- $!field_count = PQnfields($!result);
- }
-
- if defined $!result {
- self!reset_errstr;
- my $errstr = PQresultErrorMessage ($!result);
- if $errstr ne '' {
- self!set_errstr($errstr);
- return;
- }
-
- my @row = self!get_row();
-
- unless @!column_names {
- for ^$!field_count {
- my $column_name = PQfname($!result, $_);
- @!column_names.push($column_name);
- }
- }
-
- if @row && @!column_names {
- for @row Z @!column_names -> $column_value, $column_name {
- %row_hash{$column_name} = $column_value;
- }
- } else {
- self.finish;
+ method column_names {
+ $!field_count = PQnfields($!result);
+ unless @!column_names {
+ for ^$!field_count {
+ my $column_name = PQfname($!result, $_);
+ @!column_names.push($column_name);
}
-
- $row_hashref = %row_hash;
}
- return $row_hashref;
}
method fetchall_hashref(Str $key) {

0 comments on commit ecdc343

Please sign in to comment.