Uploaded image for project: 'CUBRID APIs'
  1. CUBRID APIs
  2. APIS-410

[Python 8.4.4] After insert into class and then select it from class, the datatime is changed

    Details

      Description

      After insert into class and then select it from class, the datatime is changed

      Cubrid 8.4.4
      cubrid python driver  8.4.4
      

      error msg

      ======================================================================
      FAIL: test_date (__main__.FetchoneTypeTest)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "python/_05_datetype/DataTypeTest.py", line 208, in test_date
          self.assertEquals(dataList[i].isoformat(), data[0])
      AssertionError: '0001-01-01' != datetime.date(1, 1, 1)
      
      ======================================================================
      FAIL: test_datetime (__main__.FetchoneTypeTest)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "python/_05_datetype/DataTypeTest.py", line 237, in test_datetime
          self.assertEquals('0001-01-01 00:00:00.000', data[2])
      AssertionError: '0001-01-01 00:00:00.000' != datetime.datetime(1, 1, 1, 0, 0)
      
      ======================================================================
      FAIL: test_time (__main__.FetchoneTypeTest)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "python/_05_datetype/DataTypeTest.py", line 222, in test_time
          self.assertEquals(dataList[i].isoformat().rstrip('9').rstrip('.'), data[1])
      AssertionError: '00:00:00' != datetime.time(0, 0)
      
      ======================================================================
      FAIL: test_timestamp (__main__.FetchoneTypeTest)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
        File "python/_05_datetype/DataTypeTest.py", line 252, in test_timestamp
          self.assertEquals(dataCheck[i], data[0])
      AssertionError: '2012-10-31 00:00:00' != datetime.datetime(2012, 10, 31, 0, 0)
      
      ----------------------------------------------------------------------
      
      This problem has not exist when using cubrid 9.0.0 and python driver 9.0.0 
      the test codes attached 
      
      
      1. DataTypeTest.py
        12 kB
        欧明宝[Bom Owen]

        Activity

        Hide
        cn15800 谢韦华[Bert] added a comment - - edited

        The bug is case by cci. If you set autocommit as CCI_AUTOCOMMIT_FALSE and insert value as follow:
        insert into datetime_db(c_time) values v1,v2,v3
        When you excute select command and not excute commit command, the data retuen by cci:
        v3,v2,v1
        But if you excute select command after commit(cci_end_tran (con, CCI_TRAN_COMMIT, &cci_error)), the bug will not appear.

        If you set autocommit as CCI_AUTOCOMMIT_TRUE or insert value as follow:
        insert into datetime_db(c_time) values v1
        insert into datetime_db(c_time) values v2
        insert into datetime_db(c_time) values v3

        The bug will not exist.

        Show
        cn15800 谢韦华[Bert] added a comment - - edited The bug is case by cci. If you set autocommit as CCI_AUTOCOMMIT_FALSE and insert value as follow: insert into datetime_db(c_time) values v1,v2,v3 When you excute select command and not excute commit command, the data retuen by cci: v3,v2,v1 But if you excute select command after commit(cci_end_tran (con, CCI_TRAN_COMMIT, &cci_error)), the bug will not appear. If you set autocommit as CCI_AUTOCOMMIT_TRUE or insert value as follow: insert into datetime_db(c_time) values v1 insert into datetime_db(c_time) values v2 insert into datetime_db(c_time) values v3 The bug will not exist.
        Hide
        cn15800 谢韦华[Bert] added a comment -

        I do not know it's a bug or not, you can excute commit command(self.con.commit()) and then query data.

        Order is correct

        Show
        cn15800 谢韦华[Bert] added a comment - I do not know it's a bug or not, you can excute commit command(self.con.commit()) and then query data. Order is correct
        Hide
        cn15800 谢韦华[Bert] added a comment -

        print by my Environment:

        sqlInsert:insert into datetime_db(c_datetime) values ('0001-01-01T00:00:00'),('2013-05-14T13:42:20.471000'),('2013-05-14T13:42:20.471000'),('9999-12-31T23:59:59.999999')

        0001-01-01 00:00:00

        Show
        cn15800 谢韦华[Bert] added a comment - print by my Environment: sqlInsert:insert into datetime_db(c_datetime) values ('0001-01-01T00:00:00'),('2013-05-14T13:42:20.471000'),('2013-05-14T13:42:20.471000'),('9999-12-31T23:59:59.999999') 0001-01-01 00:00:00
        Hide
        ryin005 Ray Yin added a comment - - edited

        Python isoformat() returns a string representing the date/time/datetime in ISO 8601 format
        http://docs.python.org/2/library/datetime.html

        data = self.cur.fetchone() returns a python date/time/datetime object, but not in ISO 8601 format

        So modified the case as follows:

        import unittest
        import CUBRIDdb
        import locale
        import time
        import datetime 
        from datetime import time
        from datetime import date
        from datetime import datetime
        from xml.dom import minidom
        
        class apis_410_test(unittest.TestCase):
            def setUp(self):
                    conStr="CUBRID:localhost:33188:test_python:::"
                    self.con = CUBRIDdb.connect(conStr, "dba","")        
                    self.cur = self.con.cursor()
                    self.con.set_autocommit(True)
                    self.cur.execute("DROP TABLE IF EXISTS datetime_db")
                    self.cur.execute("CREATE TABLE datetime_db(c_date date, c_time time, c_datetime datetime, c_timestamp timestamp)")
        
            def tearDown(self):
                    self.cur.close
                    self.con.close
                    
            def test_date(self):
                    dataList = [date.min,date.today(),date.max]
                    sqlInsert = "insert into datetime_db(c_date) values "
                    for i in dataList:
                        sqlInsert = sqlInsert + "('" + i.isoformat() + "'),"
                    sqlInsert = sqlInsert.rstrip(',')
                    rowNum = self.cur.execute(sqlInsert)
                    sqlSelect = "select * from datetime_db"
                    self.cur.execute(sqlSelect)
                    for i in range(rowNum):
                        data = self.cur.fetchone()
                        self.assertEquals(dataList[i], data[0])
        
            def test_datetime(self):
                    dataList = [datetime.min,datetime.today(),datetime.now(),datetime.max]
                    print ("\ndataList: ",dataList)
                    sqlInsert = "insert into datetime_db(c_datetime) values "
                    for i in dataList:
                        sqlInsert = sqlInsert + "('" + i.isoformat() + "'),"
                    sqlInsert = sqlInsert.rstrip(',')
                    rowNum = self.cur.execute(sqlInsert)
                    sqlSelect = "select * from datetime_db"
                    self.cur.execute(sqlSelect)
                    #for i in range(rowNum):
                    data = self.cur.fetchone()
                    #print data[2]
                    self.assertEquals('0001-01-01 00:00:00', data[2].isoformat(" "))
        
            def test_time(self):
                    dataList = [time.min,time.max]
                    sqlInsert = "insert into datetime_db(c_time) values "
                    for i in dataList:
                        sqlInsert = sqlInsert + "('" + i.isoformat() + "'),"
                    sqlInsert = sqlInsert.rstrip(',')
                    rowNum = self.cur.execute(sqlInsert)
                    sqlSelect = "select * from datetime_db"
                    self.cur.execute(sqlSelect)
                    for i in range(rowNum):
                        data = self.cur.fetchone()
                        self.assertEquals(dataList[i].isoformat().rstrip('9').rstrip('.'), data[1].isoformat())
        
            def test_timestamp(self):
                    dataList = ['10/31','10/31/2008','13:15:45 10/31/2008']
                    dataCheck = ['2013-10-31 00:00:00','2008-10-31 00:00:00','2008-10-31 13:15:45']
                    sqlInsert = "insert into datetime_db(c_timestamp) values "
                    for i in dataList:
                        sqlInsert = sqlInsert + "('" + i + "'),"
                    sqlInsert = sqlInsert.rstrip(',')
                    rowNum = self.cur.execute(sqlInsert)
                    sqlSelect = "select c_timestamp from datetime_db"
                    self.cur.execute(sqlSelect)
                    for i in range(rowNum):
                        data = self.cur.fetchone()
                        self.assertEquals(dataCheck[i], data[0].isoformat(" "))
        
        if __name__ == '__main__':
            suite = unittest.TestLoader().loadTestsFromTestCase(apis_410_test)
            unittest.TextTestRunner(verbosity=2).run(suite)
        
        • Environment:
          • OS: Linux 64
          • Server Version: CUBRID 9.1.0.0212
          • Driver Version: cubrid-python-9.1.0.p1.tar.gz (2013-05-22)
        • Result: Pass
        Show
        ryin005 Ray Yin added a comment - - edited Python isoformat() returns a string representing the date/time/datetime in ISO 8601 format http://docs.python.org/2/library/datetime.html data = self.cur.fetchone() returns a python date/time/datetime object, but not in ISO 8601 format So modified the case as follows: import unittest import CUBRIDdb import locale import time import datetime from datetime import time from datetime import date from datetime import datetime from xml.dom import minidom class apis_410_test(unittest.TestCase): def setUp(self): conStr="CUBRID:localhost:33188:test_python:::" self.con = CUBRIDdb.connect(conStr, "dba","") self.cur = self.con.cursor() self.con.set_autocommit(True) self.cur.execute("DROP TABLE IF EXISTS datetime_db") self.cur.execute("CREATE TABLE datetime_db(c_date date, c_time time, c_datetime datetime, c_timestamp timestamp)") def tearDown(self): self.cur.close self.con.close def test_date(self): dataList = [date.min,date.today(),date.max] sqlInsert = "insert into datetime_db(c_date) values " for i in dataList: sqlInsert = sqlInsert + "('" + i.isoformat() + "')," sqlInsert = sqlInsert.rstrip(',') rowNum = self.cur.execute(sqlInsert) sqlSelect = "select * from datetime_db" self.cur.execute(sqlSelect) for i in range(rowNum): data = self.cur.fetchone() self.assertEquals(dataList[i], data[0]) def test_datetime(self): dataList = [datetime.min,datetime.today(),datetime.now(),datetime.max] print ("\ndataList: ",dataList) sqlInsert = "insert into datetime_db(c_datetime) values " for i in dataList: sqlInsert = sqlInsert + "('" + i.isoformat() + "')," sqlInsert = sqlInsert.rstrip(',') rowNum = self.cur.execute(sqlInsert) sqlSelect = "select * from datetime_db" self.cur.execute(sqlSelect) #for i in range(rowNum): data = self.cur.fetchone() #print data[2] self.assertEquals('0001-01-01 00:00:00', data[2].isoformat(" ")) def test_time(self): dataList = [time.min,time.max] sqlInsert = "insert into datetime_db(c_time) values " for i in dataList: sqlInsert = sqlInsert + "('" + i.isoformat() + "')," sqlInsert = sqlInsert.rstrip(',') rowNum = self.cur.execute(sqlInsert) sqlSelect = "select * from datetime_db" self.cur.execute(sqlSelect) for i in range(rowNum): data = self.cur.fetchone() self.assertEquals(dataList[i].isoformat().rstrip('9').rstrip('.'), data[1].isoformat()) def test_timestamp(self): dataList = ['10/31','10/31/2008','13:15:45 10/31/2008'] dataCheck = ['2013-10-31 00:00:00','2008-10-31 00:00:00','2008-10-31 13:15:45'] sqlInsert = "insert into datetime_db(c_timestamp) values " for i in dataList: sqlInsert = sqlInsert + "('" + i + "')," sqlInsert = sqlInsert.rstrip(',') rowNum = self.cur.execute(sqlInsert) sqlSelect = "select c_timestamp from datetime_db" self.cur.execute(sqlSelect) for i in range(rowNum): data = self.cur.fetchone() self.assertEquals(dataCheck[i], data[0].isoformat(" ")) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(apis_410_test) unittest.TextTestRunner(verbosity=2).run(suite) Environment: OS: Linux 64 Server Version: CUBRID 9.1.0.0212 Driver Version: cubrid-python-9.1.0.p1.tar.gz (2013-05-22) Result: Pass

          People

          • Assignee:
            jinhu 李金虎
            Reporter:
            cn14130 欧明宝[Bom Owen]
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: