MediaWiki
REL1_22
|
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 { 00054 private $mData; 00055 00056 function __construct( $data ) { 00057 $this->mData = $data; 00058 } 00059 00060 function fetch() { 00061 return $this->mData; 00062 } 00063 } 00064 00069 interface Field { 00074 function name(); 00075 00080 function tableName(); 00081 00086 function type(); 00087 00092 function isNullable(); 00093 } 00094 00099 class ResultWrapper implements Iterator { 00100 var $db, $result, $pos = 0, $currentRow = null; 00101 00108 function __construct( $database, $result ) { 00109 $this->db = $database; 00110 00111 if ( $result instanceof ResultWrapper ) { 00112 $this->result = $result->result; 00113 } else { 00114 $this->result = $result; 00115 } 00116 } 00117 00123 function numRows() { 00124 return $this->db->numRows( $this ); 00125 } 00126 00135 function fetchObject() { 00136 return $this->db->fetchObject( $this ); 00137 } 00138 00146 function fetchRow() { 00147 return $this->db->fetchRow( $this ); 00148 } 00149 00153 function free() { 00154 $this->db->freeResult( $this ); 00155 unset( $this->result ); 00156 unset( $this->db ); 00157 } 00158 00165 function seek( $row ) { 00166 $this->db->dataSeek( $this, $row ); 00167 } 00168 00169 /********************* 00170 * Iterator functions 00171 * Note that using these in combination with the non-iterator functions 00172 * above may cause rows to be skipped or repeated. 00173 */ 00174 00175 function rewind() { 00176 if ( $this->numRows() ) { 00177 $this->db->dataSeek( $this, 0 ); 00178 } 00179 $this->pos = 0; 00180 $this->currentRow = null; 00181 } 00182 00186 function current() { 00187 if ( is_null( $this->currentRow ) ) { 00188 $this->next(); 00189 } 00190 return $this->currentRow; 00191 } 00192 00196 function key() { 00197 return $this->pos; 00198 } 00199 00203 function next() { 00204 $this->pos++; 00205 $this->currentRow = $this->fetchObject(); 00206 return $this->currentRow; 00207 } 00208 00212 function valid() { 00213 return $this->current() !== false; 00214 } 00215 } 00216 00221 class FakeResultWrapper extends ResultWrapper { 00222 var $result = array(); 00223 var $db = null; // And it's going to stay that way :D 00224 var $pos = 0; 00225 var $currentRow = null; 00226 00227 function __construct( $array ) { 00228 $this->result = $array; 00229 } 00230 00234 function numRows() { 00235 return count( $this->result ); 00236 } 00237 00238 function fetchRow() { 00239 if ( $this->pos < count( $this->result ) ) { 00240 $this->currentRow = $this->result[$this->pos]; 00241 } else { 00242 $this->currentRow = false; 00243 } 00244 $this->pos++; 00245 if ( is_object( $this->currentRow ) ) { 00246 return get_object_vars( $this->currentRow ); 00247 } else { 00248 return $this->currentRow; 00249 } 00250 } 00251 00252 function seek( $row ) { 00253 $this->pos = $row; 00254 } 00255 00256 function free() { 00257 } 00258 00259 // Callers want to be able to access fields with $this->fieldName 00260 function fetchObject() { 00261 $this->fetchRow(); 00262 if ( $this->currentRow ) { 00263 return (object)$this->currentRow; 00264 } else { 00265 return false; 00266 } 00267 } 00268 00269 function rewind() { 00270 $this->pos = 0; 00271 $this->currentRow = null; 00272 } 00273 00274 function next() { 00275 return $this->fetchObject(); 00276 } 00277 } 00278 00283 class LikeMatch { 00284 private $str; 00285 00291 public function __construct( $s ) { 00292 $this->str = $s; 00293 } 00294 00300 public function toString() { 00301 return $this->str; 00302 } 00303 } 00304 00308 interface DBMasterPos { 00309 }