Exemplo n.º 1
0
    def test_datetimeoffset(self):
        if not IS_TDS73_PLUS(self.conn):
            self.skipTest('Requires TDS7.3+')

        def _testval(val):
            with self.conn.cursor() as cur:
                import pytds.tz
                cur.tzinfo_factory = pytds.tz.FixedOffsetTimezone
                cur.execute('select cast(%s as datetimeoffset)', (val, ))
                self.assertEqual(cur.fetchall(), [(val, )])

        with self.conn.cursor() as cur:
            import pytds.tz
            cur.tzinfo_factory = pytds.tz.FixedOffsetTimezone
            cur.execute(
                "select cast('2010-01-02T20:21:22.1234567+05:00' as datetimeoffset)"
            )
            self.assertEqual(
                datetime(2010, 1, 2, 20, 21, 22, 123456, tzoffset(5 * 60)),
                cur.fetchone()[0])
        _testval(Timestamp(2010, 1, 2, 0, 0, 0, 0, utc))
        _testval(Timestamp(2010, 1, 2, 0, 0, 0, 0, tzoffset(5 * 60)))
        _testval(Timestamp(1, 1, 1, 0, 0, 0, 0, utc))
        _testval(Timestamp(9999, 12, 31, 23, 59, 59, 999999, utc))
        _testval(Timestamp(2010, 1, 2, 0, 0, 0, 0, tzoffset(14)))
        _testval(Timestamp(2010, 1, 2, 0, 0, 0, 0, tzoffset(-14)))
        _testval(Timestamp(2010, 1, 2, 0, 0, 0, 0, tzoffset(-15)))
Exemplo n.º 2
0
 def test_new_datetime(self):
     if not IS_TDS73_PLUS(self.conn):
         self.skipTest('Requires TDS7.3+')
     import pytds.tz
     self._t(datetime(2011, 2, 3, 10, 11, 12, 3000),
             "cast('2011-02-03T10:11:12.003000' as datetime2)")
     self._t(time(10, 11, 12, 3000), "cast('10:11:12.003000' as time)")
     self._t(date(2011, 2, 3), "cast('2011-02-03' as date)")
     self._t(
         datetime(2011, 2, 3, 10, 11, 12, 3000,
                  pytds.tz.FixedOffsetTimezone(3 * 60)),
         "cast('2011-02-03T10:11:12.003000+03:00' as datetimeoffset)")
Exemplo n.º 3
0
    def test_date(self):
        if not IS_TDS73_PLUS(self.conn):
            self.skipTest('Requires TDS7.3+')

        def testval(val):
            with self.conn.cursor() as cur:
                cur.execute('select cast(%s as date)', (val, ))
                self.assertEqual(cur.fetchall(), [(val, )])

        testval(Date(2010, 1, 2))
        testval(Date(2010, 1, 2))
        testval(Date(1, 1, 1))
        testval(Date(9999, 12, 31))
Exemplo n.º 4
0
    def test_datetime2(self):
        if not IS_TDS73_PLUS(self.conn):
            self.skipTest('Requires TDS7.3+')

        def testval(val):
            with self.conn.cursor() as cur:
                cur.execute('select cast(%s as datetime2)', (val, ))
                self.assertEqual(cur.fetchall(), [(val, )])

        testval(Timestamp(2010, 1, 2, 20, 21, 22, 345678))
        testval(Timestamp(2010, 1, 2, 0, 0, 0))
        testval(Timestamp(1, 1, 1, 0, 0, 0))
        testval(Timestamp(9999, 12, 31, 23, 59, 59, 999999))
Exemplo n.º 5
0
 def runTest(self):
     kwargs = settings.CONNECT_KWARGS.copy()
     use_tz = utc
     kwargs['use_tz'] = use_tz
     kwargs['database'] = 'master'
     with connect(*settings.CONNECT_ARGS, **kwargs) as conn:
         # Naive time should be interpreted as use_tz
         self.check_val(conn, '%s', datetime(2011, 2, 3, 10, 11, 12, 3000),
                        datetime(2011, 2, 3, 10, 11, 12, 3000, utc))
         # Aware time shoule be passed as-is
         dt = datetime(2011, 2, 3, 10, 11, 12, 3000, tzoffset(1))
         self.check_val(conn, '%s', dt, dt)
         # Aware time should be converted to use_tz if not using datetimeoffset type
         dt = datetime(2011, 2, 3, 10, 11, 12, 3000, tzoffset(1))
         if IS_TDS73_PLUS(conn):
             self.check_val(conn, 'cast(%s as datetime2)', dt,
                            dt.astimezone(use_tz))
Exemplo n.º 6
0
    def test_time(self):
        if not IS_TDS73_PLUS(self.conn):
            self.skipTest('Requires TDS7.3+')

        def testval(val):
            with self.conn.cursor() as cur:
                cur.execute('select cast(%s as time)', (val, ))
                self.assertEqual(cur.fetchall(), [(val, )])

        testval(Time(14, 16, 18, 123456))
        testval(Time(0, 0, 0, 0))
        testval(Time(0, 0, 0, 0))
        testval(Time(0, 0, 0, 0))
        testval(Time(23, 59, 59, 999999))
        testval(Time(0, 0, 0, 0))
        testval(Time(0, 0, 0, 0))
        testval(Time(0, 0, 0, 0))