Problem with queries, Redland and python bindings
I'm developing a semantic reverse proxy that extracts metadata. I use Django, dj-revproxy and RDFLib (and for the storage I use MySQL), but i'm switching to redland's framework with the python bindings for the management of the semantic part.
But I have an important problem开发者_开发百科. After the storage of an RDF (The data is in the Mysql database, I checked) I want to do an sparql query and the result is "none". Maybe the method for the queries is badly implemented.
def sparql_query(query, user, password, db, output, dbSystem='mysql'):
if dbSystem == 'mysql':
st= connect_librdf_mysql(user, password, db)
else:
st= connect_librdf_sqlite(db)
options = 'database=\'' + db + '\''
model=RDF.Model(st, options_string=options)
q1 = RDF.Query(query ,query_language='sparql')
#q1Result = q1.execute(model)
q1Result = model.execute(q1)
print("[ SPARQL QUERY DONE ]")
if q1Result.is_graph():
return q1Result.as_stream()
else:
return str(q1Result)
The result is this:
slok@sLoKAsus:utils$ python ./test_redland.py
[ CONNETED TO redland2 DATABASE ]
[ RDF STORED ]
[ CONNETED TO redland2 DATABASE ]
[ SPARQL QUERY DONE ]
<?xml version="1.0" encoding="utf-8"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="aname"/>
<variable name="bname"/>
</head>
<results>
</results>
</sparql>
Thanks :)
I found the problem after upgrading to the GIT version of all the Redland libs (raptor, rasqal...). The problem is when I connect to MySQL database the new=true ruins all the stored data (data remains there, but the queries are null).
In other words, to solve the problem you have to update the libs and then the first time you connect(or create) the MySQL schema(db) put the new flag to true,and then always the flag to false. I put here the code to some functions that I made: Gist of MySQL and Redland example
精彩评论