handle sqlite tables better by surrounding with brackets (#9752)

# Description

This PR helps the sqlite handling better by surrounding table names with
brackets. This makes it easier to have table names with spaces like
`Basin / profile`.

Closes #9751 

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
This commit is contained in:
Darren Schroeder 2023-07-20 11:20:56 -05:00 committed by GitHub
parent ba4723cc9f
commit c62cbcd5f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -157,7 +157,7 @@ fn action(
// create a string for sql table creation // create a string for sql table creation
let create_statement = let create_statement =
format!("CREATE TABLE IF NOT EXISTS {table_name} ({table_columns_creation})"); format!("CREATE TABLE IF NOT EXISTS [{table_name}] ({table_columns_creation})");
// prepare the string as a sqlite statement // prepare the string as a sqlite statement
let mut stmt = conn.prepare(&create_statement).map_err(|e| { let mut stmt = conn.prepare(&create_statement).map_err(|e| {
@ -189,7 +189,7 @@ fn action(
// ('dd', 'ee', 'ff') // ('dd', 'ee', 'ff')
// create the string for inserting data into the table // create the string for inserting data into the table
let insert_statement = format!("INSERT INTO {table_name} VALUES {table_values}"); let insert_statement = format!("INSERT INTO [{table_name}] VALUES {table_values}");
// prepare the string as a sqlite statement // prepare the string as a sqlite statement
let mut stmt = conn.prepare(&insert_statement).map_err(|e| { let mut stmt = conn.prepare(&insert_statement).map_err(|e| {

View File

@ -364,7 +364,7 @@ fn read_single_table(
call_span: Span, call_span: Span,
ctrlc: Option<Arc<AtomicBool>>, ctrlc: Option<Arc<AtomicBool>>,
) -> Result<Value, rusqlite::Error> { ) -> Result<Value, rusqlite::Error> {
let stmt = conn.prepare(&format!("SELECT * FROM {table_name}"))?; let stmt = conn.prepare(&format!("SELECT * FROM [{table_name}]"))?;
prepared_statement_to_nu_list(stmt, call_span, ctrlc) prepared_statement_to_nu_list(stmt, call_span, ctrlc)
} }