Skip to content

Commit d12d805

Browse files
committed
Corrections for mysql under python3.
There is a problem with the mysql connector. oursql py3k and mysql-connector-python work, but not the connector used by travis-ci and listed in the requirements-py3.txt file.
1 parent afce0c9 commit d12d805

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

rdflib_sqlalchemy/SQLAlchemy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def unionSELECT(selectComponents, distinct=False, selectType=TRIPLE_SELECT):
164164
elif tableType == ASSERTED_TYPE_PARTITION:
165165
selectClause = expression.select(
166166
[table.c.member.label('subject'),
167-
expression.literal(RDF.type).label('predicate'),
167+
expression.literal(str(RDF.type) if PY3 else unicode(RDF.type)).label('predicate'),
168168
table.c.klass.label('object'),
169169
table.c.context.label('context'),
170170
table.c.termComb.label('termcomb'),
@@ -296,7 +296,7 @@ class TermType(types.TypeDecorator):
296296

297297
def process_bind_param(self, value, dialect):
298298
if isinstance(value, (QuotedGraph, Graph)):
299-
return value.identifier
299+
return str(value.identifier) if PY3 else unicode(value.identifier)
300300
elif isinstance(value, Node):
301301
return str(value) if PY3 else unicode(value)
302302
else:
@@ -581,6 +581,7 @@ def open(self, configuration, create=True):
581581
exists, but there is insufficient permissions to open the
582582
store."""
583583
name, opts = _parse_rfc1738_args(configuration)
584+
584585
self.engine = sqlalchemy.create_engine(configuration)
585586
with self.engine.connect() as connection:
586587
if create:
@@ -1170,6 +1171,7 @@ def prefix(self, namespace):
11701171
""" """
11711172
with self.engine.connect() as connection:
11721173
nb_table = self.tables['namespace_binds']
1174+
namespace = str(namespace) if PY3 else unicode(namespace)
11731175
s = select([nb_table.c.prefix]).where(nb_table.c.uri == namespace)
11741176
res = connection.execute(s)
11751177
rt = [rtTuple[0] for rtTuple in res.fetchall()]
@@ -1179,10 +1181,11 @@ def prefix(self, namespace):
11791181
def namespace(self, prefix):
11801182
""" """
11811183
res = None
1184+
prefix_val = str(prefix) if PY3 else unicode(prefix)
11821185
try:
11831186
with self.engine.connect() as connection:
11841187
nb_table = self.tables['namespace_binds']
1185-
s = select([nb_table.c.uri]).where(nb_table.c.prefix == prefix)
1188+
s = select([nb_table.c.uri]).where(nb_table.c.prefix == prefix_val)
11861189
res = connection.execute(s)
11871190
rt = [rtTuple[0] for rtTuple in res.fetchall()]
11881191
res.close()

0 commit comments

Comments
 (0)