|
|
ru.perl- RU.PERL ---------------------------------------------------------------------- From : Konstantin Osipov 2:5020/922.100 29 Sep 2000 23:27:46 To : Andrey Brindeew Subject : Some optimisations? -------------------------------------------------------------------------------- 29 Sep 00 15:20, Andrey Brindeew wrote to All: Hе вижy, что тyт особенно оптимизировать. Можно попробовать как на твоей базе работает $sth->fetchrow_hashref, но в принципе должен работать медленнее. Еще можно извращнyться, и сделать циклы foreach через map. А вообще y меня похожая задача, и я на наглядность забил. AB> sub selectall_aohref { AB> my $self = shift; AB> confess "Called without object!\n" unless ref($self); AB> my $sql = shift; AB> confess "Required parameter missing\n" unless defined $sql; AB> confess "Placeholders (?) NOT SUPPORTED due performance issues\n" if AB> $sql =~ /\?/; AB> my $result; # Reference to result data set AB> my $tmp; # Reference to source data set AB> my $sth; AB> $sth = $self->prepare($sql) || confess('Can\'t prepare statement: AB> '.$!."\n"); AB> my $rc = $sth->execute(); # Placeholders NOT SUPPORTED at this time! AB> confess "Statement execution failed: $!\n" unless defined $rc; AB> my $fieldsref = $sth->get_sth()->{NAME}; AB> $tmp = $sth->fetchall_arrayref(); AB> my ($rowref,$hashref,$val,$c1,$c2); AB> $#{$result} = $#{$tmp}; # Reserving memory AB> $c1 = 0; AB> foreach $rowref (@{$tmp}) { AB> $hashref = { }; AB> $c2 = 0; AB> foreach $val (@{$rowref}) { AB> $hashref->{${$fieldsref}[$c2]} = $val; AB> $c2++; AB> } AB> ${$result}[$c1] = $hashref; AB> $c1++; AB> } AB> undef $tmp; AB> $sth->finish(); AB> return $result; AB> } Back to the drawing board... --- * Origin: I choose not to choose life. I choose something els (2:5020/922.100) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.perl/2014039d52650.html, оценка из 5, голосов 10
|