thomascube
2006-03-04 f5121b5639992fc9e51fd551bac2254429b638fa
commit | author | age
d13c36 1 <?php
S 2 // +----------------------------------------------------------------------+
3 // | PHP version 5                                                        |
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) 1998-2004 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$
46
47 /**
48  * @package  MDB2
49  * @category Database
50  * @author   Lukas Smith <smith@pooteeweet.org>
51  */
52
53 require_once 'MDB2.php';
54
55 class MDB2_LOB
56 {
57     var $db_index;
58     var $lob_index;
59     var $lob;
60
61     function stream_open($path, $mode, $options, &$opened_path)
62     {
63         if (!preg_match('/^rb?\+?$/', $mode)) {
64             return false;
65         }
66         $url = parse_url($path);
67         if (!array_key_exists('host', $url) && !array_key_exists('user', $url)) {
68             return false;
69         }
70         $this->db_index = $url['host'];
71         if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
72             return false;
73         }
74         $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
75         $this->lob_index = $url['user'];
76         if (!isset($db->datatype->lobs[$this->lob_index])) {
77             return false;
78         }
79         $this->lob =& $db->datatype->lobs[$this->lob_index];
80         $db->datatype->_retrieveLOB($this->lob);
81         return true;
82     }
83
84     function stream_read($count)
85     {
86         if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
87             $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
88
89             $data = $db->datatype->_readLOB($this->lob, $count);
90             $length = strlen($data);
91             if ($length == 0) {
92                 $this->lob['endOfLOB'] = true;
93             }
94             $this->lob['position'] += $length;
95             return $data;
96         }
97    }
98
99     function stream_write($data)
100     {
101         return 0;
102     }
103
104     function stream_tell()
105     {
106         return $this->lob['position'];
107     }
108
109     function stream_eof()
110     {
111         if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
112             return true;
113         }
114         $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
115         $result = $db->datatype->_endOfLOB($this->lob);
116         if (version_compare(phpversion(), "5.0", ">=")
117             && version_compare(phpversion(), "5.1", "<")
118         ) {
119             return !$result;
120         }
121         return $result;
122     }
123
124     function stream_seek($offset, $whence)
125     {
126         return false;
127     }
128
129     function stream_close()
130     {
131         if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
132             $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
133             if (isset($db->datatype->lobs[$this->lob_index])) {
134                 $db->datatype->_destroyLOB($this->lob_index);
135                 unset($db->datatype->lobs[$this->lob_index]);
136             }
137         }
138     }
139 }
140
141 if (!stream_wrapper_register("MDB2LOB", "MDB2_LOB")) {
142     MDB2::raiseError();
143     return false;
144 }
145
146 ?>