mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-09 18:24:20 +01:00
modify translate_select to return number of result columns
This commit is contained in:
@@ -99,6 +99,15 @@ pub fn translate_insert(
|
||||
})
|
||||
.collect::<Vec<(&String, usize, usize)>>();
|
||||
let root_page = btree_table.root_page;
|
||||
|
||||
let inserting_multiple_rows = match body {
|
||||
InsertBody::Select(select, _) => match select.body.select.as_ref() {
|
||||
OneSelect::Values(values) => values.len() > 1,
|
||||
OneSelect::Select(..) => true,
|
||||
},
|
||||
InsertBody::DefaultValues => false,
|
||||
};
|
||||
|
||||
let values = match body {
|
||||
InsertBody::Select(ref mut select, _) => match select.body.select.as_mut() {
|
||||
OneSelect::Values(ref mut values) => values,
|
||||
@@ -141,8 +150,6 @@ pub fn translate_insert(
|
||||
let halt_label = program.allocate_label();
|
||||
let loop_start_label = program.allocate_label();
|
||||
|
||||
let inserting_multiple_rows = values.len() > 1;
|
||||
|
||||
// Multiple rows - use coroutine for value population
|
||||
if inserting_multiple_rows {
|
||||
let yield_reg = program.alloc_register();
|
||||
|
||||
@@ -232,7 +232,9 @@ pub fn translate_inner(
|
||||
ast::Stmt::Release(_) => bail_parse_error!("RELEASE not supported yet"),
|
||||
ast::Stmt::Rollback { .. } => bail_parse_error!("ROLLBACK not supported yet"),
|
||||
ast::Stmt::Savepoint(_) => bail_parse_error!("SAVEPOINT not supported yet"),
|
||||
ast::Stmt::Select(select) => translate_select(query_mode, schema, *select, syms, program)?,
|
||||
ast::Stmt::Select(select) => {
|
||||
translate_select(query_mode, schema, *select, syms, program)?.program
|
||||
}
|
||||
ast::Stmt::Update(mut update) => translate_update(
|
||||
query_mode,
|
||||
schema,
|
||||
|
||||
@@ -19,13 +19,18 @@ use crate::{schema::Schema, vdbe::builder::ProgramBuilder, Result};
|
||||
use limbo_sqlite3_parser::ast::{self, CompoundSelect, SortOrder};
|
||||
use limbo_sqlite3_parser::ast::{ResultColumn, SelectInner};
|
||||
|
||||
pub struct TranslateSelectResult {
|
||||
pub program: ProgramBuilder,
|
||||
pub num_result_cols: usize,
|
||||
}
|
||||
|
||||
pub fn translate_select(
|
||||
query_mode: QueryMode,
|
||||
schema: &Schema,
|
||||
select: ast::Select,
|
||||
syms: &SymbolTable,
|
||||
mut program: ProgramBuilder,
|
||||
) -> Result<ProgramBuilder> {
|
||||
) -> Result<TranslateSelectResult> {
|
||||
let mut select_plan = prepare_select_plan(
|
||||
schema,
|
||||
select,
|
||||
@@ -63,8 +68,12 @@ pub fn translate_select(
|
||||
};
|
||||
|
||||
program.extend(&opts);
|
||||
let num_result_cols = select.result_columns.len();
|
||||
emit_program(&mut program, select_plan, syms)?;
|
||||
Ok(program)
|
||||
Ok(TranslateSelectResult {
|
||||
program,
|
||||
num_result_cols,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn prepare_select_plan<'a>(
|
||||
|
||||
Reference in New Issue
Block a user