cursor: add MVCCScanCursorPosition

This commit is contained in:
Piotr Sarna
2023-05-11 14:11:10 +02:00
parent 582bf14934
commit d5eec5d528
3 changed files with 18 additions and 2 deletions

View File

@@ -39,6 +39,8 @@ MVCCError MVCCScanCursorRead(MVCCScanCursorRef cursor, uint8_t **value_ptr, int6
int MVCCScanCursorNext(MVCCScanCursorRef cursor);
uint64_t MVCCScanCursorPosition(MVCCScanCursorRef cursor);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

View File

@@ -200,7 +200,7 @@ pub unsafe extern "C" fn MVCCScanCursorRead(
// TODO: deduplicate with MVCCDatabaseRead()
match runtime.block_on(async move {
let maybe_row = cursor.current().await?;
let maybe_row = cursor.current_row().await?;
match maybe_row {
Some(row) => {
tracing::debug!("Found row {row:?}");
@@ -243,3 +243,10 @@ pub unsafe extern "C" fn MVCCScanCursorNext(cursor: MVCCScanCursorRef) -> std::f
0
}
}
#[no_mangle]
pub unsafe extern "C" fn MVCCScanCursorPosition(cursor: MVCCScanCursorRef) -> u64 {
let cursor_ctx = unsafe { &mut *cursor.ptr };
let cursor = &mut cursor_ctx.cursor;
cursor.current_row_id().unwrap_or(0)
}

View File

@@ -36,7 +36,14 @@ impl<
})
}
pub async fn current(&self) -> Result<Option<Row>> {
pub fn current_row_id(&self) -> Option<u64> {
if self.index >= self.row_ids.len() {
return None;
}
Some(self.row_ids[self.index])
}
pub async fn current_row(&self) -> Result<Option<Row>> {
if self.index >= self.row_ids.len() {
return Ok(None);
}