pureperl.html
来自「perl教程」· HTML 代码 · 共 222 行
HTML
222 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>DBI::PurePerl -- a DBI emulation using pure perl</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>DBI::PurePerl -- a DBI emulation using pure perl</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#experimental_status">EXPERIMENTAL STATUS</a></li>
<li><a href="#usage">USAGE</a></li>
<li><a href="#installation">INSTALLATION</a></li>
<li><a href="#differences_between_dbi_and_dbi__pureperl">DIFFERENCES BETWEEN DBI AND DBI::PurePerl</a></li>
<ul>
<li><a href="#attributes">Attributes</a></li>
<li><a href="#tracing">Tracing</a></li>
<li><a href="#parameter_usage_checking">Parameter Usage Checking</a></li>
<li><a href="#speed">Speed</a></li>
<li><a href="#may_not_fully_support_hash__">May not fully support <code>hash()</code></a></li>
<li><a href="#doesn_t_support_preparse__">Doesn't support <code>preparse()</code></a></li>
<li><a href="#doesn_t_support_dbd__proxy">Doesn't support DBD::Proxy</a></li>
<li><a href="#others">Others</a></li>
</ul>
<li><a href="#authors">AUTHORS</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<hr />
<h1><a name="name">NAME</a></h1>
<p>DBI::PurePerl -- a DBI emulation using pure perl (no C/XS compilation required)</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">BEGIN</span> <span class="operator">{</span> <span class="variable">$ENV</span><span class="operator">{</span><span class="string">DBI_PUREPERL</span><span class="operator">}</span> <span class="operator">=</span> <span class="number">2</span> <span class="operator">}</span>
<span class="keyword">use</span> <span class="variable">DBI</span><span class="operator">;</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This is a pure perl emulation of the DBI internals. In almost all
cases you will be better off using standard DBI since the portions
of the standard version written in C make it *much* faster.</p>
<p>However, if you are in a situation where it isn't possible to install
a compiled version of standard DBI, and you're using pure-perl DBD
drivers, then this module allows you to use most common features
of DBI without needing any changes in your scripts.</p>
<p>
</p>
<hr />
<h1><a name="experimental_status">EXPERIMENTAL STATUS</a></h1>
<p>DBI::PurePerl is new so please treat it as experimental pending
more extensive testing. So far it has passed all tests with DBD::CSV,
DBD::AnyData, DBD::XBase, DBD::Sprite, DBD::mysqlPP. Please send
bug reports to Jeff Zucker at <<a href="mailto:jeff@vpservices.com">jeff@vpservices.com</a>> with a cc to
<<a href="mailto:dbi-dev@perl.org">dbi-dev@perl.org</a>>.</p>
<p>
</p>
<hr />
<h1><a name="usage">USAGE</a></h1>
<p>The usage is the same as for standard DBI with the exception
that you need to set the enviornment variable DBI_PUREPERL if
you want to use the PurePerl version.</p>
<pre>
DBI_PUREPERL == 0 (the default) Always use compiled DBI, die
if it isn't properly compiled & installed</pre>
<pre>
DBI_PUREPERL == 1 Use compiled DBI if it is properly compiled
& installed, otherwise use PurePerl</pre>
<pre>
DBI_PUREPERL == 2 Always use PurePerl</pre>
<p>You may set the enviornment variable in your shell (e.g. with
set or setenv or export, etc) or else set it in your script like
this:</p>
<pre>
<span class="keyword">BEGIN</span> <span class="operator">{</span> <span class="variable">$ENV</span><span class="operator">{</span><span class="string">DBI_PUREPERL</span><span class="operator">}</span><span class="operator">=</span><span class="number">2</span> <span class="operator">}</span>
</pre>
<p>before you <code>use DBI;</code>.</p>
<p>
</p>
<hr />
<h1><a name="installation">INSTALLATION</a></h1>
<p>In most situations simply install DBI (see the DBI pod for details).</p>
<p>In the situation in which you can not install DBI itself, you
may manually copy DBI.pm and PurePerl.pm into the appropriate
directories.</p>
<p>For example:</p>
<pre>
cp DBI.pm /usr/jdoe/mylibs/.
cp PurePerl.pm /usr/jdoe/mylibs/DBI/.</pre>
<p>Then add this to the top of scripts:</p>
<pre>
<span class="keyword">BEGIN</span> <span class="operator">{</span>
<span class="variable">$ENV</span><span class="operator">{</span><span class="string">DBI_PUREPERL</span><span class="operator">}</span> <span class="operator">=</span> <span class="number">1</span><span class="operator">;</span> <span class="comment"># or =2</span>
<span class="keyword">unshift</span> <span class="variable">@INC</span><span class="operator">,</span> <span class="string">'/usr/jdoe/mylibs'</span><span class="operator">;</span>
<span class="operator">}</span>
</pre>
<p>(Or should we perhaps patch Makefile.PL so that if DBI_PUREPERL
is set to 2 prior to make, the normal compile process is skipped
and the files are installed automatically?)</p>
<p>
</p>
<hr />
<h1><a name="differences_between_dbi_and_dbi__pureperl">DIFFERENCES BETWEEN DBI AND DBI::PurePerl</a></h1>
<p>
</p>
<h2><a name="attributes">Attributes</a></h2>
<p>Boolean attributes still return boolean values but the actual values
used may be different, i.e., 0 or undef instead of an empty string.</p>
<p>Some handle attributes are either not supported or have very limited
functionality:</p>
<pre>
ActiveKids
InactiveDestroy
Kids
Taint
TaintIn
TaintOut</pre>
<p>(and probably others)</p>
<p>
</p>
<h2><a name="tracing">Tracing</a></h2>
<p>Trace functionality is more limited and the code to handle tracing is
only embeded into DBI:PurePerl if the DBI_TRACE environment variable
is defined. To enable total tracing you can set the DBI_TRACE
environment variable as usual. But to enable individual handle
tracing using the <code>trace()</code> method you also need to set the DBI_TRACE
environment variable, but set it to 0.</p>
<p>
</p>
<h2><a name="parameter_usage_checking">Parameter Usage Checking</a></h2>
<p>The DBI does some basic parameter count checking on method calls.
DBI::PurePerl doesn't.</p>
<p>
</p>
<h2><a name="speed">Speed</a></h2>
<p>DBI::PurePerl is slower. Although, with some drivers in some
contexts this may not be very significant for you.</p>
<p>By way of example... the test.pl script in the DBI source
distribution has a simple benchmark that just does:</p>
<pre>
<span class="keyword">my</span> <span class="variable">$null_dbh</span> <span class="operator">=</span> <span class="variable">DBI</span><span class="operator">-></span><span class="keyword">connect</span><span class="operator">(</span><span class="string">'dbi:NullP:'</span><span class="operator">,</span><span class="string">''</span><span class="operator">,</span><span class="string">''</span><span class="operator">);</span>
<span class="keyword">my</span> <span class="variable">$i</span> <span class="operator">=</span> <span class="number">10_000</span><span class="operator">;</span>
<span class="variable">$null_dbh</span><span class="operator">-></span><span class="variable">prepare</span><span class="operator">(</span><span class="string">''</span><span class="operator">)</span> <span class="keyword">while</span> <span class="variable">$i</span><span class="operator">--;</span>
</pre>
<p>In other words just prepares a statement, creating and destroying
a statement handle, over and over again. Using the real DBI this
runs at ~4550 handles per second whereas DBI::PurePerl manages
~2800 per second on the same machine (not too bad really).</p>
<p>
</p>
<h2><a name="may_not_fully_support_hash__">May not fully support <code>hash()</code></a></h2>
<p>If you want to use type 1 hash, i.e., <code>hash($string,1)</code> with
DBI::PurePerl, you'll need version 1.56 or higher of Math::BigInt
(available on CPAN).</p>
<p>
</p>
<h2><a name="doesn_t_support_preparse__">Doesn't support <code>preparse()</code></a></h2>
<p>The DBI-><code>preparse()</code> method isn't supported in DBI::PurePerl.</p>
<p>
</p>
<h2><a name="doesn_t_support_dbd__proxy">Doesn't support DBD::Proxy</a></h2>
<p>There's a subtle problem somewhere I've not been able to identify.
DBI::ProxyServer seem to work fine with DBI::PurePerl but DBD::Proxy
does not work 100% (which is sad because that would be far more useful :)
Try re-enabling t/80proxy.t for DBI::PurePerl to see if the problem
that remains will affect you're usage.</p>
<p>
</p>
<h2><a name="others">Others</a></h2>
<pre>
can() - doesn't have any special behaviour</pre>
<p>Please let us know if you find any other differences between DBI
and DBI::PurePerl.</p>
<p>
</p>
<hr />
<h1><a name="authors">AUTHORS</a></h1>
<p>Tim Bunce and Jeff Zucker.</p>
<p>Tim provided the direction and basis for the code. The original
idea for the module and most of the brute force porting from C to
Perl was by Jeff. Tim then reworked some core parts to boost the
performance and accuracy of the emulation. Thanks also to Randal
Schwartz and John Tobey for patches.</p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright (c) 2002 Tim Bunce Ireland.</p>
<p>See COPYRIGHT section in DBI.pm for usage and distribution rights.</p>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?