Enable columns with spaces for into_sqlite by adding quotes to column names (#12759)

# Description
Spaces were causing an issue with into_sqlite when they appeared in
column names.

This is because the column names were not properly wrapped with
backticks that allow sqlite to properly interpret the column.

The issue has been addressed by adding backticks to the column names of
into sqlite. The output of the column names when using open is
unchanged, and the column names appear without backticks as expected.

fixes #12700 

# User-Facing Changes
N/A

# Tests + Formatting
Formatting has been respected.

Repro steps from the issue have been done, and ran multiple times. New
values get added to the correct columns as expected.
This commit is contained in:
Maxime Jacob 2024-05-04 09:12:44 -04:00 committed by GitHub
parent 1e71cd4777
commit 3ae6fe2114
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -269,7 +269,8 @@ fn insert_in_transaction(
let insert_statement = format!( let insert_statement = format!(
"INSERT INTO [{}] ({}) VALUES ({})", "INSERT INTO [{}] ({}) VALUES ({})",
table_name, table_name,
Itertools::intersperse(val.columns().map(String::as_str), ", ").collect::<String>(), Itertools::intersperse(val.columns().map(|c| format!("`{}`", c)), ", ".to_string())
.collect::<String>(),
Itertools::intersperse(itertools::repeat_n("?", val.len()), ", ").collect::<String>(), Itertools::intersperse(itertools::repeat_n("?", val.len()), ", ").collect::<String>(),
); );
@ -390,8 +391,12 @@ fn get_columns_with_sqlite_types(
let mut columns: Vec<(String, &'static str)> = vec![]; let mut columns: Vec<(String, &'static str)> = vec![];
for (c, v) in record { for (c, v) in record {
if !columns.iter().any(|(name, _)| name == c) { if !columns
columns.push((c.clone(), nu_value_to_sqlite_type(v)?)); .iter()
.map(|name| (format!("`{}`", name.0), name.1))
.any(|(name, _)| name == *c)
{
columns.push((format!("`{}`", c), nu_value_to_sqlite_type(v)?));
} }
} }