diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-07 23:08:42 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-07 23:08:42 +0000 |
| commit | 048f70ce85d254eff0b5ccf16fd4e15274b0bc6a (patch) | |
| tree | 41e964852135c7b56142af3ac313b0355470e562 /lib/sqlalchemy/dialects/sqlite | |
| parent | 90efddbb1d52e7c26bb71e4b1c2dea121d3a0f8e (diff) | |
| download | sqlalchemy-048f70ce85d254eff0b5ccf16fd4e15274b0bc6a.tar.gz | |
- sqlite dialect properly generates CREATE INDEX for a table
that is in an alternate schema. [ticket:1439]
Diffstat (limited to 'lib/sqlalchemy/dialects/sqlite')
| -rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index d83eb4b86..235a17a66 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -239,11 +239,25 @@ class SQLiteDDLCompiler(compiler.DDLCompiler): if not column.nullable: colspec += " NOT NULL" return colspec - + + def visit_create_index(self, create): + index = create.element + preparer = self.preparer + text = "CREATE " + if index.unique: + text += "UNIQUE " + text += "INDEX %s ON %s (%s)" \ + % (preparer.format_index(index, + name=self._validate_identifier(index.name, True)), + preparer.format_table(index.table, use_schema=False), + ', '.join(preparer.quote(c.name, c.quote) + for c in index.columns)) + return text + class SQLiteTypeCompiler(compiler.GenericTypeCompiler): def visit_binary(self, type_): return self.visit_BLOB(type_) - + class SQLiteIdentifierPreparer(compiler.IdentifierPreparer): reserved_words = set([ 'add', 'after', 'all', 'alter', 'analyze', 'and', 'as', 'asc', @@ -265,6 +279,16 @@ class SQLiteIdentifierPreparer(compiler.IdentifierPreparer): 'vacuum', 'values', 'view', 'virtual', 'when', 'where', ]) + def format_index(self, index, use_schema=True, name=None): + """Prepare a quoted index and schema name.""" + + if name is None: + name = index.name + result = self.quote(name, index.quote) + if not self.omit_schema and use_schema and getattr(index.table, "schema", None): + result = self.quote_schema(index.table.schema, index.table.quote_schema) + "." + result + return result + class SQLiteDialect(default.DefaultDialect): name = 'sqlite' supports_alter = False |
