Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplify drivers for post GLR role
  • Loading branch information
salortiz committed Mar 19, 2016
1 parent 3849814 commit d20be30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 88 deletions.
36 changes: 5 additions & 31 deletions lib/DBDish/Pg/StatementHandle.pm6
Expand Up @@ -70,48 +70,22 @@ method execute(*@params) {
}
}

method _row(:$hash) {
my @row_array;
my %ret_hash;
method _row() {
my $l = ();
if $!field_count && $!current_row < $!row_count {
for ^$!field_count {
$l = do for ^$!field_count {
my $value = @!column-type[$_];
unless $!result.PQgetisnull($!current_row, $_) {
$value = $!result.get-value($!current_row, $_, $value);
if @!column-type[$_] ~~ Array {
$value = _pg-to-array($value, @!column-type[$_].of);
}
}
$hash ?? (%ret_hash{@!column-name[$_]} = $value)
!! @row_array.push($value);
}
self.finish if ++$!current_row == $!row_count;
$value;
}
$hash ?? %ret_hash !! @row_array;
}

method fetchrow() {
my @row_array;
if $!field_count && $!current_row < $!row_count {
@row_array.push($!result.PQgetisnull($!current_row, $_) ?? Str
!! $!result.PQgetvalue($!current_row, $_)
) for ^$!field_count;
self.finish if ++$!current_row == $!row_count;
}
@row_array;
}

method fetchall_hashref(Str $key) {
my %results;

return () if $!current_row >= $!row_count;

while my $row = self.fetchrow_hashref {
%results{$row{$key}} = $row;
}

my $results_ref = %results;
$results_ref;
$l;
}

my grammar PgArrayGrammar {
Expand Down
41 changes: 12 additions & 29 deletions lib/DBDish/SQLite/StatementHandle.pm6
Expand Up @@ -39,12 +39,12 @@ method execute(*@params) {
self!set-err($!row_status, sqlite3_errmsg($!conn));
} else {
my $rows = 0; my $was-select = True;
without $!field_count {
$!field_count = sqlite3_column_count($!statement_handle);
for ^$!field_count {
@!column-name.push: sqlite3_column_name($!statement_handle, $_);
@!column-type.push: Any; #TODO
}
without $!field_count {
$!field_count = sqlite3_column_count($!statement_handle);
for ^$!field_count {
@!column-name.push: sqlite3_column_name($!statement_handle, $_);
@!column-type.push: Any; #TODO
}
}
unless $!field_count { # Assume non SELECT
$rows = sqlite3_changes($!conn);
Expand All @@ -54,11 +54,10 @@ method execute(*@params) {
}
}

method _row (:$hash) {
my @row;
my %hash;
method _row() {
my $list = ();
if $!row_status == SQLITE_ROW {
for ^$!field_count -> $col {
$list = do for ^$!field_count -> $col {
my $value;
given sqlite3_column_type($!statement_handle, $col) {
when SQLITE_INTEGER {
Expand All @@ -74,38 +73,22 @@ method _row (:$hash) {
}
when SQLITE_NULL {
# SQLite can't determine the type of NULL column, so instead
# of lyng, prefer an explicit Nil.
# of lying, prefer an explicit Nil.
$value = Nil;
}
default {
$value = sqlite3_column_text($!statement_handle, $col);
}
}
$hash ?? (%hash{@!column-name[$col]} = $value) !! @row.push($value);
}
$!affected_rows++;
self.reset-err;
if ($!row_status = sqlite3_step($!statement_handle)) == SQLITE_DONE {
self.finish;
}
}
$hash ?? %hash !! @row;
}

method fetchrow {
my @row;
die 'fetchrow_array without prior execute' unless $!row_status;
if $!row_status == SQLITE_ROW {
for ^$!field_count {
@row.push: sqlite3_column_text($!statement_handle, $_);
$value;
}
$!affected_rows++;
self.reset-err;
if ($!row_status = sqlite3_step($!statement_handle)) == SQLITE_DONE {
self.finish;
}
}
@row;
$list;
}

method _free {
Expand Down
32 changes: 4 additions & 28 deletions lib/DBDish/mysql/StatementHandle.pm6
Expand Up @@ -100,43 +100,19 @@ method !get_result {
$!Prefetch ?? $!mysql_client.mysql_store_result !! $!mysql_client.mysql_use_result;
}

method _row(:$hash) {
my @row_array;
my %hash;
my @names;
my @types;

method _row {
my $list = ();
if $!field_count -> $fields {
if my $row = $!result_set.fetch_row {
loop (my int $i = 0; $i < $fields; $i++) {
my $value = $row.want($i, @!column-type[$i]);
$hash ?? (%hash{@!column-name[$i]} = $value) !! @row_array.push($value);
}
$!affected_rows++ unless $!Prefetch;
}
else {
.fail without self!handle-errors;
self.finish;
}
}
$hash ?? %hash !! @row_array;
}

method fetchrow() {
my @row_array;
if $!field_count {
if my $native_row = $!result_set.fetch_row {
loop (my int $i=0; $i < $!field_count; $i++ ) {
@row_array.push($native_row[$i]);
}
$list = do for ^$fields { $row.want($_, @!column-type[$_]) }
$!affected_rows++ unless $!Prefetch;
}
else {
.fail without self!handle-errors;
self.finish;
}
}
@row_array;
$list;
}

method mysql_insertid() {
Expand Down

0 comments on commit d20be30

Please sign in to comment.