diff --git a/core/lib.rs b/core/lib.rs index e4874e755..b845a39c4 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -1612,21 +1612,7 @@ impl Connection { } let pragma = format!("PRAGMA {pragma_name}"); let mut stmt = self.prepare(pragma)?; - let mut results = Vec::new(); - loop { - match stmt.step()? { - vdbe::StepResult::Row => { - let row: Vec = stmt.row().unwrap().get_values().cloned().collect(); - results.push(row); - } - vdbe::StepResult::Interrupt | vdbe::StepResult::Busy => { - return Err(LimboError::Busy); - } - _ => break, - } - } - - Ok(results) + stmt.run_collect_rows() } /// Set a new value to `pragma_name`. @@ -1643,21 +1629,7 @@ impl Connection { } let pragma = format!("PRAGMA {pragma_name} = {pragma_value}"); let mut stmt = self.prepare(pragma)?; - let mut results = Vec::new(); - loop { - match stmt.step()? { - vdbe::StepResult::Row => { - let row: Vec = stmt.row().unwrap().get_values().cloned().collect(); - results.push(row); - } - vdbe::StepResult::Interrupt | vdbe::StepResult::Busy => { - return Err(LimboError::Busy); - } - _ => break, - } - } - - Ok(results) + stmt.run_collect_rows() } pub fn experimental_views_enabled(&self) -> bool { @@ -2021,6 +1993,23 @@ impl Statement { } } + pub(crate) fn run_collect_rows(&mut self) -> Result>> { + let mut values = Vec::new(); + loop { + match self.step()? { + vdbe::StepResult::Done => return Ok(values), + vdbe::StepResult::IO => self.run_once()?, + vdbe::StepResult::Row => { + values.push(self.row().unwrap().get_values().cloned().collect()); + continue; + } + vdbe::StepResult::Interrupt | vdbe::StepResult::Busy => { + return Err(LimboError::Busy) + } + } + } + } + #[instrument(skip_all, level = Level::DEBUG)] fn reprepare(&mut self) -> Result<()> { tracing::trace!("repreparing statement");