root/galaxy-central/eggs/sqlalchemy_migrate-0.5.4-py2.6.egg/migrate/versioning/script/sql.py

リビジョン 3, 1.0 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1from migrate.versioning.script import base
2
3class SqlScript(base.BaseScript):
4    """A file containing plain SQL statements."""
5    def run(self, engine, step):
6        text = self.source()
7        # Don't rely on SA's autocommit here
8        # (SA uses .startswith to check if a commit is needed. What if script
9        # starts with a comment?)
10        conn = engine.connect()
11        try:
12            trans = conn.begin()
13            try:
14                # ###HACK: SQLite doesn't allow multiple statements through
15                # its execute() method, but it provides executescript() instead
16                dbapi = conn.engine.raw_connection()
17                if getattr(dbapi, 'executescript', None):
18                    dbapi.executescript(text)
19                else:
20                    conn.execute(text)
21                # Success
22                trans.commit()
23            except:
24                trans.rollback()
25                raise
26        finally:
27            conn.close()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。