mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 04:24:21 +01:00
Merge pull request #60 from pereman2/agg-uppercase
core: fix agg function uppercase parsing
This commit is contained in:
@@ -8,6 +8,7 @@ mod storage;
|
||||
mod translate;
|
||||
mod types;
|
||||
mod vdbe;
|
||||
mod util;
|
||||
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
#[global_allocator]
|
||||
|
||||
@@ -8,6 +8,8 @@ use sqlite3_parser::{
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::util::normalize_ident;
|
||||
|
||||
pub struct Schema {
|
||||
pub tables: HashMap<String, Table>,
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
8
core/util.rs
Normal file
8
core/util.rs
Normal file
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user