core: Move result row to ProgramState

Move result row to `ProgramState` to mimic what SQLite does where `Vdbe`
struct has a `pResultRow` member. This makes it easier to deal with result
lifetime, but more importantly, eventually lazily parse values at the edges of
the API.
This commit is contained in:
Pekka Enberg
2025-02-06 07:52:00 +02:00
parent 0012e9d556
commit c210821100
20 changed files with 230 additions and 211 deletions

View File

@@ -41,16 +41,17 @@ fn test_simple_overflow_page() -> anyhow::Result<()> {
match conn.query(list_query) {
Ok(Some(ref mut rows)) => loop {
match rows.step()? {
StepResult::Row(row) => {
let first_value = &row.values[0];
let text = &row.values[1];
StepResult::Row => {
let row = rows.row().unwrap();
let first_value = row.values[0].to_value();
let text = row.values[1].to_value();
let id = match first_value {
Value::Integer(i) => *i as i32,
Value::Float(f) => *f as i32,
Value::Integer(i) => i as i32,
Value::Float(f) => f as i32,
_ => unreachable!(),
};
let text = match text {
Value::Text(t) => *t,
Value::Text(t) => t,
_ => unreachable!(),
};
assert_eq!(1, id);
@@ -115,16 +116,17 @@ fn test_sequential_overflow_page() -> anyhow::Result<()> {
match conn.query(list_query) {
Ok(Some(ref mut rows)) => loop {
match rows.step()? {
StepResult::Row(row) => {
let first_value = &row.values[0];
let text = &row.values[1];
StepResult::Row => {
let row = rows.row().unwrap();
let first_value = row.values[0].to_value();
let text = row.values[1].to_value();
let id = match first_value {
Value::Integer(i) => *i as i32,
Value::Float(f) => *f as i32,
Value::Integer(i) => i as i32,
Value::Float(f) => f as i32,
_ => unreachable!(),
};
let text = match text {
Value::Text(t) => *t,
Value::Text(t) => t,
_ => unreachable!(),
};
let huge_text = &huge_texts[current_index];
@@ -186,11 +188,12 @@ fn test_sequential_write() -> anyhow::Result<()> {
match conn.query(list_query) {
Ok(Some(ref mut rows)) => loop {
match rows.step()? {
StepResult::Row(row) => {
StepResult::Row => {
let row = rows.row().unwrap();
let first_value = row.values.first().expect("missing id");
let id = match first_value {
Value::Integer(i) => *i as i32,
Value::Float(f) => *f as i32,
let id = match first_value.to_value() {
Value::Integer(i) => i as i32,
Value::Float(f) => f as i32,
_ => unreachable!(),
};
assert_eq!(current_read_index, id);
@@ -251,10 +254,11 @@ fn test_regression_multi_row_insert() -> anyhow::Result<()> {
match conn.query(list_query) {
Ok(Some(ref mut rows)) => loop {
match rows.step()? {
StepResult::Row(row) => {
StepResult::Row => {
let row = rows.row().unwrap();
let first_value = row.values.first().expect("missing id");
let id = match first_value {
Value::Float(f) => *f as i32,
let id = match first_value.to_value() {
Value::Float(f) => f as i32,
_ => panic!("expected float"),
};
actual_ids.push(id);
@@ -296,8 +300,9 @@ fn test_statement_reset() -> anyhow::Result<()> {
loop {
match stmt.step()? {
StepResult::Row(row) => {
assert_eq!(row.values[0], Value::Integer(1));
StepResult::Row => {
let row = stmt.row().unwrap();
assert_eq!(row.values[0].to_value(), Value::Integer(1));
break;
}
StepResult::IO => tmp_db.io.run_once()?,
@@ -309,8 +314,9 @@ fn test_statement_reset() -> anyhow::Result<()> {
loop {
match stmt.step()? {
StepResult::Row(row) => {
assert_eq!(row.values[0], Value::Integer(1));
StepResult::Row => {
let row = stmt.row().unwrap();
assert_eq!(row.values[0].to_value(), Value::Integer(1));
break;
}
StepResult::IO => tmp_db.io.run_once()?,
@@ -358,11 +364,12 @@ fn test_wal_checkpoint() -> anyhow::Result<()> {
match conn.query(list_query) {
Ok(Some(ref mut rows)) => loop {
match rows.step()? {
StepResult::Row(row) => {
let first_value = &row.values[0];
StepResult::Row => {
let row = rows.row().unwrap();
let first_value = row.values[0].to_value();
let id = match first_value {
Value::Integer(i) => *i as i32,
Value::Float(f) => *f as i32,
Value::Integer(i) => i as i32,
Value::Float(f) => f as i32,
_ => unreachable!(),
};
assert_eq!(current_index, id as usize);
@@ -421,10 +428,11 @@ fn test_wal_restart() -> anyhow::Result<()> {
if let Some(ref mut rows) = conn.query(list_query)? {
loop {
match rows.step()? {
StepResult::Row(row) => {
let first_value = &row.values[0];
StepResult::Row => {
let row = rows.row().unwrap();
let first_value = row.values[0].to_value();
let count = match first_value {
Value::Integer(i) => *i as i32,
Value::Integer(i) => i,
_ => unreachable!(),
};
debug!("counted {}", count);