use std::cell::RefCell; use std::rc::Rc; use crate::function::AggFunc; use crate::pager::Pager; use crate::schema::{Schema, Table}; use crate::sqlite3_ondisk::{DatabaseHeader, MIN_PAGE_CACHE_SIZE}; use crate::util::normalize_ident; use crate::vdbe::{Insn, Program, ProgramBuilder}; use anyhow::Result; use sqlite3_parser::ast; struct Select<'a> { columns: Vec, column_info: Vec, from: Option<&'a Table>, limit: Option, exist_aggregation: bool, } struct ColumnInfo { func: Option, args: Option>, columns_to_allocate: usize, /* number of result columns this col will result on */ } impl ColumnInfo { pub fn new() -> Self { Self { func: None, args: None, columns_to_allocate: 1, } } pub fn is_aggregation_function(&self) -> bool { self.func.is_some() } } /// Translate SQL statement into bytecode program. pub fn translate( schema: &Schema, stmt: ast::Stmt, database_header: Rc>, pager: Rc, ) -> Result { match stmt { ast::Stmt::Select(select) => { let select = build_select(schema, select)?; translate_select(select) } ast::Stmt::Pragma(name, body) => translate_pragma(&name, body, database_header, pager), _ => todo!(), } } fn build_select(schema: &Schema, select: ast::Select) -> Result