From 9242e5c6715a0543e7c70e0d824dbfe7834553fa Mon Sep 17 00:00:00 2001 From: Pere Diaz Bou Date: Mon, 1 Jul 2024 15:47:57 +0200 Subject: [PATCH] core: fix agg function uppercase parsing Signed-off-by: Pere Diaz Bou --- core/lib.rs | 1 + core/schema.rs | 10 ++-------- core/translate.rs | 3 ++- core/util.rs | 8 ++++++++ 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 core/util.rs diff --git a/core/lib.rs b/core/lib.rs index 91b2084ac..73eb826c1 100644 --- a/core/lib.rs +++ b/core/lib.rs @@ -8,6 +8,7 @@ mod storage; mod translate; mod types; mod vdbe; +mod util; #[cfg(not(target_family = "wasm"))] #[global_allocator] diff --git a/core/schema.rs b/core/schema.rs index bd30f289a..3e48b2208 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -8,6 +8,8 @@ use sqlite3_parser::{ }; use std::collections::HashMap; +use crate::util::normalize_ident; + pub struct Schema { pub tables: HashMap, } @@ -140,14 +142,6 @@ fn create_table(tbl_name: QualifiedName, body: CreateTableBody, root_page: usize }) } -fn normalize_ident(ident: &str) -> String { - if ident.starts_with('"') && ident.ends_with('"') { - ident[1..ident.len() - 1].to_string().to_lowercase() - } else { - ident.to_lowercase() - } -} - pub struct Column { pub name: String, pub ty: Type, diff --git a/core/translate.rs b/core/translate.rs index 2ace4a36c..4aeeb1a00 100644 --- a/core/translate.rs +++ b/core/translate.rs @@ -4,6 +4,7 @@ use std::rc::Rc; use crate::pager::Pager; use crate::schema::Schema; use crate::sqlite3_ondisk::{DatabaseHeader, MIN_PAGE_CACHE_SIZE}; +use crate::util::normalize_ident; use crate::vdbe::{AggFunc, Insn, Program, ProgramBuilder}; use anyhow::Result; use sqlite3_parser::ast::{ @@ -323,7 +324,7 @@ fn analyze_column(column: &sqlite3_parser::ast::ResultColumn, column_info_out: & args, filter_over: _, } => { - let func_type = match name.0.as_str() { + let func_type = match normalize_ident(name.0.as_str()).as_str() { "avg" => Some(AggregationFunc::Avg), "count" => Some(AggregationFunc::Count), "group_concat" => Some(AggregationFunc::GroupConcat), diff --git a/core/util.rs b/core/util.rs new file mode 100644 index 000000000..0d87d5779 --- /dev/null +++ b/core/util.rs @@ -0,0 +1,8 @@ + +pub fn normalize_ident(ident: &str) -> String { + if ident.starts_with('"') && ident.ends_with('"') { + ident[1..ident.len() - 1].to_string().to_lowercase() + } else { + ident.to_lowercase() + } +}