Commits

Anonymous committed 3c17eb2

mssql and test changes from trunk

  • Participants
  • Parent commits 333252f
  • Branches rel_0_4

Comments (0)

Files changed (3)

   - cleanup to connection-bound sessions, SessionTransaction
 - postgres
   - fixed max identifier length (63) [ticket:571]
+
+- mssql
+    - added support for TIME columns (simulated using DATETIME) [ticket:679]
+    - index names are now quoted when dropping from reflected tables [ticket:684]
   
 0.3.9
 - general

lib/sqlalchemy/databases/mssql.py

     def get_col_spec(self):
         return "SMALLDATETIME"
 
+class MSTime(sqltypes.Time):
+    __zero_date = datetime.date(1900, 1, 1)
+
+    def __init__(self, *a, **kw):
+        super(MSTime, self).__init__(False)
+    
+    def get_col_spec(self):
+        return "DATETIME"
+
+    def convert_bind_param(self, value, dialect):
+        if isinstance(value, datetime.datetime):
+            value = datetime.datetime.combine(self.__zero_date, value.time())
+        elif isinstance(value, datetime.time):
+            value = datetime.datetime.combine(self.__zero_date, value)
+        return value
+
+    def convert_result_value(self, value, dialect):
+        if isinstance(value, datetime.datetime):
+            return value.time()
+        elif isinstance(value, datetime.date):
+            return datetime.time(0, 0, 0)
+        return value
+
 class MSDateTime_adodbapi(MSDateTime):
     def convert_result_value(self, value, dialect):
         # adodbapi will return datetimes with empty time values as datetime.date() objects.
         sqltypes.Float : MSFloat,
         sqltypes.DateTime : MSDateTime,
         sqltypes.Date : MSDate,
+        sqltypes.Time : MSTime,
         sqltypes.String : MSString,
         sqltypes.Binary : MSBinary,
         sqltypes.Boolean : MSBoolean,
 
 class MSSQLSchemaDropper(ansisql.ANSISchemaDropper):
     def visit_index(self, index):
-        self.append("\nDROP INDEX " + index.table.name + "." + index.name)
+        self.append("\nDROP INDEX %s.%s" % (
+            self.preparer.quote_identifier(index.table.name),
+            self.preparer.quote_identifier(index.name)
+            ))
         self.execute()
 
+
 class MSSQLDefaultRunner(ansisql.ANSIDefaultRunner):
     # TODO: does ms-sql have standalone sequences ?
     pass

test/sql/testtypes.py

 
             collist = [Column('user_id', INT, primary_key = True), Column('user_name', VARCHAR(20)), Column('user_datetime', DateTime),
                Column('user_date', Date), Column('user_time', TIMESTAMP)]
-        elif db.engine.name == 'mysql' or db.engine.name == 'mssql':
+        elif db.engine.name == 'mysql':
             # these dont really support the TIME type at all
             insert_data =  [
                  [7, 'jack', datetime.datetime(2005, 11, 10, 0, 0), datetime.datetime(2005, 11, 10, 0, 0, 0)],
                     [10, 'colber', None, None, None]
             ]
 
+            if db.engine.name == 'mssql':
+                # MSSQL Datetime values have only a 3.33 milliseconds precision
+                insert_data[2] = [9, 'foo', datetime.datetime(2005, 11, 10, 11, 52, 35, 547000), datetime.date(1970,4,1), datetime.time(23,59,59,997000)]
+            
             fnames = ['user_id', 'user_name', 'user_datetime', 'user_date', 'user_time']
 
             collist = [Column('user_id', INT, primary_key = True), Column('user_name', VARCHAR(20)), Column('user_datetime', DateTime(timezone=False)),