mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 08:22:08 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@334774 c90b9560-bf6c-de11-be94-00142212c4b1
184 lines
5.3 KiB
XML
184 lines
5.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 14af302c9c0e561fa6f9cdd956268758ba9a89c5 Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="pdo.sqlitecreatefunction" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>PDO::sqliteCreateFunction</refname>
|
|
<refpurpose>
|
|
Registra una función definida por el usuario para utilizarla en sentencias SQL
|
|
</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier> <type>bool</type><methodname>PDO::sqliteCreateFunction</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></methodparam>
|
|
</methodsynopsis>
|
|
&warn.experimental.func;
|
|
|
|
<para>
|
|
Este método permite registrar una función de PHP con SQLite como una
|
|
<acronym>FDU</acronym> (Función Definida por el Usuario), y así poder invocarla
|
|
desde dentro de sentencias SQL.
|
|
</para>
|
|
<para>
|
|
LA FDU se puede usar en cualquier sentencia SQL que pueda invocar funciones, tales como
|
|
SELECT y UPDATE, y también en disparadores.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>function_name</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
El nombre de la función usada en sentencias SQL.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>callback</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Una función de llamada de retorno para manejar la función SQL definida.
|
|
</para>
|
|
<note>
|
|
<simpara>
|
|
Las funciones de llamada de retorno deberían devolver un tipo comprendido por
|
|
SQLite (esto es, <link linkend="language.types.intro">del tipo escalar</link>).
|
|
</simpara>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>num_args</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Una sugerencia para el analizador de SQLite si la función de llamada de retorno acepta
|
|
un número predeterminado de argumentos.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.success;
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo de <function>PDO::sqliteCreateFunction</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function md5_e_invertir($string)
|
|
{
|
|
return strrev(md5($string));
|
|
}
|
|
|
|
$bd = new PDO('sqlite:sqlitedb');
|
|
$bd->sqliteCreateFunction('md5rev', 'md5_e_invertir', 1);
|
|
$filas = $bd->query('SELECT md5rev(filename) FROM files')->fetchAll();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
En este ejemplo, se tiene una función que calcula la suma md5 de una
|
|
cadena, y luego la inverte. Cuando se ejecuta la sentencia SQL,
|
|
devuelve el valor del nombre del fichero transformado por dicha función. Los datos
|
|
devueltos en <parameter>$filas</parameter> contienen el resultado procesado.
|
|
</para>
|
|
<para>
|
|
La belleza de esta técnica consiste en que no se necesario procesar el
|
|
resultado usando un bucle &foreach; después de haber consultado los datos.
|
|
</para>
|
|
<!-- not for PDO it doesn't, at least not yet
|
|
<para>
|
|
PHP registers a special function named <literal>php</literal> when the
|
|
database is first opened. The php function can be used to call any PHP
|
|
function without having to register it first.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Example of using the PHP function</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$rows = $db->query("SELECT php('md5', filename) from files")->fetchAll();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
This example will call the <function>md5</function> on each
|
|
<literal>filename</literal> column in the database and return the result
|
|
into <parameter>$rows</parameter>
|
|
</para>
|
|
</example>
|
|
</para>
|
|
|
|
-->
|
|
<tip>
|
|
<para>
|
|
Se puede usar <xref linkend="pdo.sqlitecreatefunction" /> y
|
|
<xref linkend="pdo.sqlitecreateaggregate" /> para invalidar funciones SQL
|
|
nativas de SQLite.
|
|
</para>
|
|
</tip>
|
|
<note>
|
|
<para>
|
|
Este método no está disponible con el controlador SQLite2.
|
|
Use la API de sqlite de estilo antiguo en su lugar.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><xref linkend="pdo.sqlitecreateaggregate" /></member>
|
|
<member><function>sqlite_create_function</function></member>
|
|
<member><function>sqlite_create_aggregate</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</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
|
|
-->
|