ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
LOB.php
Go to the documentation of this file.
1 <?php
2 // +----------------------------------------------------------------------+
3 // | PHP version 5 |
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. |
12 // | |
13 // | Redistribution and use in source and binary forms, with or without |
14 // | modification, are permitted provided that the following conditions |
15 // | are met: |
16 // | |
17 // | Redistributions of source code must retain the above copyright |
18 // | notice, this list of conditions and the following disclaimer. |
19 // | |
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. |
23 // | |
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. |
28 // | |
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 // +----------------------------------------------------------------------+
44 //
45 // $Id: LOB.php,v 1.34 2006/10/25 11:52:21 lsmith Exp $
46 
53 require_once 'MDB2.php';
54 
62 class MDB2_LOB
63 {
71  var $db_index;
72 
81 
82  // {{{ stream_open()
83 
95  function stream_open($path, $mode, $options, &$opened_path)
96  {
97  if (!preg_match('/^rb?\+?$/', $mode)) {
98  return false;
99  }
100  $url = parse_url($path);
101  if (empty($url['host'])) {
102  return false;
103  }
104  $this->db_index = (int)$url['host'];
105  if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
106  return false;
107  }
108  $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
109  $this->lob_index = (int)$url['user'];
110  if (!isset($db->datatype->lobs[$this->lob_index])) {
111  return false;
112  }
113  return true;
114  }
115  // }}}
116 
117  // {{{ stream_read()
118 
127  function stream_read($count)
128  {
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]);
132 
133  $data = $db->datatype->_readLOB($db->datatype->lobs[$this->lob_index], $count);
134  $length = strlen($data);
135  if ($length == 0) {
136  $db->datatype->lobs[$this->lob_index]['endOfLOB'] = true;
137  }
138  $db->datatype->lobs[$this->lob_index]['position'] += $length;
139  return $data;
140  }
141  }
142  // }}}
143 
144  // {{{ stream_write()
145 
154  function stream_write($data)
155  {
156  return 0;
157  }
158  // }}}
159 
160  // {{{ stream_tell()
161 
168  function stream_tell()
169  {
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'];
173  }
174  }
175  // }}}
176 
177  // {{{ stream_eof()
178 
185  function stream_eof()
186  {
187  if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
188  return true;
189  }
190 
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", "<")
195  ) {
196  return !$result;
197  }
198  return $result;
199  }
200  // }}}
201 
202  // {{{ stream_seek()
203 
213  function stream_seek($offset, $whence)
214  {
215  return false;
216  }
217  // }}}
218 
219  // {{{ stream_stat()
220 
226  function stream_stat()
227  {
228  if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
229  $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
230  return array(
231  'db_index' => $this->db_index,
232  'lob_index' => $this->lob_index,
233  );
234  }
235  }
236  // }}}
237 
238  // {{{ stream_close()
239 
245  function stream_close()
246  {
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]);
252  }
253  }
254  }
255  // }}}
256 }
257 
258 // register streams wrapper
259 if (!stream_wrapper_register("MDB2LOB", "MDB2_LOB")) {
261  return false;
262 }
263 
264 ?>