Pages

MYSQL_ROW in MYSQL_RES

We don't have big expectations for our toy ResultSet class. We would just like that, when we perform a SELECT on a Connection, the could go through the ResultSet we get back, printing to the output console (and maybe other output streams) any row in it.

Quite a reasonable requirement.

But before working on it we should understand better how a result set is organized in MySQL Connector/C.

Basically, we can think to MYSQL_RES as a container of rows. Well, it is much more than this, but currently we are just interested in this aspect of its personality. The rows are stored in its data section as array of MYSQL_ROW.

A MYSQL_ROW is an array of byte arrays. We could usually think to a single item in a MYSQL_ROW as a c-strings, but we should be aware that it could contain internal null-bytes, when used to represent binary data.

To get the next MYSQL_ROW in a MYSQL_RES we can use the mysql_fetch_row() function. Besides we can access directly a specific position using mysql_row_seek(). This two functions are enough for us, since we want to provide just a way to move forward in the resultset and reset it to the beginning position.

So, what we are going to do in the next couple of posts would be to design a class Row that is going to represent a single row, possibly a dummy one, of a result set; and improve our ResultSet class to give the user a way to iterate on it.

No comments:

Post a Comment