use crate::Engine;
use std::io::{Read, Write};
use uqa_sql::SQLError;
impl Engine {
pub fn copy_from(&self, statement: &str, mut input: impl Read) -> Result<u64, SQLError> {
let _statement = self.runtime.statement_gate.lock();
let result = self.synchronize_for_copy().and_then(|()| {
uqa_execution::copy::copy_from(&self.copy_execution_context(), statement, &mut input)
});
result.map_err(|error| self.abort_sql_transaction_after_error(error))
}
pub fn copy_to(&self, statement: &str, mut output: impl Write) -> Result<u64, SQLError> {
let _statement = self.runtime.statement_gate.lock();
let result = self.synchronize_for_copy().and_then(|()| {
uqa_execution::copy::copy_to(&self.copy_execution_context(), statement, &mut output)
});
result.map_err(|error| self.abort_sql_transaction_after_error(error))
}
fn synchronize_for_copy(&self) -> Result<(), SQLError> {
self.synchronize_table_catalog()
.map_err(|error| SQLError::Internal(format!("refresh table catalog: {error}")))?;
self.synchronize_table_data().map_err(|error| {
SQLError::Internal(format!("refresh committed table data: {error}"))
})?;
self.synchronize_catalog_registries().map_err(|error| {
SQLError::Internal(format!("refresh durable catalog registries: {error}"))
})
}
}