Exemplo n.º 1
0
 def __init__(self, where_pattern=None):
     super(SPARQLUpdateQuery, self).__init__(where_pattern)
     self._delete = GroupGraphPattern([])
     self._insert = GroupGraphPattern([])
     # delete() can be called without graph pattern (DELETE WHERE), so we have to distinguish
     # between absent delete and delete without arguments (empty_delete)
     self.empty_delete = False
Exemplo n.º 2
0
 def delete(self, pattern=None, return_clone=True):  # Empty delete pattern means DELETE WHERE
     clone = self._clone() if return_clone else self
     if pattern is None:
         clone.empty_delete = True
         return clone
     elif not isinstance(pattern, GroupGraphPattern):
         pattern = GroupGraphPattern.from_obj(pattern)
     clone._delete.pattern(pattern)
     return clone
Exemplo n.º 3
0
 def delete(self, pattern=None):  # Empty delete pattern means DELETE WHERE
     clone = self._clone()
     if pattern is None:
         clone.empty_delete = True
         return clone
     elif not isinstance(pattern, GroupGraphPattern):
         pattern = GroupGraphPattern.from_obj(pattern)
     clone._delete.pattern(pattern)
     return clone
Exemplo n.º 4
0
 def template(self, query):
     yield '{'
     template = query._template
     if isinstance(template, basestring):
         yield template
     else:
         if not isinstance(template, GraphPattern):
             template = GroupGraphPattern.from_obj(template)
         for token in self.graph_pattern(template, False):
             yield token
     yield '}'
Exemplo n.º 5
0
 def template(self, query):
     yield '{'
     template = query._template
     if isinstance(template, basestring):
         yield template
     else:
         if not isinstance(template, GraphPattern):
             template = GroupGraphPattern.from_obj(template)
         for token in self.graph_pattern(template, False):
             yield token
     yield '}'
Exemplo n.º 6
0
    def where(self, *patterns, **kwargs):
        """Return a new `Select` with the given patterns in the WHERE clause.

        Each argument may be a triple (a 3-tuple or `Triple` instances) or a
        `GraphPattern` instance.  The patterns are added to the WHERE clause in
        the order specified.

        If the keyword-only `optional` argument is true, add all given patterns
        to an OPTIONAL graph pattern.

        """
        clone = self._clone()
        if patterns:
            graph_pattern = GroupGraphPattern.from_obj(patterns, **kwargs)
            clone._where.pattern(graph_pattern)
        return clone
Exemplo n.º 7
0
    def where(self, *patterns, **kwargs):
        """Return a new `Select` with the given patterns in the WHERE clause.

        Each argument may be a triple (a 3-tuple or `Triple` instances) or a
        `GraphPattern` instance.  The patterns are added to the WHERE clause in
        the order specified.

        If the keyword-only `optional` argument is true, add all given patterns
        to an OPTIONAL graph pattern.

        """
        clone = self._clone()
        if patterns:
            graph_pattern = GroupGraphPattern.from_obj(patterns, **kwargs)
            clone._where.pattern(graph_pattern)
        return clone
Exemplo n.º 8
0
def optional(*patterns):
    from sparqlquery.sparql.patterns import GroupGraphPattern
    return GroupGraphPattern(patterns, optional=True)
Exemplo n.º 9
0
 def insert(self, pattern, return_clone=True):
     clone = self._clone() if return_clone else self
     if not isinstance(pattern, GroupGraphPattern):
         pattern = GroupGraphPattern.from_obj(pattern)
     clone._insert.pattern(pattern)
     return clone
Exemplo n.º 10
0
 def __init__(self, pattern=None):
     if pattern is None:
         pattern = GroupGraphPattern([])
     elif not isinstance(pattern, GroupGraphPattern):
         pattern = GroupGraphPattern.from_obj(pattern)
     self._where = pattern
Exemplo n.º 11
0
 def insert(self, pattern):
     clone = self._clone()
     if not isinstance(pattern, GroupGraphPattern):
         pattern = GroupGraphPattern.from_obj(pattern)
     clone._insert.pattern(pattern)
     return clone
Exemplo n.º 12
0
 def __init__(self, pattern=None):
     if pattern is None:
         pattern = GroupGraphPattern([])
     elif not isinstance(pattern, GroupGraphPattern):
         pattern = GroupGraphPattern.from_obj(pattern)
     self._where = pattern