sqlite.html

来自「perl教程」· HTML 代码 · 共 414 行 · 第 1/2 页

HTML
414
字号
<?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>DBD::SQLite - Self Contained RDBMS in a DBI Driver</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>DBD::SQLite - Self Contained RDBMS in a DBI Driver</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="#conformance_with_dbi_specification">CONFORMANCE WITH DBI SPECIFICATION</a></li>
	<li><a href="#driver_private_attributes">DRIVER PRIVATE ATTRIBUTES</a></li>
	<ul>

		<li><a href="#database_handle_attributes">Database Handle Attributes</a></li>
	</ul>

	<li><a href="#driver_private_methods">DRIVER PRIVATE METHODS</a></li>
	<ul>

		<li><a href="#_dbh_func__last_insert_rowid__">$dbh-&gt;<code>func('last_insert_rowid')</code></a></li>
		<li><a href="#_dbh_func___busy_timeout___">$dbh-&gt;func( 'busy_timeout' )</a></li>
		<li><a href="#_dbh_func___ms___busy_timeout___">$dbh-&gt;func( $ms, 'busy_timeout' )</a></li>
		<li><a href="#_dbh_func___name___argc___func_ref__create_function__">$dbh-&gt;func( $name, $argc, $func_ref, &quot;create_function&quot; )</a></li>
		<li><a href="#_dbh_func___name___argc___pkg___create_aggregate___">$dbh-&gt;func( $name, $argc, $pkg, 'create_aggregate' )</a></li>
	</ul>

	<li><a href="#blobs">BLOBS</a></li>
	<li><a href="#notes">NOTES</a></li>
	<li><a href="#performance">PERFORMANCE</a></li>
	<li><a href="#bugs">BUGS</a></li>
	<li><a href="#author">AUTHOR</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>DBD::SQLite - Self Contained RDBMS in a DBI Driver</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
  <span class="keyword">use</span> <span class="variable">DBI</span><span class="operator">;</span>
  <span class="keyword">my</span> <span class="variable">$dbh</span> <span class="operator">=</span> <span class="variable">DBI</span><span class="operator">-&gt;</span><span class="keyword">connect</span><span class="operator">(</span><span class="string">"dbi:SQLite:dbname=dbfile"</span><span class="operator">,</span><span class="string">""</span><span class="operator">,</span><span class="string">""</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>SQLite is a public domain RDBMS database engine that you can find
at <a href="http://www.hwaci.com/sw/sqlite/.">http://www.hwaci.com/sw/sqlite/.</a></p>
<p>Rather than ask you to install SQLite first, because SQLite is public
domain, DBD::SQLite includes the entire thing in the distribution. So
in order to get a fast transaction capable RDBMS working for your
perl project you simply have to install this module, and <strong>nothing</strong>
else.</p>
<p>SQLite supports the following features:</p>
<dl>
<dt><strong><a name="item_implements_a_large_subset_of_sql92">Implements a large subset of SQL92</a></strong>

<dd>
<p>See <a href="http://www.hwaci.com/sw/sqlite/lang.html">http://www.hwaci.com/sw/sqlite/lang.html</a> for details.</p>
</dd>
</li>
<dt><strong><a name="item_a_complete_db_in_a_single_disk_file">A complete DB in a single disk file</a></strong>

<dd>
<p>Everything for your database is stored in a single disk file, making it
easier to move things around than with DBD::CSV.</p>
</dd>
</li>
<dt><strong><a name="item_atomic_commit_and_rollback">Atomic commit and rollback</a></strong>

<dd>
<p>Yes, DBD::SQLite is small and light, but it supports full transactions!</p>
</dd>
</li>
<dt><strong><a name="item_extensible">Extensible</a></strong>

<dd>
<p>User-defined aggregate or regular functions can be registered with the
SQL parser.</p>
</dd>
</li>
</dl>
<p>There's lots more to it, so please refer to the docs on the SQLite web
page, listed above, for SQL details. Also refer to <a href="../../lib/DBI.html">the DBI manpage</a> for details
on how to use DBI itself.</p>
<p>
</p>
<hr />
<h1><a name="conformance_with_dbi_specification">CONFORMANCE WITH DBI SPECIFICATION</a></h1>
<p>The API works like every DBI module does. Please see <a href="../../lib/DBI.html">the DBI manpage</a> for more
details about core features.</p>
<p>Currently many statement attributes are not implemented or are
limited by the typeless nature of the SQLite database.</p>
<p>
</p>
<hr />
<h1><a name="driver_private_attributes">DRIVER PRIVATE ATTRIBUTES</a></h1>
<p>
</p>
<h2><a name="database_handle_attributes">Database Handle Attributes</a></h2>
<dl>
<dt><strong><a name="item_sqlite_version">sqlite_version</a></strong>

<dd>
<p>Returns the version of the SQLite library which DBD::SQLite is using,
e.g., &quot;2.8.0&quot;. Can only be read.</p>
</dd>
</li>
<dt><strong><a name="item_unicode">unicode</a></strong>

<dd>
<p>If set to a true value, DBD::SQLite will turn the UTF-8 flag on for all text
strings coming out of the database. For more details on the UTF-8 flag see
<a href="../../lib/Pod/perlunicode.html">the perlunicode manpage</a>. The default is for the UTF-8 flag to be turned off.</p>
</dd>
<dd>
<p>Also note that due to some bizareness in SQLite's type system (see
<a href="http://www.sqlite.org/datatype3.html),">http://www.sqlite.org/datatype3.html),</a> if you want to retain
blob-style behavior for <strong>some</strong> columns under <code>$dbh-&gt;{unicode} = 1
&gt;&gt; (say, to store images in the database), you have to state so
explicitely using the 3-argument form of DBI/bind_param</code> when doing
updates:</p>
</dd>
<dd>
<pre>
    <span class="keyword">use</span> <span class="variable">DBI</span> <span class="string">qw(:sql_types)</span><span class="operator">;</span>
    <span class="variable">$dbh</span><span class="operator">-&gt;</span><span class="operator">{</span><span class="string">unicode</span><span class="operator">}</span> <span class="operator">=</span> <span class="number">1</span><span class="operator">;</span>
    <span class="keyword">my</span> <span class="variable">$sth</span> <span class="operator">=</span> <span class="variable">$dbh</span><span class="operator">-&gt;</span><span class="variable">prepare</span>
         <span class="operator">(</span><span class="string">"INSERT INTO mytable (blobcolumn) VALUES (?)"</span><span class="operator">);</span>
    <span class="variable">$sth</span><span class="operator">-&gt;</span><span class="variable">bind_param</span><span class="operator">(</span><span class="number">1</span><span class="operator">,</span> <span class="variable">$binary_data</span><span class="operator">,</span> <span class="variable">SQL_BLOB</span><span class="operator">);</span> <span class="comment"># binary_data will</span>
    <span class="comment"># be stored as-is.</span>
</pre>
</dd>
<dd>
<p>Defining the column type as BLOB in the DDL is <strong>not</strong> sufficient.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="driver_private_methods">DRIVER PRIVATE METHODS</a></h1>
<p>
</p>
<h2><a name="_dbh_func__last_insert_rowid__">$dbh-&gt;<code>func('last_insert_rowid')</code></a></h2>
<p>This method returns the last inserted rowid. If you specify an INTEGER PRIMARY
KEY as the first column in your table, that is the column that is returned.
Otherwise, it is the hidden ROWID column. See the sqlite docs for details.</p>
<p>Note: You can now use $dbh-&gt;<code>last_insert_id()</code> if you have a recent version of
DBI.</p>
<p>
</p>
<h2><a name="_dbh_func___busy_timeout___">$dbh-&gt;func( 'busy_timeout' )</a></h2>
<p>Retrieve the current busy timeout.</p>
<p>
</p>
<h2><a name="_dbh_func___ms___busy_timeout___">$dbh-&gt;func( $ms, 'busy_timeout' )</a></h2>
<p>Set the current busy timeout. The timeout is in milliseconds.</p>
<p>
</p>
<h2><a name="_dbh_func___name___argc___func_ref__create_function__">$dbh-&gt;func( $name, $argc, $func_ref, &quot;create_function&quot; )</a></h2>
<p>This method will register a new function which will be useable in SQL
query. The method's parameters are:</p>
<dl>
<dt><strong><a name="item__name">$name</a></strong>

<dd>
<p>The name of the function. This is the name of the function as it will
be used from SQL.</p>
</dd>
</li>
<dt><strong><a name="item__argc">$argc</a></strong>

<dd>
<p>The number of arguments taken by the function. If this number is -1,
the function can take any number of arguments.</p>
</dd>
</li>
<dt><strong><a name="item__func_ref">$func_ref</a></strong>

<dd>
<p>This should be a reference to the function's implementation.</p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?