Reading data
As we have learned in the previous chapter, an indexless table can be read using two access patterns—either sequential, with rnd_init()
and rnd_next()
methods, or a random one with position()
and rnd_pos()
methods. Let's start with the former:
int ha_html::rnd_next(unsigned char *buf) { fseek(fhtml, current_row_end, SEEK_SET); for (;;) {
This is one of the most complex methods in our storage engine. Let's analyze it line by line. We started by positioning the stream at the end of the last read row, and will be looking for the first non-deleted row (remember that a row starts with a<tr>
tag, while a deleted row starts with<!‑‑)
.
But first we save the offset of the row that we will read, as it may be needed for position()
, and check it against the end of data offset:
current_row_start= ftell(fhtml); if (current_row_start >= data_end) return HA_ERR_END_OF_FILE;
This check allows us to skip any processing and return an error at once if we have read all of the rows...