9 function __construct( $data ) {
29 * This allows us to distinguish a blob from a normal string and an array of strings
34 function __construct( $data ) {
44 * Base for all database-specific classes representing information about database fields
55 * Name of table this field belongs to
67 * Whether this field can store NULL values
70 function isNullable();
74 * Result wrapper for grabbing data queried by someone else
77 class ResultWrapper
implements Iterator
{
78 var $db, $result, $pos = 0, $currentRow = null;
81 * Create a new result object from a result resource and a Database object
83 * @param DatabaseBase $database
84 * @param resource $result
86 function __construct( $database, $result ) {
87 $this->db
= $database;
89 if ( $result instanceof ResultWrapper
) {
90 $this->result
= $result->result
;
92 $this->result
= $result;
97 * Get the number of rows in a result object
102 return $this->db
->numRows( $this );
106 * Fetch the next row from the given result object, in object form.
107 * Fields can be retrieved with $row->fieldname, with fields acting like
111 * @throws DBUnexpectedError Thrown if the database returns an error
113 function fetchObject() {
114 return $this->db
->fetchObject( $this );
118 * Fetch the next row from the given result object, in associative array
119 * form. Fields are retrieved with $row['fieldname'].
122 * @throws DBUnexpectedError Thrown if the database returns an error
124 function fetchRow() {
125 return $this->db
->fetchRow( $this );
129 * Free a result object
132 $this->db
->freeResult( $this );
133 unset( $this->result
);
138 * Change the position of the cursor in a result object.
139 * See mysql_data_seek()
141 * @param $row integer
143 function seek( $row ) {
144 $this->db
->dataSeek( $this, $row );
147 /*********************
149 * Note that using these in combination with the non-iterator functions
150 * above may cause rows to be skipped or repeated.
154 if ( $this->numRows() ) {
155 $this->db
->dataSeek( $this, 0 );
158 $this->currentRow
= null;
165 if ( is_null( $this->currentRow
) ) {
168 return $this->currentRow
;
183 $this->currentRow
= $this->fetchObject();
184 return $this->currentRow
;
191 return $this->current() !== false;
196 * Overloads the relevant methods of the real ResultsWrapper so it
197 * doesn't go anywhere near an actual database.
199 class FakeResultWrapper
extends ResultWrapper
{
200 var $result = array();
201 var $db = null; // And it's going to stay that way :D
203 var $currentRow = null;
205 function __construct( $array ) {
206 $this->result
= $array;
213 return count( $this->result
);
216 function fetchRow() {
217 if ( $this->pos
< count( $this->result
) ) {
218 $this->currentRow
= $this->result
[$this->pos
];
220 $this->currentRow
= false;
223 return $this->currentRow
;
226 function seek( $row ) {
232 // Callers want to be able to access fields with $this->fieldName
233 function fetchObject() {
235 if ( $this->currentRow
) {
236 return (object)$this->currentRow
;
244 $this->currentRow
= null;
248 return $this->fetchObject();
253 * Used by DatabaseBase::buildLike() to represent characters that have special meaning in SQL LIKE clauses
254 * and thus need no escaping. Don't instantiate it manually, use DatabaseBase::anyChar() and anyString() instead.
260 * Store a string into a LikeMatch marker object.
264 public function __construct( $s ) {
269 * Return the original stored string.
273 public function toString() {
279 * An object representing a master or slave position in a replicated setup.
281 interface DBMasterPos
{