diff --git a/core/schema.rs b/core/schema.rs index 3c932a454..2f63131ce 100644 --- a/core/schema.rs +++ b/core/schema.rs @@ -163,7 +163,7 @@ impl PseudoTable { pub fn add_column(&mut self, name: &str, ty: Type, primary_key: bool) { self.columns.push(Column { - name: name.to_string(), + name: normalize_ident(name), ty, primary_key, }); @@ -259,7 +259,7 @@ fn create_table( primary_key = true; } cols.push(Column { - name, + name: normalize_ident(&name), ty, primary_key, }); diff --git a/core/translate/expr.rs b/core/translate/expr.rs index 379c6e338..53816b24c 100644 --- a/core/translate/expr.rs +++ b/core/translate/expr.rs @@ -576,13 +576,15 @@ pub fn resolve_ident_qualified<'a>( select: &'a Select, cursor_hint: Option, ) -> Result<(usize, Type, usize, bool)> { + let ident = normalize_ident(ident); + let table_name = normalize_ident(table_name); for join in &select.src_tables { match join.table { Table::BTree(ref table) => { - let table_identifier = match join.alias { - Some(alias) => alias.clone(), - None => table.name.to_string(), - }; + let table_identifier = normalize_ident(match join.alias { + Some(alias) => alias, + None => &table.name, + }); if table_identifier == *table_name { let res = table .columns @@ -612,14 +614,15 @@ pub fn resolve_ident_table<'a>( select: &'a Select, cursor_hint: Option, ) -> Result<(usize, Type, usize, bool)> { + let ident = normalize_ident(ident); let mut found = Vec::new(); for join in &select.src_tables { match join.table { Table::BTree(ref table) => { - let table_identifier = match join.alias { - Some(alias) => alias.clone(), - None => table.name.to_string(), - }; + let table_identifier = normalize_ident(match join.alias { + Some(alias) => alias, + None => &table.name, + }); let res = table .columns .iter() diff --git a/core/translate/mod.rs b/core/translate/mod.rs index 1bf0f90dc..074e01ef5 100644 --- a/core/translate/mod.rs +++ b/core/translate/mod.rs @@ -5,19 +5,19 @@ pub(crate) mod where_clause; use std::cell::RefCell; use std::rc::Rc; -use expr::{build_select, maybe_apply_affinity, translate_expr}; use crate::function::{AggFunc, Func}; use crate::pager::Pager; use crate::schema::{Column, PseudoTable, Schema, Table}; -use crate::translate::select::{ColumnInfo, LoopInfo, Select, SrcTable}; use crate::sqlite3_ondisk::{DatabaseHeader, MIN_PAGE_CACHE_SIZE}; -use crate::types::{OwnedRecord, OwnedValue}; -use crate::util::normalize_ident; -use crate::vdbe::{BranchOffset, Insn, Program, ProgramBuilder}; +use crate::translate::select::{ColumnInfo, LoopInfo, Select, SrcTable}; use crate::translate::where_clause::{ evaluate_conditions, translate_conditions, translate_where, Inner, Left, QueryConstraint, }; +use crate::types::{OwnedRecord, OwnedValue}; +use crate::util::normalize_ident; +use crate::vdbe::{BranchOffset, Insn, Program, ProgramBuilder}; use anyhow::Result; +use expr::{build_select, maybe_apply_affinity, translate_expr}; use sqlite3_parser::ast::{self, Literal}; struct LimitInfo { @@ -426,10 +426,10 @@ fn translate_tables_end( } fn translate_table_open_cursor(program: &mut ProgramBuilder, table: &SrcTable) -> LoopInfo { - let table_identifier = match table.alias { - Some(alias) => alias.clone(), - None => table.table.get_name().to_string(), - }; + let table_identifier = normalize_ident(match table.alias { + Some(alias) => alias, + None => &table.table.get_name(), + }); let cursor_id = program.alloc_cursor_id(Some(table_identifier), Some(table.table.clone())); let root_page = match &table.table { Table::BTree(btree) => btree.root_page, @@ -539,10 +539,10 @@ fn translate_table_star( target_register: usize, cursor_hint: Option, ) { - let table_identifier = match table.alias { - Some(alias) => alias.clone(), - None => table.table.get_name().to_string(), - }; + let table_identifier = normalize_ident(match table.alias { + Some(alias) => alias, + None => &table.table.get_name(), + }); let table_cursor = program.resolve_cursor_id(&table_identifier, cursor_hint); let table = &table.table; for (i, col) in table.columns().iter().enumerate() { diff --git a/testing/select.test b/testing/select.test index 1f1698a3d..ac8750bbe 100644 --- a/testing/select.test +++ b/testing/select.test @@ -22,3 +22,7 @@ do_execsql_test realify { do_execsql_test select-add { select u.age + 1 from users u where u.age = 91 limit 1; } {92} + +do_execsql_test case-insensitive-columns { + select u.aGe + 1 from USERS u where U.AGe = 91 limit 1; +} {92}