develooper Front page | perl.dbi.users | Postings from February 2001

Re: SQL placeholder statements

Thread Previous | Thread Next
From:
Stephen Clouse
Date:
February 20, 2001 15:28
Subject:
Re: SQL placeholder statements
Message ID:
20010220172709.B1204@owns.warpcore.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sat, Jan 20, 2001 at 11:03:05PM -0000, Haris wrote:
        ^^^
Your system clock is a month off.  Anyway....

> Hello,
> As far as I understood after reading the docs about placeholders in sql
> commands,
> that the benefit gained is only for that specific process.

The assumption here is highly database-dependent.  Some servers (Oracle in 
particular, Postgre I believe is adding this if it's not in already) maintain an
SQL cache and will reuse the cached execution plan if the same SQL is sent by
any subsequent connection.  Placeholders are highly beneficial in these cases,
since the statement is the same no matter what you actually bind to the
placeholders at execute time, and thus the cache will be hit.  Consult your
server's documentation to see if it does this sort of caching.

You should be using placeholders either way, if only to spare yourself from the
pain of proper quoting when interpolating variables into SQL statements, and in 
the case of CGI and other similar programs, to spare yourself from SQL variable
interpolation attacks.

> I was wondering
> would it be possible to compile all the sql statements at server startup.
> That way all users will get the benefits .I use apache+mod_perl and keep
> persistent
> db connections started from an apache perl script

For those lesser database servers, DBI offers prepare_cached.  Its usage is well
described in the Fine Manpage.

- -- 
Stephen Clouse <stephenc@theiqgroup.com>
Senior Programmer, IQ Coordinator Project Lead
The IQ Group, Inc. <http://www.theiqgroup.com/>

-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.8

iQA/AwUBOpL9TAOGqGs0PadnEQLjDwCgyG44l7jzRDG4zg0EEsFIqF16+PcAn2K4
MUVDNvdwDSJ/vBQIYtPADArE
=l5dR
-----END PGP SIGNATURE-----

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About