number rules
- sql
- Text type is properly exported now and does not raise a warning
- on DDL create
+ on DDL create; String types with no length only raise warnings during
+ CREATE TABLE [ticket:912]
- fixed bug in union() so that select() statements which don't derive
from FromClause objects can be unioned
class AccessSchemaGenerator(compiler.SchemaGenerator):
def get_column_specification(self, column, **kwargs):
- colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
# install a sequence if we have an implicit IDENTITY column
if (not getattr(column.table, 'has_sequence', False)) and column.primary_key and \
def get_column_specification(self, column, **kwargs):
colspec = self.preparer.format_column(column)
- colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
default = self.get_column_default_string(column)
if default is not None:
colspec += " SERIAL"
self.has_serial = True
else:
- colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
default = self.get_column_default_string(column)
if default is not None:
colspec += " DEFAULT " + default
class MaxDBSchemaGenerator(compiler.SchemaGenerator):
def get_column_specification(self, column, **kw):
colspec = [self.preparer.format_column(column),
- column.type.dialect_impl(self.dialect).get_col_spec()]
+ column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()]
if not column.nullable:
colspec.append('NOT NULL')
class MSSQLSchemaGenerator(compiler.SchemaGenerator):
def get_column_specification(self, column, **kwargs):
- colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
# install a IDENTITY Sequence if we have an implicit IDENTITY column
if (not getattr(column.table, 'has_sequence', False)) and column.primary_key and \
"""Builds column DDL."""
colspec = [self.preparer.format_column(column),
- column.type.dialect_impl(self.dialect).get_col_spec()]
+ column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()]
default = self.get_column_default_string(column)
if default is not None:
class OracleSchemaGenerator(compiler.SchemaGenerator):
def get_column_specification(self, column, **kwargs):
colspec = self.preparer.format_column(column)
- colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
default = self.get_column_default_string(column)
if default is not None:
colspec += " DEFAULT " + default
item_type = item_type()
self.item_type = item_type
- def dialect_impl(self, dialect):
+ def dialect_impl(self, dialect, **kwargs):
impl = self.__class__.__new__(self.__class__)
impl.__dict__.update(self.__dict__)
impl.item_type = self.item_type.dialect_impl(dialect)
else:
colspec += " SERIAL"
else:
- colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
default = self.get_column_default_string(column)
if default is not None:
colspec += " DEFAULT " + default
class SQLiteSchemaGenerator(compiler.SchemaGenerator):
def get_column_specification(self, column, **kwargs):
- colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec = self.preparer.format_column(column) + " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
default = self.get_column_default_string(column)
if default is not None:
colspec += " DEFAULT " + default
#colspec += " numeric(30,0) IDENTITY"
colspec += " Integer IDENTITY"
else:
- colspec += " " + column.type.dialect_impl(self.dialect).get_col_spec()
+ colspec += " " + column.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
if not column.nullable:
colspec += " NOT NULL"
# py2.5 absolute imports will fix....
logging = __import__('logging')
-
+# why is this in the "logging" module?
class SADeprecationWarning(DeprecationWarning):
pass
return index.name
def visit_typeclause(self, typeclause, **kwargs):
- return typeclause.type.dialect_impl(self.dialect, _for_ddl=True).get_col_spec()
+ return typeclause.type.dialect_impl(self.dialect).get_col_spec()
def visit_textclause(self, textclause, **kwargs):
if textclause.typemap is not None:
def dialect_impl(self, dialect, **kwargs):
_for_ddl = kwargs.pop('_for_ddl', False)
- if self.length is None:
+ if _for_ddl and self.length is None:
warn_deprecated("Using String type with no length for CREATE TABLE is deprecated; use the Text type explicitly")
return TypeEngine.dialect_impl(self, dialect, **kwargs)
from testlib import *
from testlib import engines
+
class ReflectionTest(PersistTest):
@testing.exclude('mysql', '<', (4, 1, 1))
deftype = Integer
if use_string_defaults:
- deftype2 = String
+ deftype2 = Text
defval2 = "im a default"
deftype3 = Date
if testing.against('oracle'):
Column('user_name', VARCHAR(20), nullable = False),
Column('test1', CHAR(5), nullable = False),
Column('test2', FLOAT(5), nullable = False),
- Column('test3', TEXT),
+ Column('test3', Text),
Column('test4', DECIMAL, nullable = False),
Column('test5', TIMESTAMP),
Column('parent_user_id', Integer, ForeignKey('engine_users.user_id')),
Column('test6', DateTime, nullable = False),
- Column('test7', String),
+ Column('test7', Text),
Column('test8', Binary),
Column('test_passivedefault', deftype, PassiveDefault(defval)),
Column('test_passivedefault2', Integer, PassiveDefault("5")),
finally:
t.drop(checkfirst=True)
+class StringTest(AssertMixin):
+ def test_nolen_string_deprecated(self):
+ metadata = MetaData(testbase.db)
+ foo =Table('foo', metadata,
+ Column('one', String))
+
+ import warnings
+ from sqlalchemy.logging import SADeprecationWarning
+
+ warnings.filterwarnings("error", r"Using String type with no length.*")
+
+ # no warning
+ select([func.count("*")], bind=testbase.db).execute()
+
+ try:
+ # warning during CREATE
+ foo.create()
+ assert False
+ except SADeprecationWarning, e:
+ assert "Using String type with no length" in str(e)
+
+ bar = Table('bar', metadata, Column('one', String(40)))
+
+ try:
+ # no warning
+ bar.create()
+ # no warning for non-lengthed string
+ select([func.count("*")], from_obj=bar).execute()
+ finally:
+ bar.drop()
+ warnings.filterwarnings("always", r"Using String type with no length.*")
+
+
class NumericTest(AssertMixin):
def setUpAll(self):
global numeric_table, metadata