2003-06-21 13:24:58 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2005-02-21 00:31:07 +00:00
|
|
|
<!-- $Revision: 1.6 $ -->
|
2003-06-21 13:24:58 +00:00
|
|
|
<refentry id="function.sqlite-udf-decode-binary">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>sqlite_udf_decode_binary</refname>
|
2004-07-27 04:48:55 +00:00
|
|
|
<refpurpose>Decode binary data passed as parameters to an UDF</refpurpose>
|
2003-06-21 13:24:58 +00:00
|
|
|
</refnamediv>
|
2005-02-21 00:31:07 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2003-06-21 13:24:58 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>string</type><methodname>sqlite_udf_decode_binary</methodname>
|
|
|
|
<methodparam><type>string</type><parameter>data</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
<function>sqlite_udf_decode_binary</function> decodes the binary encoding
|
|
|
|
that was applied to the parameter by either
|
|
|
|
<function>sqlite_udf_encode_binary</function> or
|
|
|
|
<function>sqlite_escape_string</function>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
You must call this function on parameters passed to your UDF if you need
|
|
|
|
them to handle binary data, as the binary encoding employed by PHP will
|
|
|
|
obscure the content and of the parameter in its natural, non-coded form.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
PHP does not perform this encode/decode operation automatically as it would
|
|
|
|
severely impact performance if it did.
|
|
|
|
</para>
|
2005-02-21 00:31:07 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2003-06-21 13:24:58 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>binary-safe max_length aggregation function example</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
$data = array(
|
|
|
|
'one',
|
|
|
|
'two',
|
|
|
|
'three',
|
2003-12-11 15:42:10 +00:00
|
|
|
'four',
|
|
|
|
'five',
|
2003-06-21 13:24:58 +00:00
|
|
|
'six',
|
|
|
|
'seven',
|
|
|
|
'eight',
|
2003-12-11 15:42:10 +00:00
|
|
|
'nine',
|
|
|
|
'ten',
|
2003-06-21 13:24:58 +00:00
|
|
|
);
|
|
|
|
$db = sqlite_open(':memory:');
|
|
|
|
sqlite_query($db, "CREATE TABLE strings(a)");
|
|
|
|
foreach ($data as $str) {
|
2003-07-06 04:43:08 +00:00
|
|
|
$str = sqlite_escape_string($str);
|
|
|
|
sqlite_query($db, "INSERT INTO strings VALUES ('$str')");
|
2003-06-21 13:24:58 +00:00
|
|
|
}
|
|
|
|
|
2004-01-15 12:43:50 +00:00
|
|
|
function max_len_step(&$context, $string)
|
|
|
|
{
|
2003-07-06 04:43:08 +00:00
|
|
|
$string = sqlite_udf_decode_binary($string);
|
|
|
|
if (strlen($string) > $context) {
|
|
|
|
$context = strlen($string);
|
|
|
|
}
|
2003-06-21 13:24:58 +00:00
|
|
|
}
|
|
|
|
|
2004-01-15 12:43:50 +00:00
|
|
|
function max_len_finalize(&$context)
|
|
|
|
{
|
2003-07-06 04:43:08 +00:00
|
|
|
return $context;
|
2003-06-21 13:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sqlite_create_aggregate($db, 'max_len', 'max_len_step', 'max_len_finalize');
|
|
|
|
|
|
|
|
var_dump(sqlite_array_query($db, 'SELECT max_len(a) from strings'));
|
|
|
|
|
2003-07-06 04:43:08 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2003-06-21 13:24:58 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2005-02-21 00:31:07 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2003-06-21 13:24:58 +00:00
|
|
|
<para>
|
2005-02-21 00:31:07 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>sqlite_udf_encode_binary</function></member>
|
|
|
|
<member><function>sqlite_create_function</function></member>
|
|
|
|
<member><function>sqlite_create_aggregate</function></member>
|
|
|
|
</simplelist>
|
2003-06-21 13:24:58 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2005-02-21 00:31:07 +00:00
|
|
|
|
2003-06-21 13:24:58 +00:00
|
|
|
<!-- 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
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../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
|
|
|
|
-->
|