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
[EMAIL PROTECTED]

> -----Original Message-----
> From: Steven Lembark [mailto:[EMAIL PROTECTED] 
> Sent: Monday, August 29, 2005 2:08 AM
> To: Hirosi Taguti; dbi-users@perl.org
> 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
> [EMAIL PROTECTED]                                     1 888 359 3508
> 

Reply via email to