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

[Python] Rollback has no effect after insert data

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Python-Apricot
    • Fix Version/s: Python 9.1.0.p1
    • Component/s: Python Driver
    • Labels:
    • Environment:

      Linux NC-PL-QA030 2.6.18-194.el5xen #1 SMP Fri Apr 2 15:34:40 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux

      Description

      [Python] Rollback has no effect after insert data:
      Path: _07_execute/execute_rollback.py

      Test version:

      Python Driver:
      http://svn.cubrid.org/cubridapis/python/branches/RB-9.0.0/ Revision: 852
      

      codes:

                      self.con.rollback()
                      self.cur.execute("select * from issue where nameid=6")
                      self.value=self.cur.fetchone()
                      print("after rollback: ",self.value[0],self.value[1],self.value[2])
                      self.assertEquals(len(self.value),0)
      

      Result:

      FAIL: test_rollback (__main__.RollbackTest)
      ----------------------------------------------------------------------
      Traceback (most recent call last):
      test_rollback (__main__.RollbackTest) ... 
      statement is right
      ('before rollback: ', 6, 66, 'forrollback')
      
      rollback
      ('after rollback: ', 6, 66, 'forrollback')
      FAIL
      
        File "execute_rollback.py", line 45, in test_rollback
          self.assertEquals(len(self.value),0)
      AssertionError: 3 != 0
      

      After rollback, the data still exist

        Activity

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

        http://www.python.org/dev/peps/pep-0249/

        Connection methods:
        .commit()
        Commit any pending transaction to the database.

        Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on.

        Database modules that do not support transactions should implement this method with void functionality.

        .rollback()
        This method is optional since not all databases provide transaction support. [3]

        In case a database does provide transactions this method causes the database to roll back to the start of any pending transaction. Closing a connection without committing the changes first will cause an implicit rollback to be performed.
        .cursor()

        Show
        cn15800 谢韦华[Bert] added a comment - http://www.python.org/dev/peps/pep-0249/ Connection methods: .commit() Commit any pending transaction to the database. Note that if the database supports an auto-commit feature, this must be initially off. An interface method may be provided to turn it back on. Database modules that do not support transactions should implement this method with void functionality. .rollback() This method is optional since not all databases provide transaction support. [3] In case a database does provide transactions this method causes the database to roll back to the start of any pending transaction. Closing a connection without committing the changes first will cause an implicit rollback to be performed. .cursor()
        Hide
        cn15800 谢韦华[Bert] added a comment -

        Turn auto-commit:

        con.set_autocommit('ON')

        Show
        cn15800 谢韦华[Bert] added a comment - Turn auto-commit: con.set_autocommit('ON')
        Hide
        cn15800 谢韦华[Bert] added a comment -

        Current Data:
        xieweihua@ubuntu:/mnt/hgfs/python_test/pytest$ python main.py
        [u'8']
        [u'8']
        [u'8']
        [u'0']
        [u'0']

        After insert and rollback:

        xieweihua@ubuntu:/mnt/hgfs/python_test/pytest$ python main.py
        [u'8']
        [u'8']
        [u'8']
        [u'0']
        [u'0']

        Show
        cn15800 谢韦华[Bert] added a comment - Current Data: xieweihua@ubuntu:/mnt/hgfs/python_test/pytest$ python main.py [u'8'] [u'8'] [u'8'] [u'0'] [u'0'] After insert and rollback: xieweihua@ubuntu:/mnt/hgfs/python_test/pytest$ python main.py [u'8'] [u'8'] [u'8'] [u'0'] [u'0']
        Hide
        ryin005 Ray Yin added a comment - - edited

        Test the issue by the below case:

        • Environment:
          • OS: Linux 64/32, Windows 64/32
          • Server Version: CUBRID 9.1.0.0212 (Linux 64/32, windows 64/32)
          • Driver Version: cubrid-python-9.1.0.p1.tar.gz (2013-05-22)
        • Test Code
          import unittest
          import CUBRIDdb
          import datetime
          import locale
          from xml.dom import minidom
          
          class RollbackTest(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(False)
                          self.assertEqual(self.con.get_autocommit(), False, "autocommit is off")
                          self.cur.execute("DROP TABLE IF EXISTS issue")
                          self.cur.execute("CREATE TABLE issue(nameid int primary key ,age int,name VARCHAR(40))")
                          self.cur.execute("INSERT INTO issue (name,nameid,age) VALUES('Mike',1,30),('John',2,28),('Bill',3,45)")
                          self.con.commit()
          
              def tearDown(self):
                          self.cur.close
                          self.con.close
                          
              def test_insert_rollback(self):
                          print "\ntest insert data with rollback"
                          self.cur.execute("INSERT INTO issue (name,nameid,age) VALUES('forrollback',6,66)")
                          self.cur.execute("select * from issue where nameid=6")
                          rows = self.cur.fetchall()
                          print ("before rollback data", rows)
                          self.assertEquals(len(rows),1)
                          
                          print "\nrollback"
                          self.con.rollback()
                          self.cur.execute("select * from issue where nameid=6")
                          rows = self.cur.fetchall()
                          print ("after rollback data", rows)
                          self.con.commit()
                          self.assertEquals(len(rows),0)
                      
          if __name__ == '__main__':
              suite = unittest.TestLoader().loadTestsFromTestCase(RollbackTest)
              unittest.TextTestRunner(verbosity=2).run(suite)
          
        • Description: test insert transaction either with rollback or without rollback
        • Result: Pass
        Show
        ryin005 Ray Yin added a comment - - edited Test the issue by the below case: Environment: OS: Linux 64/32, Windows 64/32 Server Version: CUBRID 9.1.0.0212 (Linux 64/32, windows 64/32) Driver Version: cubrid-python-9.1.0.p1.tar.gz (2013-05-22) Test Code import unittest import CUBRIDdb import datetime import locale from xml.dom import minidom class RollbackTest(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(False) self.assertEqual(self.con.get_autocommit(), False, "autocommit is off") self.cur.execute("DROP TABLE IF EXISTS issue") self.cur.execute("CREATE TABLE issue(nameid int primary key ,age int,name VARCHAR(40))") self.cur.execute("INSERT INTO issue (name,nameid,age) VALUES('Mike',1,30),('John',2,28),('Bill',3,45)") self.con.commit() def tearDown(self): self.cur.close self.con.close def test_insert_rollback(self): print "\ntest insert data with rollback" self.cur.execute("INSERT INTO issue (name,nameid,age) VALUES('forrollback',6,66)") self.cur.execute("select * from issue where nameid=6") rows = self.cur.fetchall() print ("before rollback data", rows) self.assertEquals(len(rows),1) print "\nrollback" self.con.rollback() self.cur.execute("select * from issue where nameid=6") rows = self.cur.fetchall() print ("after rollback data", rows) self.con.commit() self.assertEquals(len(rows),0) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(RollbackTest) unittest.TextTestRunner(verbosity=2).run(suite) Description: test insert transaction either with rollback or without rollback Result: Pass

          People

          • Assignee:
            cn15800 谢韦华[Bert]
            Reporter:
            cn14130 欧明宝[Bom Owen]
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Due:
              Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 2 days
              2d
              Remaining:
              Remaining Estimate - 2 days
              2d
              Logged:
              Time Spent - Not Specified
              Not Specified