RE: Memoizing non-place-holding sql statements to place-holding



Thanks, maybe I understand it.

By using prepare_cached method, I can do without a
hash like %cached_statments, and I can get a benefit from
all modules I'm making.

Regards,
Hirosi Taguti
h-taguchi@xxxxxxxxxxx

> -----Original Message-----
> From: Steven Lembark [mailto:lembark@xxxxxxxxxxx]
> Sent: Monday, August 29, 2005 2:08 AM
> To: Hirosi Taguti; dbi-users@xxxxxxxx
> Subject: RE: Memoizing non-place-holding sql statements to
> place-holding
>
>
> > I've read DBI doc but I cann't understand prepare_cached.
> > Any difference between prepare and prepare_cached?
>
> prepare_cached is useful if you are going to re-use
> a statement handle. It stores the statement handle
> in a hash keyed by the sql statement itself. This
> saves re-preparing the statement if it is reused:
>
> For example:
>
> my $sth = $dbh->prepare_cached( 'select foo from bar' );
>
> Calls code like:
>
> my $dbh = shfit;
> my $sql = shift;
>
> ...
>
> $cached_statments{ $sql } ||= $dbh->prepare( $sql );
>
> This only does the prepare once (when the ||= finds a
> false value in %prepared_statements).
>
> These are useful when you are going to re-run the same
> query any number of times from different parts of the
> code.
>
>
>
> --
> Steven Lembark 85-09 90th Street
> Workhorse Computing Woodhaven, NY 11421
> lembark@xxxxxxxxxxx 1 888 359 3508
>
.



Relevant Pages

  • Re: Re: Problem with instaling ACID
    ... Yash, ... >> Hash: SHA1 ... >> Regards, ...
    (Security-Basics)
  • Re: SWIG Ruby Memory Management
    ... >>> I just wanted to mention a hash table implementation in C which is ... >>> Regards, Pit ... > Hi Matt, ... Right now there are a few people working on bindings ...
    (comp.lang.ruby)
  • Re: Dlookup
    ... That solved the problem in the most elegant way. ... Best regards ... > Hash: SHA1 ...
    (microsoft.public.access.queries)
  • Re: A symbol ive never seen before (offtopic)
    ... Regards ... Michael ... > Hash: SHA1 ...
    (comp.text.tex)
  • Re: perl mysql question
    ... > the count to the value of each element of the hash. ... to let the db handle it by constructing a SQL statement that does a join ... on the name field and creates a calculated field for the total (a.count ...
    (perl.beginners)