MediaWiki
REL1_19
|
00001 <?php 00006 class DBObject { 00007 public $mData; 00008 00009 function __construct( $data ) { 00010 $this->mData = $data; 00011 } 00012 00016 function isLOB() { 00017 return false; 00018 } 00019 00020 function data() { 00021 return $this->mData; 00022 } 00023 } 00024 00031 class Blob { 00032 private $mData; 00033 00034 function __construct( $data ) { 00035 $this->mData = $data; 00036 } 00037 00038 function fetch() { 00039 return $this->mData; 00040 } 00041 } 00042 00047 interface Field { 00052 function name(); 00053 00058 function tableName(); 00059 00064 function type(); 00065 00070 function isNullable(); 00071 } 00072 00077 class ResultWrapper implements Iterator { 00078 var $db, $result, $pos = 0, $currentRow = null; 00079 00086 function __construct( $database, $result ) { 00087 $this->db = $database; 00088 00089 if ( $result instanceof ResultWrapper ) { 00090 $this->result = $result->result; 00091 } else { 00092 $this->result = $result; 00093 } 00094 } 00095 00101 function numRows() { 00102 return $this->db->numRows( $this ); 00103 } 00104 00113 function fetchObject() { 00114 return $this->db->fetchObject( $this ); 00115 } 00116 00124 function fetchRow() { 00125 return $this->db->fetchRow( $this ); 00126 } 00127 00131 function free() { 00132 $this->db->freeResult( $this ); 00133 unset( $this->result ); 00134 unset( $this->db ); 00135 } 00136 00143 function seek( $row ) { 00144 $this->db->dataSeek( $this, $row ); 00145 } 00146 00147 /********************* 00148 * Iterator functions 00149 * Note that using these in combination with the non-iterator functions 00150 * above may cause rows to be skipped or repeated. 00151 */ 00152 00153 function rewind() { 00154 if ( $this->numRows() ) { 00155 $this->db->dataSeek( $this, 0 ); 00156 } 00157 $this->pos = 0; 00158 $this->currentRow = null; 00159 } 00160 00164 function current() { 00165 if ( is_null( $this->currentRow ) ) { 00166 $this->next(); 00167 } 00168 return $this->currentRow; 00169 } 00170 00174 function key() { 00175 return $this->pos; 00176 } 00177 00181 function next() { 00182 $this->pos++; 00183 $this->currentRow = $this->fetchObject(); 00184 return $this->currentRow; 00185 } 00186 00190 function valid() { 00191 return $this->current() !== false; 00192 } 00193 } 00194 00199 class FakeResultWrapper extends ResultWrapper { 00200 var $result = array(); 00201 var $db = null; // And it's going to stay that way :D 00202 var $pos = 0; 00203 var $currentRow = null; 00204 00205 function __construct( $array ) { 00206 $this->result = $array; 00207 } 00208 00212 function numRows() { 00213 return count( $this->result ); 00214 } 00215 00216 function fetchRow() { 00217 if ( $this->pos < count( $this->result ) ) { 00218 $this->currentRow = $this->result[$this->pos]; 00219 } else { 00220 $this->currentRow = false; 00221 } 00222 $this->pos++; 00223 return $this->currentRow; 00224 } 00225 00226 function seek( $row ) { 00227 $this->pos = $row; 00228 } 00229 00230 function free() {} 00231 00232 // Callers want to be able to access fields with $this->fieldName 00233 function fetchObject() { 00234 $this->fetchRow(); 00235 if ( $this->currentRow ) { 00236 return (object)$this->currentRow; 00237 } else { 00238 return false; 00239 } 00240 } 00241 00242 function rewind() { 00243 $this->pos = 0; 00244 $this->currentRow = null; 00245 } 00246 00247 function next() { 00248 return $this->fetchObject(); 00249 } 00250 } 00251 00256 class LikeMatch { 00257 private $str; 00258 00264 public function __construct( $s ) { 00265 $this->str = $s; 00266 } 00267 00273 public function toString() { 00274 return $this->str; 00275 } 00276 } 00277 00281 interface DBMasterPos { 00282 } 00283