diff options
| author | Alex Meade <alex.meade@rackspace.com> | 2012-08-15 15:02:30 -0400 |
|---|---|---|
| committer | Alex Meade <alex.meade@rackspace.com> | 2012-08-15 20:01:13 -0400 |
| commit | 377a65ffd7ee744dec9e6e909b2263b39f38efda (patch) | |
| tree | e24d66fcbde981a9607bb105ede3f35c9a7b3979 | |
| parent | d141e64de98f4e7eb0493d8f0a631f071b6e6dc1 (diff) | |
Update sqlite to use PoolEvents for regexp.
Use PoolEvents instead of PoolListener for adding regexp function.
Fixes bug 1037219
Change-Id: I205ecce133f628e995f38dea5ce89ddf36b01a9b
| -rw-r--r-- | nova/db/sqlalchemy/session.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/nova/db/sqlalchemy/session.py b/nova/db/sqlalchemy/session.py index cada9d79a..6e754be7e 100644 --- a/nova/db/sqlalchemy/session.py +++ b/nova/db/sqlalchemy/session.py @@ -57,6 +57,15 @@ def synchronous_switch_listener(dbapi_conn, connection_rec): dbapi_conn.execute("PRAGMA synchronous = OFF") +def add_regexp_listener(dbapi_con, con_record): + """Add REGEXP function to sqlite connections.""" + + def regexp(expr, item): + reg = re.compile(expr) + return reg.search(unicode(item)) is not None + dbapi_con.create_function('regexp', 2, regexp) + + def ping_listener(dbapi_conn, connection_rec, connection_proxy): """ Ensures that MySQL connections checked out of the @@ -86,16 +95,6 @@ def is_db_connection_error(args): return False -def regexp(expr, item): - reg = re.compile(expr) - return reg.search(unicode(item)) is not None - - -class AddRegexFactory(sqlalchemy.interfaces.PoolListener): - def connect(delf, dbapi_con, con_record): - dbapi_con.create_function('REGEXP', 2, regexp) - - def get_engine(): """Return a SQLAlchemy engine.""" global _ENGINE @@ -120,7 +119,6 @@ def get_engine(): if FLAGS.sql_connection == "sqlite://": engine_args["poolclass"] = StaticPool engine_args["connect_args"] = {'check_same_thread': False} - engine_args['listeners'] = [AddRegexFactory()] _ENGINE = sqlalchemy.create_engine(FLAGS.sql_connection, **engine_args) @@ -130,6 +128,7 @@ def get_engine(): if not FLAGS.sqlite_synchronous: sqlalchemy.event.listen(_ENGINE, 'connect', synchronous_switch_listener) + sqlalchemy.event.listen(_ENGINE, 'connect', add_regexp_listener) if (FLAGS.sql_connection_trace and _ENGINE.dialect.dbapi.__name__ == 'MySQLdb'): |
