11
11
RDF ,
12
12
URIRef
13
13
)
14
+ from rdflib .term import Node
14
15
from rdflib .graph import Graph
15
16
from rdflib .graph import QuotedGraph
16
17
from rdflib .store import Store # , NodePickler
48
49
49
50
INTERNED_PREFIX = 'kb_'
50
51
52
+ MYSQL_MAX_INDEX_LENGTH = 200
53
+
51
54
Any = None
52
55
53
56
# Stolen from Will Waites' py4s
@@ -294,6 +297,8 @@ class TermType(types.TypeDecorator):
294
297
def process_bind_param (self , value , dialect ):
295
298
if isinstance (value , (QuotedGraph , Graph )):
296
299
return value .identifier
300
+ elif isinstance (value , Node ):
301
+ return str (value ) if PY3 else unicode (value )
297
302
else :
298
303
return value
299
304
@@ -578,13 +583,8 @@ def open(self, configuration, create=True):
578
583
name , opts = _parse_rfc1738_args (configuration )
579
584
self .engine = sqlalchemy .create_engine (configuration )
580
585
with self .engine .connect () as connection :
581
- trans = connection .begin ()
582
586
if create :
583
- try :
584
- self .metadata .create_all (self .engine )
585
- trans .commit ()
586
- except Exception :
587
- trans .rollback ()
587
+ self .metadata .create_all (self .engine )
588
588
#self._db.create_function("regexp", 2, regexp)
589
589
if configuration :
590
590
from sqlalchemy .engine import reflection
@@ -1211,10 +1211,10 @@ def __create_table_definitions(self):
1211
1211
nullable = False , key = "termComb" ),
1212
1212
Index ("%s_A_termComb_index" % self ._internedId ,
1213
1213
'termComb' ),
1214
- Index ("%s_A_s_index" % self ._internedId , 'subject' ),
1215
- Index ("%s_A_p_index" % self ._internedId , 'predicate' ),
1216
- Index ("%s_A_o_index" % self ._internedId , 'object' ),
1217
- Index ("%s_A_c_index" % self ._internedId , 'context' )),
1214
+ Index ("%s_A_s_index" % self ._internedId , 'subject' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1215
+ Index ("%s_A_p_index" % self ._internedId , 'predicate' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1216
+ Index ("%s_A_o_index" % self ._internedId , 'object' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1217
+ Index ("%s_A_c_index" % self ._internedId , 'context' , mysql_length = MYSQL_MAX_INDEX_LENGTH )),
1218
1218
'type_statements' :
1219
1219
Table ('%s_type_statements' % self ._internedId , self .metadata ,
1220
1220
Column ('member' , TermType , nullable = False ),
@@ -1224,9 +1224,9 @@ def __create_table_definitions(self):
1224
1224
key = "termComb" ),
1225
1225
Index ("%s_T_termComb_index" % self ._internedId ,
1226
1226
'termComb' ),
1227
- Index ("%s_member_index" % self ._internedId , 'member' ),
1228
- Index ("%s_klass_index" % self ._internedId , 'klass' ),
1229
- Index ("%s_c_index" % self ._internedId , 'context' )),
1227
+ Index ("%s_member_index" % self ._internedId , 'member' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1228
+ Index ("%s_klass_index" % self ._internedId , 'klass' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1229
+ Index ("%s_c_index" % self ._internedId , 'context' , mysql_length = MYSQL_MAX_INDEX_LENGTH )),
1230
1230
'literal_statements' :
1231
1231
Table (
1232
1232
'%s_literal_statements' % self ._internedId , self .metadata ,
@@ -1242,9 +1242,9 @@ def __create_table_definitions(self):
1242
1242
key = "objDatatype" ),
1243
1243
Index ("%s_L_termComb_index" % self ._internedId ,
1244
1244
'termComb' ),
1245
- Index ("%s_L_s_index" % self ._internedId , 'subject' ),
1246
- Index ("%s_L_p_index" % self ._internedId , 'predicate' ),
1247
- Index ("%s_L_c_index" % self ._internedId , 'context' )),
1245
+ Index ("%s_L_s_index" % self ._internedId , 'subject' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1246
+ Index ("%s_L_p_index" % self ._internedId , 'predicate' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1247
+ Index ("%s_L_c_index" % self ._internedId , 'context' , mysql_length = MYSQL_MAX_INDEX_LENGTH )),
1248
1248
'quoted_statements' :
1249
1249
Table (
1250
1250
"%s_quoted_statements" % self ._internedId , self .metadata ,
@@ -1260,17 +1260,17 @@ def __create_table_definitions(self):
1260
1260
key = "objDatatype" ),
1261
1261
Index ("%s_Q_termComb_index" % self ._internedId ,
1262
1262
'termComb' ),
1263
- Index ("%s_Q_s_index" % self ._internedId , 'subject' ),
1264
- Index ("%s_Q_p_index" % self ._internedId , 'predicate' ),
1265
- Index ("%s_Q_o_index" % self ._internedId , 'object' ),
1266
- Index ("%s_Q_c_index" % self ._internedId , 'context' )),
1263
+ Index ("%s_Q_s_index" % self ._internedId , 'subject' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1264
+ Index ("%s_Q_p_index" % self ._internedId , 'predicate' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1265
+ Index ("%s_Q_o_index" % self ._internedId , 'object' , mysql_length = MYSQL_MAX_INDEX_LENGTH ),
1266
+ Index ("%s_Q_c_index" % self ._internedId , 'context' , mysql_length = MYSQL_MAX_INDEX_LENGTH )),
1267
1267
'namespace_binds' :
1268
1268
Table (
1269
1269
"%s_namespace_binds" % self ._internedId , self .metadata ,
1270
1270
Column ('prefix' , types .String (20 ), unique = True ,
1271
1271
nullable = False , primary_key = True ),
1272
1272
Column ('uri' , types .Text ),
1273
- Index ("%s_uri_index" % self ._internedId , 'uri' ))
1273
+ Index ("%s_uri_index" % self ._internedId , 'uri' , mysql_length = MYSQL_MAX_INDEX_LENGTH ))
1274
1274
}
1275
1275
1276
1276
0 commit comments