mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 07:02:08 +01:00
- reference/mbstring/functions/mb-decode-numericentity.xml 1. php/doc-en@4e69a9f2b1 - reference/imap/functions/imap-headerinfo.xml 1. php/doc-en@4e69a9f2b1 - reference/ssh2/functions/ssh2-auth-pubkey-file.xml 1. php/doc-en@74ef2355c5 - reference/ssh2/functions/ssh2-connect.xml 1. php/doc-en@74ef2355c5 - reference/stream/functions/stream-filter-append.xml 1. php/doc-en@a684294e0b - reference/stream/functions/stream-filter-prepend.xml 1. php/doc-en@a684294e0b - reference/filesystem/functions/fgetcsv.xml 1. php/doc-en@e1fd0bef1d 2. php/doc-en@0a3648a718 3. `&warning.csv.escape-parameter;` の重複を削除(既訳のバグ修正) - reference/spl/splfileobject/fgetcsv.xml 1. php/doc-en@e1fd0bef1d 2. php/doc-en@3a89b55d11 3. php/doc-en@0a3648a718 - language/predefined/attributes/nodiscard.xml 1. php/doc-en@30bda33771 - reference/pdo_sqlite/pdo/sqlite/createfunction.xml 1. php/doc-en@28930349ca - reference/math/functions/fmod.xml 1. php/doc-en@54a788ca59 - reference/simplexml/simplexmlelement/addChild.xml 1. php/doc-en@dca2a8354f - reference/json/functions/json-last-error.xml 1. php/doc-en@058ea1e842 - features/commandline.xml 1. php/doc-en@96b10a9885 - appendices/migration85/incompatible.xml 1. php/doc-en@048982b729 2. php/doc-en@f81bbcf9d3 - reference/random/random/randomizer/getfloat.xml 1. php/doc-en@1ada637cc8 2. php/doc-en@423a1da63f - reference/mysqli/mysqli/multi-query.xml 1. php/doc-en@1beae37b69 - reference/image/functions/getimagesize.xml 1. php/doc-en@6bb90d24b2 - reference/curl/functions/curl-close.xml 1. php/doc-en@86c8ebd19e - reference/curl/functions/curl-share-close.xml 1. php/doc-en@29c3d13980 - reference/yaml/functions/yaml-parse-file.xml 1. php/doc-en@132d2a8d63 - reference/mysqli/mysqli/options.xml 1. php/doc-en@e309a62b16 2. MYSQLI_SERVER_PUBLIC_KEY の古い「PHP 5.5.0 以降」テキストを削除(既訳のバグ修正) - appendices/transports.xml 1. php/doc-en@ae90ecc932 - reference/soap/soapserver/addfunction.xml 1. php/doc-en@577239f64b - reference/var/functions/settype.xml 1. php/doc-en@8d49e302b4 - features/http-auth.xml 1. php/doc-en@cd4180557a
188 lines
6.0 KiB
XML
188 lines
6.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 28930349caaaa78f908c380e44066d37a70e97b8 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->createFunction('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
|
|
-->
|