mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 23:23:12 +01:00
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:
parent
1e71cd4777
commit
3ae6fe2114
@ -269,7 +269,8 @@ fn insert_in_transaction(
|
||||
let insert_statement = format!(
|
||||
"INSERT INTO [{}] ({}) VALUES ({})",
|
||||
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>(),
|
||||
);
|
||||
|
||||
@ -390,8 +391,12 @@ fn get_columns_with_sqlite_types(
|
||||
let mut columns: Vec<(String, &'static str)> = vec![];
|
||||
|
||||
for (c, v) in record {
|
||||
if !columns.iter().any(|(name, _)| name == c) {
|
||||
columns.push((c.clone(), nu_value_to_sqlite_type(v)?));
|
||||
if !columns
|
||||
.iter()
|
||||
.map(|name| (format!("`{}`", name.0), name.1))
|
||||
.any(|(name, _)| name == *c)
|
||||
{
|
||||
columns.push((format!("`{}`", c), nu_value_to_sqlite_type(v)?));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user