diff options
Diffstat (limited to 'lib/sqlalchemy/databases')
-rw-r--r-- | lib/sqlalchemy/databases/access.py | 20 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/firebird.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/information_schema.py | 31 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/informix.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/maxdb.py | 14 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 3 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/oracle.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/postgres.py | 7 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 4 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/sybase.py | 2 |
11 files changed, 48 insertions, 50 deletions
diff --git a/lib/sqlalchemy/databases/access.py b/lib/sqlalchemy/databases/access.py index aa65985d4..f33452200 100644 --- a/lib/sqlalchemy/databases/access.py +++ b/lib/sqlalchemy/databases/access.py @@ -22,7 +22,7 @@ class AcNumeric(types.Numeric): else: return str(value) return process - + def get_col_spec(self): return "NUMERIC" @@ -37,7 +37,7 @@ class AcFloat(types.Float): return str(value) return None return process - + class AcInteger(types.Integer): def get_col_spec(self): return "INTEGER" @@ -83,7 +83,7 @@ class AcUnicode(types.Unicode): return None class AcChar(types.CHAR): - def get_col_spec(self): + def get_col_spec(self): return "TEXT" + (self.length and ("(%d)" % self.length) or "") class AcBinary(types.Binary): @@ -100,7 +100,7 @@ class AcBoolean(types.Boolean): return None return value and True or False return process - + def bind_processor(self, dialect): def process(value): if value is True: @@ -112,7 +112,7 @@ class AcBoolean(types.Boolean): else: return value and True or False return process - + class AcTimeStamp(types.TIMESTAMP): def get_col_spec(self): return "TIMESTAMP" @@ -246,7 +246,7 @@ class AccessDialect(default.DefaultDialect): except Exception, e: return False - def reflecttable(self, connection, table, include_columns): + def reflecttable(self, connection, table, include_columns): # This is defined in the function, as it relies on win32com constants, # that aren't imported until dbapi method is called if not hasattr(self, 'ischema_names'): @@ -262,11 +262,11 @@ class AccessDialect(default.DefaultDialect): const.dbBoolean: AcBoolean, const.dbText: AcUnicode, # All Access strings are unicode } - + # A fresh DAO connection is opened for each reflection # This is necessary, so we get the latest updates dtbs = daoEngine.OpenDatabase(connection.engine.url.database) - + try: for tbl in dtbs.TableDefs: if tbl.Name.lower() == table.name.lower(): @@ -290,7 +290,7 @@ class AccessDialect(default.DefaultDialect): elif default: if col.Type == const.dbBoolean: default = default == 'Yes' and '1' or '0' - colargs['default'] = schema.PassiveDefault(sql.text(default)) + colargs['server_default'] = schema.DefaultClause(sql.text(default)) table.append_column(schema.Column(col.Name, coltype, **colargs)) @@ -316,7 +316,7 @@ class AccessDialect(default.DefaultDialect): col.unique = idx.Unique else: pass # TBD: multi-column indexes - + for fk in dtbs.Relations: if fk.ForeignTable != table.name: diff --git a/lib/sqlalchemy/databases/firebird.py b/lib/sqlalchemy/databases/firebird.py index d3662ccbf..346475869 100644 --- a/lib/sqlalchemy/databases/firebird.py +++ b/lib/sqlalchemy/databases/firebird.py @@ -550,7 +550,7 @@ class FBDialect(default.DefaultDialect): # the value comes down as "DEFAULT 'value'" assert row['fdefault'].startswith('DEFAULT ') defvalue = row['fdefault'][8:] - args.append(schema.PassiveDefault(sql.text(defvalue))) + args.append(schema.DefaultClause(sql.text(defvalue))) col = schema.Column(*args, **kw) if kw['primary_key']: diff --git a/lib/sqlalchemy/databases/information_schema.py b/lib/sqlalchemy/databases/information_schema.py index 20929cf1e..659bfc33a 100644 --- a/lib/sqlalchemy/databases/information_schema.py +++ b/lib/sqlalchemy/databases/information_schema.py @@ -1,7 +1,7 @@ import sqlalchemy.sql as sql import sqlalchemy.exc as exc from sqlalchemy import select, MetaData, Table, Column, String, Integer -from sqlalchemy.schema import PassiveDefault, ForeignKeyConstraint +from sqlalchemy.schema import DefaultClause, ForeignKeyConstraint ischema = MetaData() @@ -30,7 +30,7 @@ columns = Table("columns", ischema, Column("numeric_scale", Integer), Column("column_default", Integer), schema="information_schema") - + constraints = Table("table_constraints", ischema, Column("table_schema", String), Column("table_name", String), @@ -85,17 +85,17 @@ def table_names(connection, schema): def reflecttable(connection, table, include_columns, ischema_names): key_constraints = pg_key_constraints - + if table.schema is not None: current_schema = table.schema else: current_schema = connection.default_schema_name() - - s = select([columns], + + s = select([columns], sql.and_(columns.c.table_name==table.name, columns.c.table_schema==current_schema), order_by=[columns.c.ordinal_position]) - + c = connection.execute(s) found_table = False while True: @@ -106,9 +106,9 @@ def reflecttable(connection, table, include_columns, ischema_names): # continue found_table = True (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.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], @@ -116,7 +116,7 @@ def reflecttable(connection, table, include_columns, ischema_names): ) if include_columns and name not in include_columns: continue - + args = [] for a in (charlen, numericprec, numericscale): if a is not None: @@ -126,9 +126,9 @@ def reflecttable(connection, table, include_columns, ischema_names): coltype = coltype(*args) colargs = [] if default is not None: - colargs.append(PassiveDefault(sql.text(default))) + colargs.append(DefaultClause(sql.text(default))) table.append_column(Column(name, coltype, nullable=nullable, *colargs)) - + if not found_table: raise exc.NoSuchTableError(table.name) @@ -156,7 +156,7 @@ def reflecttable(connection, table, include_columns, ischema_names): row[colmap[5]], row[colmap[6]] ) - #print "type %s on column %s to remote %s.%s.%s" % (type, constrained_column, referred_schema, referred_table, referred_column) + #print "type %s on column %s to remote %s.%s.%s" % (type, constrained_column, referred_schema, referred_table, referred_column) if type == 'PRIMARY KEY': table.primary_key.add(table.c[constrained_column]) elif type == 'FOREIGN KEY': @@ -177,7 +177,6 @@ def reflecttable(connection, table, include_columns, ischema_names): fk[0].append(constrained_column) if refspec not in fk[1]: fk[1].append(refspec) - + for name, value in fks.iteritems(): - table.append_constraint(ForeignKeyConstraint(value[0], value[1], name=name)) - + table.append_constraint(ForeignKeyConstraint(value[0], value[1], name=name)) diff --git a/lib/sqlalchemy/databases/informix.py b/lib/sqlalchemy/databases/informix.py index c7bc49dbe..42c46db7c 100644 --- a/lib/sqlalchemy/databases/informix.py +++ b/lib/sqlalchemy/databases/informix.py @@ -317,7 +317,7 @@ class InfoDialect(default.DefaultDialect): colargs = [] if default is not None: - colargs.append(schema.PassiveDefault(sql.text(default))) + colargs.append(schema.DefaultClause(sql.text(default))) table.append_column(schema.Column(name, coltype, nullable = (nullable == 0), *colargs)) diff --git a/lib/sqlalchemy/databases/maxdb.py b/lib/sqlalchemy/databases/maxdb.py index 392cde61f..8d4d3bb0c 100644 --- a/lib/sqlalchemy/databases/maxdb.py +++ b/lib/sqlalchemy/databases/maxdb.py @@ -54,8 +54,8 @@ required components such as an Max-aware 'old oracle style' join compiler (thetas with (+) outer indicators) are already done and available for integration- email the devel list if you're interested in working on this. -""" +""" import datetime, itertools, re from sqlalchemy import exc, schema, sql, util @@ -648,14 +648,14 @@ class MaxDBDialect(default.DefaultDialect): col_kw['autoincrement'] = True else: # strip current numbering - col_kw['default'] = schema.PassiveDefault( + col_kw['server_default'] = schema.DefaultClause( sql.text('SERIAL')) col_kw['autoincrement'] = True else: - col_kw['default'] = schema.PassiveDefault( + col_kw['server_default'] = schema.DefaultClause( sql.text(func_def)) elif constant_def is not None: - col_kw['default'] = schema.PassiveDefault(sql.text( + col_kw['server_default'] = schema.DefaultClause(sql.text( "'%s'" % constant_def.replace("'", "''"))) table.append_column(schema.Column(name, type_instance, **col_kw)) @@ -972,7 +972,7 @@ class MaxDBSchemaGenerator(compiler.SchemaGenerator): # Assign DEFAULT SERIAL heuristically elif column.primary_key and column.autoincrement: # For SERIAL on a non-primary key member, use - # PassiveDefault(text('SERIAL')) + # DefaultClause(text('SERIAL')) try: first = [c for c in column.table.primary_key.columns if (c.autoincrement and @@ -987,7 +987,7 @@ class MaxDBSchemaGenerator(compiler.SchemaGenerator): return ' '.join(colspec) def get_column_default_string(self, column): - if isinstance(column.default, schema.PassiveDefault): + if isinstance(column.server_default, schema.DefaultClause): if isinstance(column.default.arg, basestring): if isinstance(column.type, sqltypes.Integer): return str(column.default.arg) @@ -1087,7 +1087,7 @@ def _autoserial_column(table): if col.default.optional: return index, col elif (col.default is None or - (not isinstance(col.default, schema.PassiveDefault))): + (not isinstance(col.server_default, schema.DefaultClause))): return index, col return None, None diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 4e129952f..1cacd81ef 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -37,7 +37,6 @@ Known issues / TODO: does **not** work around """ - import datetime, operator, re, sys from sqlalchemy import sql, schema, exc, util @@ -604,7 +603,7 @@ class MSSQLDialect(default.DefaultDialect): coltype = coltype(*args) colargs = [] if default is not None: - colargs.append(schema.PassiveDefault(sql.text(default))) + colargs.append(schema.DefaultClause(sql.text(default))) table.append_column(schema.Column(name, coltype, nullable=nullable, autoincrement=False, *colargs)) diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 0f40569b1..c4e6bf31f 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -671,19 +671,18 @@ class MSTimeStamp(sqltypes.TIMESTAMP): """MySQL TIMESTAMP type. To signal the orm to automatically re-select modified rows to retrieve - the updated timestamp, add a PassiveDefault to your column specification:: + the updated timestamp, add a DefaultClause to your column specification:: from sqlalchemy.databases import mysql Column('updated', mysql.MSTimeStamp, - PassiveDefault(sql.text('CURRENT_TIMESTAMP'))) + server_default=sql.text('CURRENT_TIMESTAMP')) The full range of MySQL 4.1+ TIMESTAMP defaults can be specified in - the PassiveDefault:: + the the default: - PassiveDefault(sql.text('CURRENT TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')) + server_default=sql.text('CURRENT TIMESTAMP ON UPDATE CURRENT_TIMESTAMP') """ - def get_col_spec(self): return "TIMESTAMP" @@ -2228,7 +2227,7 @@ class MySQLSchemaReflector(object): default = sql.text(default) else: default = default[1:-1] - col_args.append(schema.PassiveDefault(default)) + col_args.append(schema.DefaultClause(default)) table.append_column(schema.Column(name, type_instance, *col_args, **col_kw)) diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index 5bc8a186f..2f69f8fd9 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -493,7 +493,7 @@ class OracleDialect(default.DefaultDialect): colargs = [] if default is not None: - colargs.append(schema.PassiveDefault(sql.text(default))) + colargs.append(schema.DefaultClause(sql.text(default))) table.append_column(schema.Column(colname, coltype, nullable=nullable, *colargs)) diff --git a/lib/sqlalchemy/databases/postgres.py b/lib/sqlalchemy/databases/postgres.py index 23b0a273e..2f4865e96 100644 --- a/lib/sqlalchemy/databases/postgres.py +++ b/lib/sqlalchemy/databases/postgres.py @@ -546,7 +546,7 @@ class PGDialect(default.DefaultDialect): # unconditionally quote the schema name. this could # later be enhanced to obey quoting rules / "quote schema" default = match.group(1) + ('"%s"' % sch) + '.' + match.group(2) + match.group(3) - colargs.append(schema.PassiveDefault(sql.text(default))) + colargs.append(schema.DefaultClause(sql.text(default))) table.append_column(schema.Column(name, coltype, nullable=nullable, *colargs)) @@ -777,8 +777,9 @@ class PGDefaultRunner(base.DefaultRunner): def get_column_default(self, column, isinsert=True): if column.primary_key: # pre-execute passive defaults on primary keys - if isinstance(column.default, schema.PassiveDefault): - return self.execute_string("select %s" % column.default.arg) + if (isinstance(column.server_default, schema.DefaultClause) and + column.server_default.arg is not None): + return self.execute_string("select %s" % column.server_default.arg) elif (isinstance(column.type, sqltypes.Integer) and column.autoincrement) and (column.default is None or (isinstance(column.default, schema.Sequence) and column.default.optional)): sch = column.table.schema # TODO: this has to build into the Sequence object so we can get the quoting diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index a63741cf7..98e2acbf4 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -7,7 +7,7 @@ import datetime, re, time -from sqlalchemy import schema, exc, pool, PassiveDefault +from sqlalchemy import schema, exc, pool, DefaultClause from sqlalchemy.engine import default import sqlalchemy.types as sqltypes import sqlalchemy.util as util @@ -336,7 +336,7 @@ class SQLiteDialect(default.DefaultDialect): colargs = [] if has_default: - colargs.append(PassiveDefault('?')) + colargs.append(DefaultClause('?')) table.append_column(schema.Column(name, coltype, primary_key = primary_key, nullable = nullable, *colargs)) if not found_table: diff --git a/lib/sqlalchemy/databases/sybase.py b/lib/sqlalchemy/databases/sybase.py index 14734c6e0..cc8597068 100644 --- a/lib/sqlalchemy/databases/sybase.py +++ b/lib/sqlalchemy/databases/sybase.py @@ -599,7 +599,7 @@ class SybaseSQLDialect(default.DefaultDialect): coltype = coltype(*args) colargs = [] if default is not None: - colargs.append(schema.PassiveDefault(sql.text(default))) + colargs.append(schema.DefaultClause(sql.text(default))) # any sequences ? col = schema.Column(name, coltype, nullable=nullable, primary_key=primary_key, *colargs) |