9 function __construct( $data ) {
26 * This allows us to distinguish a blob from a normal string and an array of strings
31 function __construct( $data ) {
41 * Base for all database-specific classes representing information about database fields
52 * Name of table this field belongs to
64 * Whether this field can store NULL values
67 function isNullable();
71 * Result wrapper for grabbing data queried by someone else
74 class ResultWrapper
implements Iterator
{
75 var $db, $result, $pos = 0, $currentRow = null;
78 * Create a new result object from a result resource and a Database object
80 * @param DatabaseBase $database
81 * @param resource $result
83 function __construct( $database, $result ) {
84 $this->db
= $database;
86 if ( $result instanceof ResultWrapper
) {
87 $this->result
= $result->result
;
89 $this->result
= $result;
94 * Get the number of rows in a result object
99 return $this->db
->numRows( $this );
103 * Fetch the next row from the given result object, in object form.
104 * Fields can be retrieved with $row->fieldname, with fields acting like
108 * @throws DBUnexpectedError Thrown if the database returns an error
110 function fetchObject() {
111 return $this->db
->fetchObject( $this );
115 * Fetch the next row from the given result object, in associative array
116 * form. Fields are retrieved with $row['fieldname'].
119 * @throws DBUnexpectedError Thrown if the database returns an error
121 function fetchRow() {
122 return $this->db
->fetchRow( $this );
126 * Free a result object
129 $this->db
->freeResult( $this );
130 unset( $this->result
);
135 * Change the position of the cursor in a result object.
136 * See mysql_data_seek()
138 * @param $row integer
140 function seek( $row ) {
141 $this->db
->dataSeek( $this, $row );
144 /*********************
146 * Note that using these in combination with the non-iterator functions
147 * above may cause rows to be skipped or repeated.
151 if ( $this->numRows() ) {
152 $this->db
->dataSeek( $this, 0 );
155 $this->currentRow
= null;
162 if ( is_null( $this->currentRow
) ) {
165 return $this->currentRow
;
180 $this->currentRow
= $this->fetchObject();
181 return $this->currentRow
;
188 return $this->current() !== false;
193 * Overloads the relevant methods of the real ResultsWrapper so it
194 * doesn't go anywhere near an actual database.
196 class FakeResultWrapper
extends ResultWrapper
{
197 var $result = array();
198 var $db = null; // And it's going to stay that way :D
200 var $currentRow = null;
202 function __construct( $array ) {
203 $this->result
= $array;
210 return count( $this->result
);
213 function fetchRow() {
214 if ( $this->pos
< count( $this->result
) ) {
215 $this->currentRow
= $this->result
[$this->pos
];
217 $this->currentRow
= false;
220 return $this->currentRow
;
223 function seek( $row ) {
229 // Callers want to be able to access fields with $this->fieldName
230 function fetchObject() {
232 if ( $this->currentRow
) {
233 return (object)$this->currentRow
;
241 $this->currentRow
= null;
245 return $this->fetchObject();
250 * Used by DatabaseBase::buildLike() to represent characters that have special meaning in SQL LIKE clauses
251 * and thus need no escaping. Don't instantiate it manually, use DatabaseBase::anyChar() and anyString() instead.
257 * Store a string into a LikeMatch marker object.
261 public function __construct( $s ) {
266 * Return the original stored string.
270 public function toString() {
276 * An object representing a master or slave position in a replicated setup.
278 interface DBMasterPos
{