MediaWiki  REL1_24
DatabaseUtility.php
Go to the documentation of this file.
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 
00261     function fetchRow() {
00262         if ( $this->pos < count( $this->result ) ) {
00263             $this->currentRow = $this->result[$this->pos];
00264         } else {
00265             $this->currentRow = false;
00266         }
00267         $this->pos++;
00268         if ( is_object( $this->currentRow ) ) {
00269             return get_object_vars( $this->currentRow );
00270         } else {
00271             return $this->currentRow;
00272         }
00273     }
00274 
00275     function seek( $row ) {
00276         $this->pos = $row;
00277     }
00278 
00279     function free() {
00280     }
00281 
00286     function fetchObject() {
00287         $this->fetchRow();
00288         if ( $this->currentRow ) {
00289             return (object)$this->currentRow;
00290         } else {
00291             return false;
00292         }
00293     }
00294 
00295     function rewind() {
00296         $this->pos = 0;
00297         $this->currentRow = null;
00298     }
00299 
00303     function next() {
00304         return $this->fetchObject();
00305     }
00306 }
00307 
00313 class LikeMatch {
00315     private $str;
00316 
00322     public function __construct( $s ) {
00323         $this->str = $s;
00324     }
00325 
00331     public function toString() {
00332         return $this->str;
00333     }
00334 }
00335 
00341 interface DBMasterPos {
00342 }