diff --git a/lib/src/sparql/algebra.rs b/lib/src/sparql/algebra.rs index 87498ba3..f7e415fb 100644 --- a/lib/src/sparql/algebra.rs +++ b/lib/src/sparql/algebra.rs @@ -214,9 +214,9 @@ impl<'a> TryFrom<&'a String> for Query { #[derive(Eq, PartialEq, Debug, Clone, Hash)] pub struct Update { /// The update base IRI - pub base_iri: Option>, + pub(super) base_iri: Option>, /// The [update operations](https://www.w3.org/TR/sparql11-update/#formalModelGraphUpdate) - pub operations: Vec, + pub(super) operations: Vec, } impl Update { @@ -224,6 +224,28 @@ impl Update { pub fn parse(update: &str, base_iri: Option<&str>) -> Result { parse_update(update, base_iri) } + + /// Returns [the query dataset specification](https://www.w3.org/TR/sparql11-query/#specifyingDataset) in [DELETE/INSERT operations](https://www.w3.org/TR/sparql11-update/#deleteInsert). + pub fn using_datasets(&self) -> impl Iterator { + self.operations.iter().filter_map(|operation| { + if let GraphUpdateOperation::DeleteInsert { using, .. } = operation { + Some(using) + } else { + None + } + }) + } + + /// Returns [the query dataset specification](https://www.w3.org/TR/sparql11-query/#specifyingDataset) in [DELETE/INSERT operations](https://www.w3.org/TR/sparql11-update/#deleteInsert). + pub fn using_datasets_mut(&mut self) -> impl Iterator { + self.operations.iter_mut().filter_map(|operation| { + if let GraphUpdateOperation::DeleteInsert { using, .. } = operation { + Some(using) + } else { + None + } + }) + } } impl fmt::Display for Update { diff --git a/lib/src/sparql/mod.rs b/lib/src/sparql/mod.rs index 34dd2211..1f7b1b8c 100644 --- a/lib/src/sparql/mod.rs +++ b/lib/src/sparql/mod.rs @@ -1,8 +1,8 @@ //! [SPARQL](https://www.w3.org/TR/sparql11-overview/) implementation. //! -//! Stores execute SPARQL. See [`SledStore`](super::store::memory::SledStore::query()) for an example. +//! Stores execute SPARQL. See [`SledStore`](super::store::sled::SledStore::query()) for an example. -pub mod algebra; +mod algebra; mod csv_results; mod dataset; mod error; diff --git a/server/src/main.rs b/server/src/main.rs index 68cff0ba..07ec38a0 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -22,7 +22,6 @@ use http_types::{ }; use oxigraph::io::{DatasetFormat, GraphFormat}; use oxigraph::model::{GraphName, GraphNameRef, NamedNode, NamedOrBlankNode}; -use oxigraph::sparql::algebra::GraphUpdateOperation; use oxigraph::sparql::{Query, QueryResults, QueryResultsFormat, Update}; use oxigraph::SledStore as Store; use oxiri::Iri; @@ -494,16 +493,14 @@ fn evaluate_sparql_update( .collect::>>() .map_err(bad_request)?; if !default_graph_uris.is_empty() || !named_graph_uris.is_empty() { - for operation in &mut update.operations { - if let GraphUpdateOperation::DeleteInsert { using, .. } = operation { - if !using.is_default_dataset() { - bail_status!(400, + for using in update.using_datasets_mut() { + if !using.is_default_dataset() { + bail_status!(400, "using-graph-uri and using-named-graph-uri must not be used with a SPARQL UPDATE containing USING", ); - } - using.set_default_graph(default_graph_uris.clone()); - using.set_available_named_graphs(named_graph_uris.clone()); } + using.set_default_graph(default_graph_uris.clone()); + using.set_available_named_graphs(named_graph_uris.clone()); } } store.update(update)?;