mirror of
https://github.com/php/doc-ja.git
synced 2026-03-25 23:52:16 +01:00
* php/doc-en#4288 を反映(PDOのディレクトリ構成変更) * php/doc-en#4298 を反映(不要セクションの削除) * Update EN-Revision * php/doc-en#4330 を反映(PDOの階層構造の変更)
188 lines
6.0 KiB
XML
188 lines
6.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 51610360d58ed09bc9d1312f419057c0d1d1a998 Maintainer: KentarouTakeda Status: ready -->
|
|
<!-- CREDITS: KentarouTakeda -->
|
|
<refentry xml:id="pdo-sqlite.createfunction" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>Pdo\Sqlite::createFunction</refname>
|
|
<refpurpose>
|
|
SQL 文で使用するユーザー定義関数を登録する
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis role="Pdo\\Sqlite">
|
|
<modifier>public</modifier> <type>bool</type><methodname>Pdo\Sqlite::createFunction</methodname>
|
|
<methodparam><type>string</type><parameter>function_name</parameter></methodparam>
|
|
<methodparam><type>callable</type><parameter>callback</parameter></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>num_args</parameter><initializer>-1</initializer></methodparam>
|
|
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
PHP 関数を、ユーザー定義関数として SQLite に登録します。
|
|
登録した関数は、SQL 文の中で使用することが可能です。
|
|
ユーザー定義関数は、関数をコールできるあらゆる SQL 文
|
|
(<literal>SELECT</literal>、<literal>UPDATE</literal> 、トリガなど) から呼び出せます。
|
|
</simpara>
|
|
<tip>
|
|
<simpara>
|
|
このメソッドを使用してネイティブ SQL 関数を上書きすることができます。
|
|
</simpara>
|
|
</tip>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>function_name</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
SQL 文で使用する関数の名前。
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>callback</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
定義した SQL 関数を処理するコールバック関数。
|
|
</simpara>
|
|
<note>
|
|
<simpara>
|
|
この関数が返す値は、SQLite が理解できる形式 (すなわち
|
|
<link linkend="language.types.intro">スカラー型</link>)
|
|
でなければなりません。
|
|
</simpara>
|
|
</note>
|
|
<para>
|
|
コールバック関数の定義は次のとおりです:
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname><replaceable>callback</replaceable></methodname>
|
|
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
|
|
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>value</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
SQL関数に渡す最初の引数
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>values</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
SQL関数に渡す2つ目以降の引数
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>num_args</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
SQL 関数がとる引数の数。
|
|
このパラメータが <literal>-1</literal> の場合、
|
|
SQL 関数は任意の数の引数を取ることができます。
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>flags</parameter></term>
|
|
<listitem>
|
|
<simpara>
|
|
ビット単位のフラグの組み合わせ。
|
|
現在は、<constant>PDO::SQLITE_DETERMINISTIC</constant> だけがサポートされています。
|
|
これは、単一のSQLステートメント内では、
|
|
同じ入力に対して常に同じ結果を返すことを指定します。
|
|
</simpara>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<simpara>
|
|
&return.success;
|
|
</simpara>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example xml:id="pdo-sqlite.createfunction.example.basic">
|
|
<title><methodname>Pdo\Sqlite::createFunction</methodname> の例</title>
|
|
<simpara>
|
|
この例では、文字列の SHA256 ハッシュを計算し
|
|
それを反転する関数を使っています。SQL 文を実行すると、
|
|
この関数によって変換されたファイル名が
|
|
<varname>$rows</varname> に格納され返ります。
|
|
</simpara>
|
|
<simpara>
|
|
この手法の素晴らしい点は、クエリの後に
|
|
&foreach; ループを用いて結果を処理する必要がないことです。
|
|
</simpara>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function sha256_and_reverse($string)
|
|
{
|
|
return strrev(hash('sha256', $string));
|
|
}
|
|
|
|
$db = new Pdo\Sqlite('sqlite::sqlitedb');
|
|
$db->sqliteCreateFunction('sha256rev', 'sha256_and_reverse', 1);
|
|
$rows = $db->query('SELECT sha256rev(filename) FROM files')->fetchAll();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<!-- TODO
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Code example
|
|
]]>
|
|
</screen>
|
|
-->
|
|
</example>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<simplelist>
|
|
<member><methodname>Pdo\Sqlite::createAggregate</methodname></member>
|
|
<member><methodname>Pdo\Sqlite::createCollation</methodname></member>
|
|
<member><function>sqlite_create_function</function></member>
|
|
<member><function>sqlite_create_aggregate</function></member>
|
|
</simplelist>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|