📄 function.sqlite-udf-decode-binary.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Decode binary data passed as parameters to an UDF</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-single-query.html">sqlite_single_query</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-udf-encode-binary.html">sqlite_udf_encode_binary</a></div> <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.sqlite-udf-decode-binary" class="refentry"> <div class="refnamediv"> <h1 class="refname">sqlite_udf_decode_binary</h1> <p class="verinfo">(PHP 5, PECL sqlite:1.0-1.0.3)</p><p class="refpurpose"><span class="refname">sqlite_udf_decode_binary</span> — <span class="dc-title">Decode binary data passed as parameters to an UDF</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><b><b>sqlite_udf_decode_binary</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$data</tt></span> )</div> <p class="para rdfs-comment"> Decodes binary data passed as parameters to a <acronym title="User Defined Functions">UDF</acronym>. </p> <p class="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. </p> <p class="para"> PHP does not perform this encode/decode operation automatically as it would severely impact performance if it did. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">data</tt></i></span> <dd> <p class="para"> The encoded data that will be decoded, data that was applied by either <a href="function.sqlite-udf-encode-binary.html" class="function">sqlite_udf_encode_binary()</a> or <a href="function.sqlite-escape-string.html" class="function">sqlite_escape_string()</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The decoded <a href="language.types.string.html" class="type string">string</a>. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 binary-safe max_length aggregation function example</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$data </span><span style="color: #007700">= array(<br /> </span><span style="color: #DD0000">'one'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'two'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'three'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'four'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'five'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'six'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'seven'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'eight'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'nine'</span><span style="color: #007700">,<br /> </span><span style="color: #DD0000">'ten'</span><span style="color: #007700">,<br /> );<br /></span><span style="color: #0000BB">$db </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_open</span><span style="color: #007700">(</span><span style="color: #DD0000">':memory:'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">sqlite_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #DD0000">"CREATE TABLE strings(a)"</span><span style="color: #007700">);<br />foreach (</span><span style="color: #0000BB">$data </span><span style="color: #007700">as </span><span style="color: #0000BB">$str</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$str </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_escape_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">sqlite_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #DD0000">"INSERT INTO strings VALUES ('$str')"</span><span style="color: #007700">);<br />}<br /><br />function </span><span style="color: #0000BB">max_len_step</span><span style="color: #007700">(&</span><span style="color: #0000BB">$context</span><span style="color: #007700">, </span><span style="color: #0000BB">$string</span><span style="color: #007700">) <br />{<br /> </span><span style="color: #0000BB">$string </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_udf_decode_binary</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">);<br /> if (</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">) > </span><span style="color: #0000BB">$context</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$context </span><span style="color: #007700">= </span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$string</span><span style="color: #007700">);<br /> }<br />}<br /><br />function </span><span style="color: #0000BB">max_len_finalize</span><span style="color: #007700">(&</span><span style="color: #0000BB">$context</span><span style="color: #007700">) <br />{<br /> return </span><span style="color: #0000BB">$context</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">sqlite_create_aggregate</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #DD0000">'max_len'</span><span style="color: #007700">, </span><span style="color: #DD0000">'max_len_step'</span><span style="color: #007700">, </span><span style="color: #DD0000">'max_len_finalize'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">sqlite_array_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">, </span><span style="color: #DD0000">'SELECT max_len(a) from strings'</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.sqlite-udf-encode-binary.html" class="function" rel="rdfs-seeAlso">sqlite_udf_encode_binary()</a></li> <li class="member"><a href="function.sqlite-create-function.html" class="function" rel="rdfs-seeAlso">sqlite_create_function()</a></li> <li class="member"><a href="function.sqlite-create-aggregate.html" class="function" rel="rdfs-seeAlso">sqlite_create_aggregate()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-single-query.html">sqlite_single_query</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-udf-encode-binary.html">sqlite_udf_encode_binary</a></div> <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -