>-----Original Message-----
>From: Chad [mailto:[EMAIL PROTECTED]]
>Sent: Monday, June 25, 2001 8:47 AM
>To: [EMAIL PROTECTED]
>Subject: CachedKids Attribute need help understanding
>
>
>I've just started implementing prepare_cached into my scripts 
>and my code is
>similar to the example in the book
>
>while ( ($field, $value) = each %search_fields ) {
>    push @sql,   "$field = ?";
>    push @values, $value;
>}
>$qualifier = "";
>$qualifier = "where ".join(" and ", @sql) if @sql;
>$sth = $dbh->prepare_cached("SELECT * FROM table $qualifier");

This will keep a cached statement handle. So the next time that
prepare_cached is called all of the prepare operation is not performed if
the statement is equal to what it was before.

>$sth->execute(@values);
>
>while (@ary = $sth->fetchrow_array ())
>    {
>    print join ('\t',@ary);
>    }
>
>$sth->finish();
>
>At the end of the example in 'Programming the Perl DBI' it 
>says "The cache
>can be accessed (and cleared) via the CachedKids attribute."
>
>The question I have is where is it that I place CachedKids in 
>order to clear
>the cache.  I have no idea how to use it and the book is vague 
>and doesn't
>have any example on where to put it.
>
>Searching online I've seen it used like this 
>$dbh->{CachedKids};  to like
>this $dbh->CachedKids(\%myHash); but I need a little more 
>detail.  It may be

Thus something like this:

#!/usr/bin/perl -w
use strict;

use DBI;

my $dbh = DBI->connect("dbi:ODBC:test");
my $sth = $dbh->prepare_cached("select * from product");

my $href = $dbh->{CachedKids};

foreach my $key ( keys %{$href} ) {
    print "$key\n";

}

would print: "select * from product".

So the statement you pass through prepare_cached is the key to CachedKids
ensuring that each statement is unique. It is not really meant as something
to recall a statement without calling prepare, but more as a speed tool
where the exact same statement has been issued before.

-Neil


>that I don't need to use it at all.  If that's the case then 
>please tell me.






>
>Thanks for any help that can be provided,
>Chad
>

__________________________________________________________________________
Please Note :
Only  the intended recipient is authorised to access or use this e-mail.  If
you are not the intended recipient,
please delete this e-mail and notify the sender immediately.   The contents
of this e-mail are the writer's 
opinion and are not necessarily endorsed by the Gunz Companies unless
expressly stated.

We use virus scanning software but exclude all liability for viruses or
similar in any attachment.


Reply via email to