-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 'Store cursor types in program state and remove trait Cursor' f…
…rom Jussi Saurio I was planning on starting work on index insertion, but realized we need to know whether our cursor refers to a table or an index etc., so it resulted in this refactoring work. - `cursor_ref` now contains what _type_ of cursor it is (table, index, pseudo, sorter) - `program.cursors` is now `program.btree_table_cursors`, `program.btree_index_cursors` etc and they are unboxed because dynamic dispatch is no longer necessary - Cursor trait removed -- 95% of the shit was btree specific anyway, so I just moved them to `BTreeCursor`. In certain instructions in the VDBE we expect a btree cursor and in others we expect a pseudo/sorter etc, lets make that explicit. - I also removed `BTreeCursor::get_new_rowid()` specific tests that required macros to generate a mock implementation of the `Cursor` trait -- main reason is I couldn't figure out how to reimplement this without the trait, and the second reason is that I don't think we really need those tests, AND the proc macro is constantly failing in my editor as well and screwing up `rust-analyzer` Closes #655
- Loading branch information
Showing
14 changed files
with
484 additions
and
707 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,19 @@ | ||
use crate::{ | ||
types::{SeekKey, SeekOp}, | ||
Result, | ||
}; | ||
use std::cell::{Ref, RefCell}; | ||
|
||
use crate::types::{Cursor, CursorResult, OwnedRecord, OwnedValue}; | ||
use crate::types::OwnedRecord; | ||
|
||
pub struct PseudoCursor { | ||
current: RefCell<Option<OwnedRecord>>, | ||
current: Option<OwnedRecord>, | ||
} | ||
|
||
impl PseudoCursor { | ||
pub fn new() -> Self { | ||
Self { | ||
current: RefCell::new(None), | ||
} | ||
} | ||
} | ||
|
||
impl Cursor for PseudoCursor { | ||
fn is_empty(&self) -> bool { | ||
self.current.borrow().is_none() | ||
} | ||
|
||
fn root_page(&self) -> usize { | ||
unreachable!() | ||
} | ||
|
||
fn rewind(&mut self) -> Result<CursorResult<()>> { | ||
*self.current.borrow_mut() = None; | ||
Ok(CursorResult::Ok(())) | ||
} | ||
|
||
fn next(&mut self) -> Result<CursorResult<()>> { | ||
*self.current.borrow_mut() = None; | ||
Ok(CursorResult::Ok(())) | ||
} | ||
|
||
fn wait_for_completion(&mut self) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn rowid(&self) -> Result<Option<u64>> { | ||
let x = self | ||
.current | ||
.borrow() | ||
.as_ref() | ||
.map(|record| match record.values[0] { | ||
OwnedValue::Integer(rowid) => rowid as u64, | ||
ref ov => { | ||
panic!("Expected integer value, got {:?}", ov); | ||
} | ||
}); | ||
Ok(x) | ||
} | ||
|
||
fn seek(&mut self, _: SeekKey<'_>, _: SeekOp) -> Result<CursorResult<bool>> { | ||
unimplemented!(); | ||
} | ||
|
||
fn seek_to_last(&mut self) -> Result<CursorResult<()>> { | ||
unimplemented!(); | ||
} | ||
|
||
fn record(&self) -> Result<Ref<Option<OwnedRecord>>> { | ||
Ok(self.current.borrow()) | ||
} | ||
|
||
fn insert( | ||
&mut self, | ||
key: &OwnedValue, | ||
record: &OwnedRecord, | ||
moved_before: bool, | ||
) -> Result<CursorResult<()>> { | ||
let _ = key; | ||
let _ = moved_before; | ||
*self.current.borrow_mut() = Some(record.clone()); | ||
Ok(CursorResult::Ok(())) | ||
} | ||
|
||
fn delete(&mut self) -> Result<CursorResult<()>> { | ||
unimplemented!() | ||
} | ||
|
||
fn get_null_flag(&self) -> bool { | ||
false | ||
} | ||
|
||
fn set_null_flag(&mut self, _null_flag: bool) { | ||
// Do nothing | ||
} | ||
|
||
fn exists(&mut self, key: &OwnedValue) -> Result<CursorResult<bool>> { | ||
let _ = key; | ||
todo!() | ||
} | ||
|
||
fn btree_create(&mut self, _flags: usize) -> u32 { | ||
unreachable!("Please don't.") | ||
Self { current: None } | ||
} | ||
|
||
fn last(&mut self) -> Result<CursorResult<()>> { | ||
todo!() | ||
pub fn record(&self) -> Option<&OwnedRecord> { | ||
self.current.as_ref() | ||
} | ||
|
||
fn prev(&mut self) -> Result<CursorResult<()>> { | ||
todo!() | ||
pub fn insert(&mut self, record: OwnedRecord) { | ||
self.current = Some(record); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.