php-doc-en/reference/sqlite/functions/sqlite-udf-decode-binary.xml
2003-12-11 15:42:10 +00:00

99 lines
2.6 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.3 $ -->
<refentry id="function.sqlite-udf-decode-binary">
<refnamediv>
<refname>sqlite_udf_decode_binary</refname>
<refpurpose>Decode binary data passed as parameters to an UDF.</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<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>
<para>
<example>
<title>binary-safe max_length aggregation function example</title>
<programlisting role="php">
<![CDATA[
<?php
$data = array(
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine',
'ten',
);
$db = sqlite_open(':memory:');
sqlite_query($db, "CREATE TABLE strings(a)");
foreach ($data as $str) {
$str = sqlite_escape_string($str);
sqlite_query($db, "INSERT INTO strings VALUES ('$str')");
}
function max_len_step(&$context, $string) {
$string = sqlite_udf_decode_binary($string);
if (strlen($string) > $context) {
$context = strlen($string);
}
}
function max_len_finalize(&$context) {
return $context;
}
sqlite_create_aggregate($db, 'max_len', 'max_len_step', 'max_len_finalize');
var_dump(sqlite_array_query($db, 'SELECT max_len(a) from strings'));
?>
]]>
</programlisting>
</example>
</para>
<para>
See also <function>sqlite_udf_encode_binary</function>,
<function>sqlite_create_function</function> and
<function>sqlite_create_aggregate</function>.
</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
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
-->