Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: [mv] Perl loop



******    message to minivend-users from Mike Heins <mikeh@minivend.com>     ******

Quoting Stefan Hornburg (racke@linuxia.de):
> 
> 
> Is this the best way to loop over a database within perl or is there a
> faster solution ?
> 
> [perl table=store]
> $DbSearch->{table} = $Db{store};
> $srch_ary = $DbSearch->array({ra => 1, fi => 'store'});
> for (@$srch_ary) {
>         ...
> }
> [/perl]
> 

Depends on the DB type. If it is SQL, that is quite fast, but for
a Minivend database it would be faster to use the TextSearch (assuming
the text file was up to date).

For SQL, this is the fastest:

 [perl table=store]
 my $dbh = $Sql{store};
 $dbref = $Db{store};
 my $key = $dbref->config('KEY');
 my $sth = $dbh->prepare("select $key from store")
	or return "bad reference";
 $sth->execute()
	or return "select failed";
 $srch_ary = $sth->fetchall_arrayref();
 for (@$srch_ary) {
         ...
 }
 [/perl]

This is portable and will be quite fast:

 [query arrayref=srch_ary st=db sql="select code from store"][/query]

 [perl tables=store]
    my $srch_ary = $Tmp->{srch_ary};
    for (@$srch_ary) {
            ...
    }
 [/perl]

-- 
Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH  45056
phone +1.513.523.8220 fax 7501 <heins@akopia.com>

The U.S. Senate -- white male millionaires working for YOU!  -- Dave Barry
-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: