diff options
Diffstat (limited to 'lib/sqlalchemy/databases')
| -rw-r--r-- | lib/sqlalchemy/databases/information_schema.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 14 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/oracle.py | 11 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 22 | ||||
| -rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 8 |
5 files changed, 48 insertions, 18 deletions
diff --git a/lib/sqlalchemy/databases/information_schema.py b/lib/sqlalchemy/databases/information_schema.py index c0503c25c..f6dd251cd 100644 --- a/lib/sqlalchemy/databases/information_schema.py +++ b/lib/sqlalchemy/databases/information_schema.py @@ -31,6 +31,7 @@ gen_columns = schema.Table("columns", generic_engine, Column("character_maximum_length", Integer), Column("numeric_precision", Integer), Column("numeric_scale", Integer), + Column("column_default", Integer), schema="information_schema") gen_constraints = schema.Table("table_constraints", generic_engine, @@ -109,15 +110,16 @@ def reflecttable(engine, table, ischema_names, use_mysql=False): row = c.fetchone() if row is None: break -# print "row! " + repr(row) + #print "row! " + repr(row) # continue - (name, type, nullable, charlen, numericprec, numericscale) = ( + (name, type, nullable, charlen, numericprec, numericscale, default) = ( row[columns.c.column_name], row[columns.c.data_type], row[columns.c.is_nullable] == 'YES', row[columns.c.character_maximum_length], row[columns.c.numeric_precision], row[columns.c.numeric_scale], + row[columns.c.column_default] ) args = [] @@ -127,7 +129,10 @@ def reflecttable(engine, table, ischema_names, use_mysql=False): coltype = ischema_names[type] #print "coltype " + repr(coltype) + " args " + repr(args) coltype = coltype(*args) - table.append_item(schema.Column(name, coltype, nullable = nullable)) + colargs= [] + if default is not None: + colargs.append(PassiveDefault(default)) + table.append_item(schema.Column(name, coltype, nullable=nullable, *colargs)) s = select([constraints.c.constraint_name, constraints.c.constraint_type, constraints.c.table_name, key_constraints], use_labels=True) if not use_mysql: diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 6734274cd..0afac7df3 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -132,8 +132,8 @@ class MySQLEngine(ansisql.ANSISQLEngine): def compiler(self, statement, bindparams, **kwargs): return MySQLCompiler(self, statement, bindparams, **kwargs) - def schemagenerator(self, proxy, **params): - return MySQLSchemaGenerator(proxy, **params) + def schemagenerator(self, **params): + return MySQLSchemaGenerator(self, **params) def get_default_schema_name(self): if not hasattr(self, '_default_schema_name'): @@ -234,6 +234,13 @@ class MySQLTableImpl(sql.TableImpl): self.mysql_engine = mysql_engine class MySQLCompiler(ansisql.ANSICompiler): + + def visit_function(self, func): + if len(func.clauses): + super(MySQLCompiler, self).visit_function(func) + else: + self.strings[func] = func.name + def limit_clause(self, select): text = "" if select.limit is not None: @@ -248,6 +255,9 @@ class MySQLCompiler(ansisql.ANSICompiler): class MySQLSchemaGenerator(ansisql.ANSISchemaGenerator): def get_column_specification(self, column, override_pk=False, first_pk=False): colspec = column.name + " " + column.type.get_col_spec() + default = self.get_column_default_string(column) + if default is not None: + colspec += " DEFAULT " + default if not column.nullable: colspec += " NOT NULL" diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index 857b0c2fc..2ce07a3c6 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -104,10 +104,10 @@ class OracleSQLEngine(ansisql.ANSISQLEngine): def compiler(self, statement, bindparams, **kwargs): return OracleCompiler(self, statement, bindparams, use_ansi=self._use_ansi, **kwargs) - def schemagenerator(self, proxy, **params): - return OracleSchemaGenerator(proxy, **params) - def schemadropper(self, proxy, **params): - return OracleSchemaDropper(proxy, **params) + def schemagenerator(self, **params): + return OracleSchemaGenerator(self, **params) + def schemadropper(self, **params): + return OracleSchemaDropper(self, **params) def defaultrunner(self, proxy): return OracleDefaultRunner(self, proxy) @@ -227,6 +227,9 @@ class OracleSchemaGenerator(ansisql.ANSISchemaGenerator): def get_column_specification(self, column, override_pk=False, **kwargs): colspec = column.name colspec += " " + column.type.get_col_spec() + default = self.get_column_default_string(column) + if default is not None: + colspec += " DEFAULT " + default if not column.nullable: colspec += " NOT NULL" diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 9122c2afa..5d0a4e172 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -192,11 +192,11 @@ class PGSQLEngine(ansisql.ANSISQLEngine): def compiler(self, statement, bindparams, **kwargs): return PGCompiler(self, statement, bindparams, **kwargs) - def schemagenerator(self, proxy, **params): - return PGSchemaGenerator(proxy, **params) + def schemagenerator(self, **params): + return PGSchemaGenerator(self, **params) - def schemadropper(self, proxy, **params): - return PGSchemaDropper(proxy, **params) + def schemadropper(self, **params): + return PGSchemaDropper(self, **params) def defaultrunner(self, proxy): return PGDefaultRunner(self, proxy) @@ -254,6 +254,12 @@ class PGSQLEngine(ansisql.ANSISQLEngine): class PGCompiler(ansisql.ANSICompiler): + def visit_function(self, func): + if len(func.clauses): + super(PGCompiler, self).visit_function(func) + else: + self.strings[func] = func.name + def visit_insert_column(self, column): # Postgres advises against OID usage and turns it off in 8.1, # effectively making cursor.lastrowid @@ -273,14 +279,16 @@ class PGCompiler(ansisql.ANSICompiler): return text class PGSchemaGenerator(ansisql.ANSISchemaGenerator): + def get_column_specification(self, column, override_pk=False, **kwargs): colspec = column.name - if isinstance(column.default, schema.PassiveDefault): - colspec += " DEFAULT " + column.default.text - elif column.primary_key and isinstance(column.type, types.Integer) and (column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional)): + if column.primary_key and isinstance(column.type, types.Integer) and (column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional)): colspec += " SERIAL" else: colspec += " " + column.type.get_col_spec() + default = self.get_column_default_string(column) + if default is not None: + colspec += " DEFAULT " + default if not column.nullable: colspec += " NOT NULL" diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index 83fb00205..5401c350f 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -148,8 +148,8 @@ class SQLiteSQLEngine(ansisql.ANSISQLEngine): def dbapi(self): return sqlite - def schemagenerator(self, proxy, **params): - return SQLiteSchemaGenerator(proxy, **params) + def schemagenerator(self, **params): + return SQLiteSchemaGenerator(self, **params) def reflecttable(self, table): c = self.execute("PRAGMA table_info(" + table.name + ")", {}) @@ -226,6 +226,10 @@ class SQLiteCompiler(ansisql.ANSICompiler): class SQLiteSchemaGenerator(ansisql.ANSISchemaGenerator): def get_column_specification(self, column, override_pk=False, **kwargs): colspec = column.name + " " + column.type.get_col_spec() + default = self.get_column_default_string(column) + if default is not None: + colspec += " DEFAULT " + default + if not column.nullable: colspec += " NOT NULL" if column.primary_key and not override_pk: |
