def process(value):
# adodbapi will return datetimes with empty time values as datetime.date() objects.
# Promote them back to full datetime.datetime()
- if value and not hasattr(value, 'second'):
+ if value and isinstance(value, datetime.date):
return datetime.datetime(value.year, value.month, value.day)
return value
return process
class MSDateTime_pyodbc(MSDateTime):
def bind_processor(self, dialect):
def process(value):
- if value and not hasattr(value, 'second'):
+ if value and isinstance(value, datetime.date):
return datetime.datetime(value.year, value.month, value.day)
else:
return value
class MSDate_pyodbc(MSDate):
def bind_processor(self, dialect):
def process(value):
- if value and not hasattr(value, 'second'):
+ if value and isinstance(value, datetime.date):
return datetime.datetime(value.year, value.month, value.day)
else:
return value
def result_processor(self, dialect):
def process(value):
# pyodbc returns SMALLDATETIME values as datetime.datetime(). truncate it back to datetime.date()
- if value and hasattr(value, 'second'):
+ if value and isinstance(value, datetime.datetime):
return value.date()
else:
return value
def result_processor(self, dialect):
def process(value):
# pymssql will return SMALLDATETIME values as datetime.datetime(), truncate it back to datetime.date()
- if value and hasattr(value, 'second'):
+ if value and isinstance(value, datetime.datetime):
return value.date()
else:
return value
if default is not None:
colargs.append(schema.PassiveDefault(sql.text(default)))
- table.append_column(schema.Column(name, coltype, nullable=nullable, *colargs))
+ table.append_column(schema.Column(name, coltype, nullable=nullable, autoincrement=False, *colargs))
if not found_table:
raise exceptions.NoSuchTableError(table.name)
# We also run an sp_columns to check for identity columns:
- cursor = connection.execute("sp_columns %s" % self.identifier_preparer.format_table(table))
+ cursor = connection.execute("sp_columns @table_name = '%s', @table_owner = '%s'" % (table.name, current_schema))
ic = None
while True:
row = cursor.fetchone()
col_name, type_name = row[3], row[5]
if type_name.endswith("identity"):
ic = table.c[col_name]
+ ic.autoincrement = True
# setup a psuedo-sequence to represent the identity attribute - we interpret this at table.create() time as the identity attribute
ic.sequence = schema.Sequence(ic.name + '_identity')
# MSSQL: only one identity per table allowed
super(MSSQLDialect_pymssql, self).__init__(**params)
self.use_scope_identity = True
+ # pymssql understands only ascii
+ if self.convert_unicode:
+ self.encoding = params.get('encoding', 'ascii')
+
def do_rollback(self, connection):
# pymssql throws an error on repeated rollbacks. Ignore it.
# TODO: this is normal behavior for most DBs. are we sure we want to ignore it ?
class MSSQLDialect_adodbapi(MSSQLDialect):
supports_sane_rowcount = True
supports_sane_multi_rowcount = True
+ supports_unicode = sys.maxunicode == 65535
supports_unicode_statements = True
def import_dbapi(cls):