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;
159 if ( is_null( $this->currentRow
) ) {
162 return $this->currentRow
;
171 $this->currentRow
= $this->fetchObject();
172 return $this->currentRow
;
176 return $this->current() !== false;
181 * Overloads the relevant methods of the real ResultsWrapper so it
182 * doesn't go anywhere near an actual database.
184 class FakeResultWrapper
extends ResultWrapper
{
185 var $result = array();
186 var $db = null; // And it's going to stay that way :D
188 var $currentRow = null;
190 function __construct( $array ) {
191 $this->result
= $array;
195 return count( $this->result
);
198 function fetchRow() {
199 if ( $this->pos
< count( $this->result
) ) {
200 $this->currentRow
= $this->result
[$this->pos
];
202 $this->currentRow
= false;
205 return $this->currentRow
;
208 function seek( $row ) {
214 // Callers want to be able to access fields with $this->fieldName
215 function fetchObject() {
217 if ( $this->currentRow
) {
218 return (object)$this->currentRow
;
226 $this->currentRow
= null;
230 return $this->fetchObject();
235 * Used by DatabaseBase::buildLike() to represent characters that have special meaning in SQL LIKE clauses
236 * and thus need no escaping. Don't instantiate it manually, use DatabaseBase::anyChar() and anyString() instead.
242 * Store a string into a LikeMatch marker object.
246 public function __construct( $s ) {
251 * Return the original stored string.
255 public function toString() {