Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARQLUpdateStore should use SPARQLWrapper instead of custom httplib.HTTPConnection #392

Closed
olberger opened this issue May 13, 2014 · 2 comments · Fixed by #397
Closed

Comments

@olberger
Copy link

I'm fighting with a SPARQL update syntax issue when using SPARQLUpdateStore to add triples to a virtuoso store. The requests apparently succeds, silently discarding the SPARQL syntax error reported by the server.

I'm quite sure there'd be a lot of improvement if SPARQLUpdateStore used SPARQLWrapper's query() to talk to the server instead of its own httplib.HTTPConnection connection.

@uholzer
Copy link
Contributor

uholzer commented May 13, 2014

Definitely. As far as I remember, back when I worked on SPARQLUpdateStore, SPARQLWrapper wasn't advanced enough to do updates in a meaningful way. I think the situation has changed. So, contributions are welcome.

@olberger
Copy link
Author

Something along these lines should do :

class MyResponse(StringIO.StringIO):
    """Fakes a httplib.HTTPResponse which is always correct, for MySPARQLUpdateStore::_do_update()"""
    status = 200

class MySPARQLUpdateStore(SPARQLUpdateStore):
    """Overload SPARQLUpdateStore::_do_update() to use SPARQLWrapper::query()"""
    def _do_update(self, update):
        if myconfig.VERBOSE:
            handler = urllib2.HTTPHandler(debuglevel=1)
            opener = urllib2.build_opener(handler)
            urllib2.install_opener(opener)

            print update

        sparql = SPARQLWrapper(self.update_endpoint)
        sparql.setQuery(update)
        sparql.setMethod(POST)
        sparql.setReturnFormat(JSON)
        # Hack for Virtuoso
        #sparql.queryType= SELECT

        result = sparql.query()

        response = MyResponse(result.response.read())
        return response

At least here, it seems to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants