add custom REGEXP function on begin event
@@ -276,7 +276,12 @@ class BIDSLayout(object):
return reg.search(item) is not None
conn = engine.connect()
- conn.connection.create_function('REGEXP', 2, regexp)
+ # Do not remove this decorator!!! An in-line create_function call will
+ # work when using an in-memory SQLite DB, but fails when using a file.
+ # For more details, see https://stackoverflow.com/questions/12461814/
+ @sa.event.listens_for(engine, "begin")
+ def do_begin(conn):
+ conn.connection.create_function('regexp', 2, regexp)
if reset_database:
Base.metadata.drop_all(engine)
@@ -289,6 +294,8 @@ class BIDSLayout(object):
# passing around the Layout.
globals()['session'] = self.session
+
+
return reset_database
def _validate_root(self):
