commit | author | age
|
95ebbc
|
1 |
<?php |
T |
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 |
|
|
47 |
/** |
|
48 |
* @package MDB2 |
|
49 |
* @category Database |
|
50 |
* @author Lukas Smith <smith@pooteeweet.org> |
|
51 |
*/ |
|
52 |
|
|
53 |
require_once 'MDB2.php'; |
|
54 |
|
|
55 |
/** |
|
56 |
* MDB2_LOB: user land stream wrapper implementation for LOB support |
|
57 |
* |
|
58 |
* @package MDB2 |
|
59 |
* @category Database |
|
60 |
* @author Lukas Smith <smith@pooteeweet.org> |
|
61 |
*/ |
|
62 |
class MDB2_LOB |
|
63 |
{ |
|
64 |
/** |
|
65 |
* contains the key to the global MDB2 instance array of the associated |
|
66 |
* MDB2 instance |
|
67 |
* |
|
68 |
* @var integer |
|
69 |
* @access protected |
|
70 |
*/ |
|
71 |
var $db_index; |
|
72 |
|
|
73 |
/** |
|
74 |
* contains the key to the global MDB2_LOB instance array of the associated |
|
75 |
* MDB2_LOB instance |
|
76 |
* |
|
77 |
* @var integer |
|
78 |
* @access protected |
|
79 |
*/ |
|
80 |
var $lob_index; |
|
81 |
|
|
82 |
// {{{ stream_open() |
|
83 |
|
|
84 |
/** |
|
85 |
* open stream |
|
86 |
* |
|
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 |
|
91 |
* |
|
92 |
* @return bool |
|
93 |
* @access public |
|
94 |
*/ |
|
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 |
|
|
119 |
/** |
|
120 |
* read stream |
|
121 |
* |
|
122 |
* @param int number of bytes to read |
|
123 |
* |
|
124 |
* @return string |
|
125 |
* @access public |
|
126 |
*/ |
|
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 |
|
|
146 |
/** |
|
147 |
* write stream, note implemented |
|
148 |
* |
|
149 |
* @param string data |
|
150 |
* |
|
151 |
* @return int |
|
152 |
* @access public |
|
153 |
*/ |
|
154 |
function stream_write($data) |
|
155 |
{ |
|
156 |
return 0; |
|
157 |
} |
|
158 |
// }}} |
|
159 |
|
|
160 |
// {{{ stream_tell() |
|
161 |
|
|
162 |
/** |
|
163 |
* return the current position |
|
164 |
* |
|
165 |
* @return int current position |
|
166 |
* @access public |
|
167 |
*/ |
|
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 |
|
|
179 |
/** |
|
180 |
* Check if stream reaches EOF |
|
181 |
* |
|
182 |
* @return bool |
|
183 |
* @access public |
|
184 |
*/ |
|
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 |
|
|
204 |
/** |
|
205 |
* Seek stream, not implemented |
|
206 |
* |
|
207 |
* @param int offset |
|
208 |
* @param int whence |
|
209 |
* |
|
210 |
* @return bool |
|
211 |
* @access public |
|
212 |
*/ |
|
213 |
function stream_seek($offset, $whence) |
|
214 |
{ |
|
215 |
return false; |
|
216 |
} |
|
217 |
// }}} |
|
218 |
|
|
219 |
// {{{ stream_stat() |
|
220 |
|
|
221 |
/** |
|
222 |
* return information about stream |
|
223 |
* |
|
224 |
* @access public |
|
225 |
*/ |
|
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 |
|
|
240 |
/** |
|
241 |
* close stream |
|
242 |
* |
|
243 |
* @access public |
|
244 |
*/ |
|
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")) { |
|
260 |
MDB2::raiseError(); |
|
261 |
return false; |
|
262 |
} |
|
263 |
|
|
264 |
?> |