ValueBuffer* UnqliteCursor::get_key(int key_len, pyunqlite::UserCallback* callback) { ValueBuffer* value = 0; int rc; if (callback) { rc = unqlite_kv_cursor_key_callback( this->_cursor, callback->get_unqlite_callback_function(), callback->get_unqlite_callback_data() ); } else { int nBytes = 0; unqlite_kv_cursor_key(this->_cursor, 0, &nBytes); // create the buffer value = new ValueBuffer(false, nBytes); if (!value) throw UnqliteException(UNQLITE_NOMEM); rc = unqlite_kv_cursor_key(this->_cursor, value->get_data(), &nBytes); } if (callback && (rc == UNQLITE_ABORT)) callback->process_exception(); else if (rc != UNQLITE_OK) throw UnqliteException(rc, this->_db); return value; }
ValueBuffer* UnqliteCursor::get_data( bool as_binary, sxi64 value_len, pyunqlite::UserCallback* callback, pyunqlite::ValueBuffer* direct_buffer ) { ValueBuffer* value = 0; // setup the buffer for retrieving data if (direct_buffer) { if (value_len < 0) value_len = direct_buffer->get_data_len(); else if (direct_buffer->get_data_len() < value_len) throw UnqliteException(UNQLITE_INVALID); value = new ValueBuffer(*direct_buffer); } else if (!callback) { // determine the size of the stored data if it is unknown if (value_len < 0) value_len = get_data_len(); // create a new buffer value = new ValueBuffer(as_binary, value_len); if (!value) throw UnqliteException(UNQLITE_NOMEM); } int rc; if (callback) { rc = unqlite_kv_cursor_data_callback( this->_cursor, callback->get_unqlite_callback_function(), callback->get_unqlite_callback_data() ); } else { rc = unqlite_kv_cursor_data(this->_cursor, value->get_data(), &value_len); } if (callback && (rc == UNQLITE_ABORT)) callback->process_exception(); else if (rc != UNQLITE_OK) throw UnqliteException(rc, this->_db); return value; }