php-doc-en/reference/sqlite3/sqlite3/openblob.xml
Christoph Michael Becker b95d28e6ec Fix return types
Functions which return false on failure should state that in their
signature as well.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@351135 c90b9560-bf6c-de11-be94-00142212c4b1
2020-11-02 15:52:35 +00:00

194 lines
5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="sqlite3.openblob" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>SQLite3::openBlob</refname>
<refpurpose>Opens a stream resource to read a BLOB</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier> <type class="union"><type>resource</type><type>false</type></type><methodname>SQLite3::openBlob</methodname>
<methodparam><type>string</type><parameter>table</parameter></methodparam>
<methodparam><type>string</type><parameter>column</parameter></methodparam>
<methodparam><type>int</type><parameter>rowid</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>dbname</parameter><initializer>"main"</initializer></methodparam>
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>SQLITE3_OPEN_READONLY</initializer></methodparam>
</methodsynopsis>
<para>
Opens a stream resource to read or write a BLOB, which would be selected by:
</para>
<para>
SELECT <parameter>column</parameter> FROM <parameter>dbname</parameter>.<parameter>table</parameter> WHERE rowid = <parameter>rowid</parameter>
</para>
<note>
<simpara>
It is not possible to change the size of a BLOB by writing to the stream.
Instead, an UPDATE statement has to be executed, possibly using SQLite's
zeroblob() function to set the desired BLOB size.
</simpara>
</note>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>table</parameter></term>
<listitem>
<para>
The table name.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>column</parameter></term>
<listitem>
<para>
The column name.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>rowid</parameter></term>
<listitem>
<para>
The row ID.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>dbname</parameter></term>
<listitem>
<para>
The symbolic name of the DB
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>flags</parameter></term>
<listitem>
<para>
Either <constant>SQLITE3_OPEN_READONLY</constant> or
<constant>SQLITE3_OPEN_READWRITE</constant> to open the stream
for reading only, or for reading and writing, respectively.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns a stream resource, &return.falseforfailure;.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>7.2.0</entry>
<entry>
The <parameter>flags</parameter> parameter has been added, allowing to
write BLOBs; formerly only reading was supported.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>SQLite3::openBlob</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$conn = new SQLite3(':memory:');
$conn->exec('CREATE TABLE test (text text)');
$conn->exec("INSERT INTO test VALUES ('Lorem ipsum')");
$stream = $conn->openBlob('test', 'text', 1);
echo stream_get_contents($stream);
fclose($stream); // mandatory, otherwise the next line would fail
$conn->close();
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Lorem ipsum
]]>
</screen>
</example>
</para>
<para>
<example>
<title>Incrementally writing a BLOB</title>
<programlisting role="php">
<![CDATA[
<?php
$conn = new SQLite3(':memory:');
$conn->exec('CREATE TABLE test (text text)');
$conn->exec("INSERT INTO test VALUES (zeroblob(36))");
$stream = $conn->openBlob('test', 'text', 1, 'main', SQLITE3_OPEN_READWRITE);
for ($i = 0; $i < 3; $i++) {
fwrite($stream, "Lorem ipsum\n");
}
fclose($stream);
echo $conn->querySingle("SELECT text FROM test");
$conn->close();
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Lorem ipsum
Lorem ipsum
Lorem ipsum
]]>
</screen>
</example>
</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
-->