Exemple #1
0
    def test_datetime(self):
        conn = None
        try:
            conn = connect(self.jdbc_url)
            cursor = conn.cursor()

            cursor.execute('''
            create table dt (
                one date,
                two date,
                three time,
                four time,
                five timestamp
                )
            ''')

            cursor.execute(
                'insert into dt values (?, ?, ?, ?, ?)',
                dbapi.Date(2012, 6, 1),
                Date(1338534000000),
                Time(1),
                dbapi.Time(1, 2, 3),
                dbapi.Timestamp(2012, 6, 1, 1, 2, 3),
            )
            cursor.execute('select * from dt')

            # crazy sqllite doesn't have normal date types.
            # this will force jep.jdbc to interpret the result correctly for this
            # test.
            cursor.description = (
                ('one', 91, None, None, None, None, True),
                ('two', 91, None, None, None, None, True),
                ('three', 92, None, None, None, None, True),
                ('four', 92, None, None, None, None, True),
                ('five', 93, None, None, None, None, True),
            )
            row = cursor.fetchone()

            self.assertEqual(row[0].toString(), '2012-06-01')
            self.assertEqual(row[1].getTime(), 1338534000000)
            self.assertEqual(row[2].getTime(), 1)
            self.assertEqual(row[3].toString(), '01:02:03')
            self.assertEqual(row[4].toString(), '2012-06-01 01:02:03.0')
            cursor.close()
        finally:
            if conn:
                conn.close()
Exemple #2
0
 def test_time(self):
     self.assertEquals(datetime.time(0, 0, 0),
                       Py.newTime(Time(0, 0, 0)))
     self.assertEquals(datetime.time(23, 59, 59),
                       Py.newTime(Time(23, 59, 59)))