mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +00:00
Fix unexpected sqlite insert behaviour (attempt 2) (#12128)
- fixes #11429 - fixes #12011 Refers to: https://github.com/nushell/nushell/pull/12039 In general looks a bit faster now.
This commit is contained in:
parent
8822750048
commit
a9ddc58f21
1 changed files with 32 additions and 26 deletions
|
@ -209,21 +209,6 @@ fn insert_in_transaction(
|
||||||
|
|
||||||
let table_name = table.name().clone();
|
let table_name = table.name().clone();
|
||||||
let tx = table.try_init(first_val)?;
|
let tx = table.try_init(first_val)?;
|
||||||
let insert_statement = format!(
|
|
||||||
"INSERT INTO [{}] VALUES ({})",
|
|
||||||
table_name,
|
|
||||||
["?"].repeat(first_val.values().len()).join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut insert_statement =
|
|
||||||
tx.prepare(&insert_statement)
|
|
||||||
.map_err(|e| ShellError::GenericError {
|
|
||||||
error: "Failed to prepare SQLite statement".into(),
|
|
||||||
msg: e.to_string(),
|
|
||||||
span: None,
|
|
||||||
help: None,
|
|
||||||
inner: Vec::new(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
// insert all the records
|
// insert all the records
|
||||||
stream.try_for_each(|stream_value| {
|
stream.try_for_each(|stream_value| {
|
||||||
|
@ -233,18 +218,39 @@ fn insert_in_transaction(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_value(stream_value, &mut insert_statement)
|
let val = stream_value.as_record()?;
|
||||||
})?;
|
|
||||||
|
|
||||||
insert_statement
|
let insert_statement = format!(
|
||||||
.finalize()
|
"INSERT INTO [{}] ({}) VALUES ({})",
|
||||||
.map_err(|e| ShellError::GenericError {
|
table_name,
|
||||||
error: "Failed to finalize SQLite prepared statement".into(),
|
val.cols.join(", "),
|
||||||
msg: e.to_string(),
|
["?"].repeat(val.values().len()).join(", ")
|
||||||
span: None,
|
);
|
||||||
help: None,
|
|
||||||
inner: Vec::new(),
|
let mut insert_statement =
|
||||||
})?;
|
tx.prepare(&insert_statement)
|
||||||
|
.map_err(|e| ShellError::GenericError {
|
||||||
|
error: "Failed to prepare SQLite statement".into(),
|
||||||
|
msg: e.to_string(),
|
||||||
|
span: None,
|
||||||
|
help: None,
|
||||||
|
inner: Vec::new(),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let result = insert_value(stream_value, &mut insert_statement);
|
||||||
|
|
||||||
|
insert_statement
|
||||||
|
.finalize()
|
||||||
|
.map_err(|e| ShellError::GenericError {
|
||||||
|
error: "Failed to finalize SQLite prepared statement".into(),
|
||||||
|
msg: e.to_string(),
|
||||||
|
span: None,
|
||||||
|
help: None,
|
||||||
|
inner: Vec::new(),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
result
|
||||||
|
})?;
|
||||||
|
|
||||||
tx.commit().map_err(|e| ShellError::GenericError {
|
tx.commit().map_err(|e| ShellError::GenericError {
|
||||||
error: "Failed to commit SQLite transaction".into(),
|
error: "Failed to commit SQLite transaction".into(),
|
||||||
|
|
Loading…
Reference in a new issue