← Back to team overview

drizzle-discuss team mailing list archive

PROPOSAL: Change to the Cursor interface


Hi all!

So, I've been doing some cleanups around the Cursor API, as has Brian.

I've modified the old Cursor::ha_write_row() and Cursor::write_row()
calls to follow Drizzle coding standards:

Cursor::ha_write_row() is now Cursor::insertRecord()
Cursor::write_row() is now Cursor::doInsertRecord()

Anyway, I'm proposing to change the API for the above calls, and

The existing API call is like so:

virtual int Cursor::doInsertRecord(unsigned char *new_row);

The call returns an integer that corresponds to an engine error code
(with 0 being "success").  The problem with this API, as briefly
outlined by Kostja in this MySQL internals mailing list post:

is that the return code does not indicate whether the call to
write_row() (doInsertRecord() in Drizzle) inserted a new row or
whether it replaced an existing row.

I propose changing the above Cursor::doInsertRecord() in the following way:

class Cursor
typedef std::pair<uint64_t, uint64_t> RecordChanges;
typedef std::pair<int, RecordChanges> InsertRecordResult;
/** public wrapper */
/** virtual private method */
virtual InsertRecordResult doInsertRecord(uint8_t *new_record);

The HA_EXTRA_WRITE_CAN_REPLACE flag can then be removed.  The engine
will construct a return tuple (an InsertRecordResult) containing the
error code, if any, the number of records inserted, and the number of
records replaced.  Usage in the kernel would be like so:

uint64_t inserted_rows= 0;
uint64_t replaced_rows= 0;

Cursor::InsertRecordResult result= cursor->insertRecord(table[0]);

if (result.first == 0) /* successful result */
  inserted_rows= result.second.first;
  replaced_rows= result.second.second;



Follow ups