mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-08-04 18:18:03 +00:00
syntactic changes: replace unwrap() with ? in functions that return Result<...>
This commit is contained in:
parent
86a4714711
commit
f160206cdd
7 changed files with 36 additions and 32 deletions
|
@ -194,7 +194,7 @@ impl Database {
|
|||
}
|
||||
|
||||
pub fn maybe_init_database_file(file: &Rc<dyn File>, io: &Arc<dyn IO>) -> Result<()> {
|
||||
if file.size().unwrap() == 0 {
|
||||
if file.size()? == 0 {
|
||||
// init db
|
||||
let db_header = DatabaseHeader::default();
|
||||
let page1 = allocate_page(
|
||||
|
@ -223,8 +223,7 @@ pub fn maybe_init_database_file(file: &Rc<dyn File>, io: &Arc<dyn IO>) -> Result
|
|||
let completion = Completion::Write(WriteCompletion::new(Box::new(move |_| {
|
||||
*flag_complete.borrow_mut() = true;
|
||||
})));
|
||||
file.pwrite(0, contents.buffer.clone(), Rc::new(completion))
|
||||
.unwrap();
|
||||
file.pwrite(0, contents.buffer.clone(), Rc::new(completion))?;
|
||||
}
|
||||
let mut limit = 100;
|
||||
loop {
|
||||
|
|
|
@ -542,7 +542,7 @@ impl BTreeCursor {
|
|||
match contents.rightmost_pointer() {
|
||||
Some(right_most_pointer) => {
|
||||
self.stack.set_cell_index(contents.cell_count() as i32 + 1);
|
||||
let mem_page = self.pager.read_page(right_most_pointer as usize).unwrap();
|
||||
let mem_page = self.pager.read_page(right_most_pointer as usize)?;
|
||||
self.stack.push(mem_page);
|
||||
continue;
|
||||
}
|
||||
|
@ -643,7 +643,7 @@ impl BTreeCursor {
|
|||
};
|
||||
if target_leaf_page_is_in_the_left_subtree {
|
||||
// we don't advance in case of index tree internal nodes because we will visit this node going up
|
||||
let mem_page = self.pager.read_page(*left_child_page as usize).unwrap();
|
||||
let mem_page = self.pager.read_page(*left_child_page as usize)?;
|
||||
self.stack.push(mem_page);
|
||||
found_cell = true;
|
||||
break;
|
||||
|
@ -663,7 +663,7 @@ impl BTreeCursor {
|
|||
match contents.rightmost_pointer() {
|
||||
Some(right_most_pointer) => {
|
||||
self.stack.advance();
|
||||
let mem_page = self.pager.read_page(right_most_pointer as usize).unwrap();
|
||||
let mem_page = self.pager.read_page(right_most_pointer as usize)?;
|
||||
self.stack.push(mem_page);
|
||||
continue;
|
||||
}
|
||||
|
@ -1027,15 +1027,13 @@ impl BTreeCursor {
|
|||
// Right page pointer is u32 in right most pointer, and in cell is u32 too, so we can use a *u32 to hold where we want to change this value
|
||||
let mut right_pointer = PAGE_HEADER_OFFSET_RIGHTMOST_PTR;
|
||||
for cell_idx in 0..parent_contents.cell_count() {
|
||||
let cell = parent_contents
|
||||
.cell_get(
|
||||
cell_idx,
|
||||
self.pager.clone(),
|
||||
self.payload_overflow_threshold_max(page_type.clone()),
|
||||
self.payload_overflow_threshold_min(page_type.clone()),
|
||||
self.usable_space(),
|
||||
)
|
||||
.unwrap();
|
||||
let cell = parent_contents.cell_get(
|
||||
cell_idx,
|
||||
self.pager.clone(),
|
||||
self.payload_overflow_threshold_max(page_type.clone()),
|
||||
self.payload_overflow_threshold_min(page_type.clone()),
|
||||
self.usable_space(),
|
||||
)?;
|
||||
let found = match cell {
|
||||
BTreeCell::TableInteriorCell(interior) => {
|
||||
interior._left_child_page as usize == current_idx
|
||||
|
@ -1138,6 +1136,13 @@ impl BTreeCursor {
|
|||
self.usable_space(),
|
||||
)
|
||||
.unwrap();
|
||||
let last_cell = contents.cell_get(
|
||||
contents.cell_count() - 1,
|
||||
self.pager.clone(),
|
||||
self.payload_overflow_threshold_max(contents.page_type()),
|
||||
self.payload_overflow_threshold_min(contents.page_type()),
|
||||
self.usable_space(),
|
||||
)?;
|
||||
let last_cell_pointer = match last_cell {
|
||||
BTreeCell::TableInteriorCell(interior) => interior._left_child_page,
|
||||
_ => unreachable!(),
|
||||
|
@ -1170,8 +1175,7 @@ impl BTreeCursor {
|
|||
self.payload_overflow_threshold_max(contents.page_type()),
|
||||
self.payload_overflow_threshold_min(contents.page_type()),
|
||||
self.usable_space(),
|
||||
)
|
||||
.unwrap();
|
||||
)?;
|
||||
|
||||
if is_leaf {
|
||||
// create a new divider cell and push
|
||||
|
|
|
@ -1564,7 +1564,7 @@ pub fn translate_expr(
|
|||
} else {
|
||||
// must be a float
|
||||
program.emit_insn(Insn::Real {
|
||||
value: val.parse().unwrap(),
|
||||
value: val.parse()?,
|
||||
dest: target_register,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ fn check_automatic_pk_index_required(
|
|||
if let Err(e) = result {
|
||||
bail_parse_error!("{}", e);
|
||||
}
|
||||
let column_name = result.unwrap();
|
||||
let column_name = result?;
|
||||
let column_def = columns.get(&ast::Name(column_name.clone()));
|
||||
if column_def.is_none() {
|
||||
bail_parse_error!("No such column: {}", column_name);
|
||||
|
@ -575,11 +575,11 @@ fn update_pragma(
|
|||
PragmaName::CacheSize => {
|
||||
let cache_size = match value {
|
||||
ast::Expr::Literal(ast::Literal::Numeric(numeric_value)) => {
|
||||
numeric_value.parse::<i64>().unwrap()
|
||||
numeric_value.parse::<i64>()?
|
||||
}
|
||||
ast::Expr::Unary(ast::UnaryOperator::Negative, expr) => match *expr {
|
||||
ast::Expr::Literal(ast::Literal::Numeric(numeric_value)) => {
|
||||
-numeric_value.parse::<i64>().unwrap()
|
||||
-numeric_value.parse::<i64>()?
|
||||
}
|
||||
_ => bail_parse_error!("Not a valid value"),
|
||||
},
|
||||
|
|
|
@ -330,7 +330,7 @@ impl Interaction {
|
|||
);
|
||||
return Err(err.unwrap());
|
||||
}
|
||||
let rows = rows.unwrap();
|
||||
let rows = rows?;
|
||||
assert!(rows.is_some());
|
||||
let mut rows = rows.unwrap();
|
||||
let mut out = Vec::new();
|
||||
|
|
|
@ -78,7 +78,7 @@ impl IO for SimulatorIO {
|
|||
"Injected fault".into(),
|
||||
));
|
||||
}
|
||||
self.inner.run_once().unwrap();
|
||||
self.inner.run_once()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -332,7 +332,7 @@ mod tests {
|
|||
for i in 0..iterations {
|
||||
let insert_query = format!("INSERT INTO test VALUES ({})", i);
|
||||
do_flush(&conn, &tmp_db)?;
|
||||
conn.checkpoint().unwrap();
|
||||
conn.checkpoint()?;
|
||||
match conn.query(insert_query) {
|
||||
Ok(Some(ref mut rows)) => loop {
|
||||
match rows.next_row()? {
|
||||
|
@ -351,7 +351,7 @@ mod tests {
|
|||
}
|
||||
|
||||
do_flush(&conn, &tmp_db)?;
|
||||
conn.clear_page_cache().unwrap();
|
||||
conn.clear_page_cache()?;
|
||||
let list_query = "SELECT * FROM test LIMIT 1";
|
||||
let mut current_index = 0;
|
||||
match conn.query(list_query) {
|
||||
|
@ -417,7 +417,7 @@ mod tests {
|
|||
debug!("counting");
|
||||
let list_query = "SELECT count(x) FROM test";
|
||||
loop {
|
||||
if let Some(ref mut rows) = conn.query(list_query).unwrap() {
|
||||
if let Some(ref mut rows) = conn.query(list_query)? {
|
||||
loop {
|
||||
match rows.next_row()? {
|
||||
StepResult::Row(row) => {
|
||||
|
@ -445,12 +445,13 @@ mod tests {
|
|||
let conn = tmp_db.connect_limbo();
|
||||
insert(1, &conn, &tmp_db).unwrap();
|
||||
assert_eq!(count(&conn, &tmp_db).unwrap(), 1);
|
||||
insert(1, &conn, &tmp_db)?;
|
||||
conn.close()?;
|
||||
}
|
||||
{
|
||||
let conn = tmp_db.connect_limbo();
|
||||
assert_eq!(
|
||||
count(&conn, &tmp_db).unwrap(),
|
||||
count(&conn, &tmp_db)?,
|
||||
1,
|
||||
"failed to read from wal from another connection"
|
||||
);
|
||||
|
@ -619,7 +620,7 @@ mod tests {
|
|||
|
||||
let mut stmt = conn.prepare("select ?")?;
|
||||
|
||||
stmt.bind_at(1.try_into().unwrap(), Value::Integer(1));
|
||||
stmt.bind_at(1.try_into()?, Value::Integer(1));
|
||||
|
||||
loop {
|
||||
match stmt.step()? {
|
||||
|
@ -633,7 +634,7 @@ mod tests {
|
|||
|
||||
stmt.reset();
|
||||
|
||||
stmt.bind_at(1.try_into().unwrap(), Value::Integer(2));
|
||||
stmt.bind_at(1.try_into()?, Value::Integer(2));
|
||||
|
||||
loop {
|
||||
match stmt.step()? {
|
||||
|
@ -656,14 +657,14 @@ mod tests {
|
|||
|
||||
let mut stmt = conn.prepare("select ?, ?1, :named, ?3, ?4")?;
|
||||
|
||||
stmt.bind_at(1.try_into().unwrap(), Value::Text(&"hello".to_string()));
|
||||
stmt.bind_at(1.try_into()?, Value::Text(&"hello".to_string()));
|
||||
|
||||
let i = stmt.parameters().index(":named").unwrap();
|
||||
stmt.bind_at(i, Value::Integer(42));
|
||||
|
||||
stmt.bind_at(3.try_into().unwrap(), Value::Blob(&vec![0x1, 0x2, 0x3]));
|
||||
stmt.bind_at(3.try_into()?, Value::Blob(&vec![0x1, 0x2, 0x3]));
|
||||
|
||||
stmt.bind_at(4.try_into().unwrap(), Value::Float(0.5));
|
||||
stmt.bind_at(4.try_into()?, Value::Float(0.5));
|
||||
|
||||
assert_eq!(stmt.parameters().count(), 4);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue