2 // +----------------------------------------------------------------------+
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
6 // | Stig. S. Bakken, Lukas Smith |
7 // | All rights reserved. |
8 // +----------------------------------------------------------------------+
9 // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
10 // | API as well as database abstraction for PHP applications. |
11 // | This LICENSE is in the BSD license style. |
13 // | Redistribution and use in source and binary forms, with or without |
14 // | modification, are permitted provided that the following conditions |
17 // | Redistributions of source code must retain the above copyright |
18 // | notice, this list of conditions and the following disclaimer. |
20 // | Redistributions in binary form must reproduce the above copyright |
21 // | notice, this list of conditions and the following disclaimer in the |
22 // | documentation and/or other materials provided with the distribution. |
24 // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
25 // | Lukas Smith nor the names of his contributors may be used to endorse |
26 // | or promote products derived from this software without specific prior|
27 // | written permission. |
29 // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
30 // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
31 // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
32 // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
33 // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
34 // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
35 // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
36 // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
37 // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
38 // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
39 // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
40 // | POSSIBILITY OF SUCH DAMAGE. |
41 // +----------------------------------------------------------------------+
42 // | Author: Lukas Smith <smith@pooteeweet.org> |
43 // +----------------------------------------------------------------------+
45 // $Id: LOB.php 222350 2006-10-25 11:52:21Z lsmith $
50 * @author Lukas Smith <smith@pooteeweet.org>
53 require_once 'MDB2.php';
56 * MDB2_LOB: user land stream wrapper implementation for LOB support
60 * @author Lukas Smith <smith@pooteeweet.org>
65 * contains the key to the global MDB2 instance array of the associated
74 * contains the key to the global MDB2_LOB instance array of the associated
87 * @param string specifies the URL that was passed to fopen()
88 * @param string the mode used to open the file
89 * @param int holds additional flags set by the streams API
90 * @param string not used
95 function stream_open($path, $mode, $options, &$opened_path)
97 if (!preg_match('/^rb?\+?$/', $mode)) {
100 $url = parse_url($path);
101 if (empty($url['host'])) {
104 $this->db_index = (int)$url['host'];
105 if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
108 $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
109 $this->lob_index = (int)$url['user'];
110 if (!isset($db->datatype->lobs[$this->lob_index])) {
122 * @param int number of bytes to read
127 function stream_read($count)
129 if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
130 $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
131 $db->datatype->_retrieveLOB($db->datatype->lobs[$this->lob_index]);
133 $data = $db->datatype->_readLOB($db->datatype->lobs[$this->lob_index], $count);
134 $length = strlen($data);
136 $db->datatype->lobs[$this->lob_index]['endOfLOB'] = true;
138 $db->datatype->lobs[$this->lob_index]['position'] += $length;
144 // {{{ stream_write()
147 * write stream, note implemented
154 function stream_write($data)
163 * return the current position
165 * @return int current position
168 function stream_tell()
170 if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
171 $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
172 return $db->datatype->lobs[$this->lob_index]['position'];
180 * Check if stream reaches EOF
185 function stream_eof()
187 if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
191 $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
192 $result = $db->datatype->_endOfLOB($db->datatype->lobs[$this->lob_index]);
193 if (version_compare(phpversion(), "5.0", ">=")
194 && version_compare(phpversion(), "5.1", "<")
205 * Seek stream, not implemented
213 function stream_seek($offset, $whence)
222 * return information about stream
226 function stream_stat()
228 if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
229 $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
231 'db_index' => $this->db_index,
232 'lob_index' => $this->lob_index,
238 // {{{ stream_close()
245 function stream_close()
247 if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
248 $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
249 if (isset($db->datatype->lobs[$this->lob_index])) {
250 $db->datatype->_destroyLOB($db->datatype->lobs[$this->lob_index]);
251 unset($db->datatype->lobs[$this->lob_index]);
258 // register streams wrapper
259 if (!stream_wrapper_register("MDB2LOB", "MDB2_LOB")) {