MediaWiki
REL1_23
|
00001 <?php 00028 class DBObject { 00029 public $mData; 00030 00031 function __construct( $data ) { 00032 $this->mData = $data; 00033 } 00034 00038 function isLOB() { 00039 return false; 00040 } 00041 00042 function data() { 00043 return $this->mData; 00044 } 00045 } 00046 00053 class Blob { 00055 protected $mData; 00056 00057 function __construct( $data ) { 00058 $this->mData = $data; 00059 } 00060 00061 function fetch() { 00062 return $this->mData; 00063 } 00064 } 00065 00070 interface Field { 00075 function name(); 00076 00081 function tableName(); 00082 00087 function type(); 00088 00093 function isNullable(); 00094 } 00095 00100 class ResultWrapper implements Iterator { 00102 public $result; 00103 00105 protected $db; 00106 00108 protected $pos = 0; 00109 00111 protected $currentRow = null; 00112 00119 function __construct( $database, $result ) { 00120 $this->db = $database; 00121 00122 if ( $result instanceof ResultWrapper ) { 00123 $this->result = $result->result; 00124 } else { 00125 $this->result = $result; 00126 } 00127 } 00128 00134 function numRows() { 00135 return $this->db->numRows( $this ); 00136 } 00137 00146 function fetchObject() { 00147 return $this->db->fetchObject( $this ); 00148 } 00149 00157 function fetchRow() { 00158 return $this->db->fetchRow( $this ); 00159 } 00160 00164 function free() { 00165 $this->db->freeResult( $this ); 00166 unset( $this->result ); 00167 unset( $this->db ); 00168 } 00169 00176 function seek( $row ) { 00177 $this->db->dataSeek( $this, $row ); 00178 } 00179 00180 /********************* 00181 * Iterator functions 00182 * Note that using these in combination with the non-iterator functions 00183 * above may cause rows to be skipped or repeated. 00184 */ 00185 00186 function rewind() { 00187 if ( $this->numRows() ) { 00188 $this->db->dataSeek( $this, 0 ); 00189 } 00190 $this->pos = 0; 00191 $this->currentRow = null; 00192 } 00193 00197 function current() { 00198 if ( is_null( $this->currentRow ) ) { 00199 $this->next(); 00200 } 00201 00202 return $this->currentRow; 00203 } 00204 00208 function key() { 00209 return $this->pos; 00210 } 00211 00215 function next() { 00216 $this->pos++; 00217 $this->currentRow = $this->fetchObject(); 00218 00219 return $this->currentRow; 00220 } 00221 00225 function valid() { 00226 return $this->current() !== false; 00227 } 00228 } 00229 00234 class FakeResultWrapper extends ResultWrapper { 00236 public $result = array(); 00237 00239 protected $db = null; 00240 00242 protected $pos = 0; 00243 00245 protected $currentRow = null; 00246 00247 function __construct( $array ) { 00248 $this->result = $array; 00249 } 00250 00254 function numRows() { 00255 return count( $this->result ); 00256 } 00257 00258 function fetchRow() { 00259 if ( $this->pos < count( $this->result ) ) { 00260 $this->currentRow = $this->result[$this->pos]; 00261 } else { 00262 $this->currentRow = false; 00263 } 00264 $this->pos++; 00265 if ( is_object( $this->currentRow ) ) { 00266 return get_object_vars( $this->currentRow ); 00267 } else { 00268 return $this->currentRow; 00269 } 00270 } 00271 00272 function seek( $row ) { 00273 $this->pos = $row; 00274 } 00275 00276 function free() { 00277 } 00278 00279 // Callers want to be able to access fields with $this->fieldName 00280 function fetchObject() { 00281 $this->fetchRow(); 00282 if ( $this->currentRow ) { 00283 return (object)$this->currentRow; 00284 } else { 00285 return false; 00286 } 00287 } 00288 00289 function rewind() { 00290 $this->pos = 0; 00291 $this->currentRow = null; 00292 } 00293 00294 function next() { 00295 return $this->fetchObject(); 00296 } 00297 } 00298 00304 class LikeMatch { 00306 private $str; 00307 00313 public function __construct( $s ) { 00314 $this->str = $s; 00315 } 00316 00322 public function toString() { 00323 return $this->str; 00324 } 00325 } 00326 00332 interface DBMasterPos { 00333 }