Automatically exported from code.google.com/p/planningalerts
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

246 rindas
7.7 KiB

  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.33 2006/05/31 14:38:06 lsmith Exp $
  46. /**
  47. * @package MDB2
  48. * @category Database
  49. * @author Lukas Smith <smith@pooteeweet.org>
  50. */
  51. require_once 'MDB2.php';
  52. /**
  53. * MDB2_LOB: user land stream wrapper implementation for LOB support
  54. *
  55. * @package MDB2
  56. * @category Database
  57. * @author Lukas Smith <smith@pooteeweet.org>
  58. */
  59. class MDB2_LOB
  60. {
  61. /**
  62. * contains the key to the global MDB2 instance array of the associated
  63. * MDB2 instance
  64. *
  65. * @var integer
  66. * @access protected
  67. */
  68. var $db_index;
  69. /**
  70. * contains the key to the global MDB2_LOB instance array of the associated
  71. * MDB2_LOB instance
  72. *
  73. * @var integer
  74. * @access protected
  75. */
  76. var $lob_index;
  77. // {{{ stream_open()
  78. /**
  79. * open stream
  80. *
  81. * @param string specifies the URL that was passed to fopen()
  82. * @param string the mode used to open the file
  83. * @param int holds additional flags set by the streams API
  84. * @param string not used
  85. *
  86. * @return bool
  87. * @access public
  88. */
  89. function stream_open($path, $mode, $options, &$opened_path)
  90. {
  91. if (!preg_match('/^rb?\+?$/', $mode)) {
  92. return false;
  93. }
  94. $url = parse_url($path);
  95. if (empty($url['host'])) {
  96. return false;
  97. }
  98. $this->db_index = (int)$url['host'];
  99. if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
  100. return false;
  101. }
  102. $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
  103. $this->lob_index = (int)$url['user'];
  104. if (!isset($db->datatype->lobs[$this->lob_index])) {
  105. return false;
  106. }
  107. return true;
  108. }
  109. // }}}
  110. // {{{ stream_read()
  111. /**
  112. * read stream
  113. *
  114. * @param int number of bytes to read
  115. *
  116. * @return string
  117. * @access public
  118. */
  119. function stream_read($count)
  120. {
  121. if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
  122. $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
  123. $db->datatype->_retrieveLOB($db->datatype->lobs[$this->lob_index]);
  124. $data = $db->datatype->_readLOB($db->datatype->lobs[$this->lob_index], $count);
  125. $length = strlen($data);
  126. if ($length == 0) {
  127. $db->datatype->lobs[$this->lob_index]['endOfLOB'] = true;
  128. }
  129. $db->datatype->lobs[$this->lob_index]['position'] += $length;
  130. return $data;
  131. }
  132. }
  133. // }}}
  134. // {{{ stream_write()
  135. /**
  136. * write stream, note implemented
  137. *
  138. * @param string data
  139. *
  140. * @return int
  141. * @access public
  142. */
  143. function stream_write($data)
  144. {
  145. return 0;
  146. }
  147. // }}}
  148. // {{{ stream_tell()
  149. /**
  150. * return the current position
  151. *
  152. * @return int current position
  153. * @access public
  154. */
  155. function stream_tell()
  156. {
  157. if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
  158. $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
  159. return $db->datatype->lobs[$this->lob_index]['position'];
  160. }
  161. }
  162. // }}}
  163. // {{{ stream_eof()
  164. /**
  165. * Check if stream reaches EOF
  166. *
  167. * @return bool
  168. * @access public
  169. */
  170. function stream_eof()
  171. {
  172. if (!isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
  173. return true;
  174. }
  175. $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
  176. $result = $db->datatype->_endOfLOB($db->datatype->lobs[$this->lob_index]);
  177. if (version_compare(phpversion(), "5.0", ">=")
  178. && version_compare(phpversion(), "5.1", "<")
  179. ) {
  180. return !$result;
  181. }
  182. return $result;
  183. }
  184. // }}}
  185. // {{{ stream_seek()
  186. /**
  187. * Seek stream, not implemented
  188. *
  189. * @param int offset
  190. * @param int whence
  191. *
  192. * @return bool
  193. * @access public
  194. */
  195. function stream_seek($offset, $whence)
  196. {
  197. return false;
  198. }
  199. // }}}
  200. // {{{ stream_close()
  201. /**
  202. * close stream
  203. *
  204. * @access public
  205. */
  206. function stream_close()
  207. {
  208. if (isset($GLOBALS['_MDB2_databases'][$this->db_index])) {
  209. $db =& $GLOBALS['_MDB2_databases'][$this->db_index];
  210. if (isset($db->datatype->lobs[$this->lob_index])) {
  211. $db->datatype->_destroyLOB($db->datatype->lobs[$this->lob_index]);
  212. unset($db->datatype->lobs[$this->lob_index]);
  213. }
  214. }
  215. }
  216. // }}}
  217. }
  218. // register streams wrapper
  219. if (!stream_wrapper_register("MDB2LOB", "MDB2_LOB")) {
  220. MDB2::raiseError();
  221. return false;
  222. }
  223. ?>