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

Python CUBRIDdb driver should implement cubrid_set_autocommit/cubrid_get_autocommit

    Details

      Description

      First of all, I used the documentation from here:
      http://packages.python.org/CUBRID-Python/

      and I tried to use the CUBRIDdb driver.

      Currently, rollback/commit functions from the driver cannot be used at all. That's why this bug is critical. It leads to various bugs because cubrid auto_commit mode cannot be enabled or disabled.

      The following functions: cubrid_set_autocommit/cubrid_get_autocommit from the CCI driver should be called in the python driver also.

      The "_cubrid" driver holds most of these functions, but it lacks others. "CUBRIDdb" should support these functions also.

      Here is a test code:

      {code}
      import CUBRIDdb

      con = CUBRIDdb.connect('CUBRID:localhost:33000:demodb', 'dba', '')
      c = con.cursor()

      c.execute("DROP TABLE IF EXISTS posts")
      c.execute("CREATE TABLE posts(id integer,title varchar(255),body string,last_updated timestamp);")
      args = (4, 'ddd', 'CUBRID-Python is Open Source!!')
      c.execute('insert into posts(id, title, body, last_updated) values (?, ?, ?, SYSTIMESTAMP)', args)
      con.rollback()

      c.execute('select * from posts')
      rows = c.fetchall()

      for r in rows:
      print r{code}

      Here is a similar task in PHP (where everything works fine):

      {code}
      $conn = cubrid_connect("localhost", 33000, "demodb", "dba", "");
      cubrid_set_autocommit($conn,CUBRID_AUTOCOMMIT_FALSE);

      cubrid_query("DROP TABLE IF EXISTS tst");
      cubrid_query("CREATE TABLE tst (a INTEGER)");
      cubrid_query("INSERT INTO tst VALUES(1)");
      cubrid_commit($conn);
      cubrid_query("INSERT INTO tst VALUES(2)");
      cubrid_query("INSERT INTO tst VALUES(3)");
      cubrid_rollback($conn);

      cubrid_disconnect($conn);{code}

      In the _cubrid driver there are other very useful functions such as: insert_id(), client_version(), server_version(), set_isolation_level().

      I cannot use _cubrid driver as it is missing "executemany()" and "fetchall()".

      Another useful function would be to get/set the charset used (I am referring to functions that exist in the CCI).

        Activity

        Hide
        jinhu 李金虎 added a comment -

        Hi, Veliscu Ovidiu

        In the Python Database API Specification v2.0(http://www.python.org/dev/peps/pep-0249/), the autocommit should be initially off.
        Note that if the database supports an auto-commit feature, this must be initially off.

        But in Cubrid(8.4.1), the autocommit is ON in default. Considered the compatiblity, we should keep the default autocommit value when user invokes the connect(). If user want to disable the autocommit, the set_autocommit(False) should be invoked. Do you think so?

        Show
        jinhu 李金虎 added a comment - Hi, Veliscu Ovidiu In the Python Database API Specification v2.0( http://www.python.org/dev/peps/pep-0249/ ), the autocommit should be initially off. Note that if the database supports an auto-commit feature, this must be initially off. But in Cubrid(8.4.1), the autocommit is ON in default. Considered the compatiblity, we should keep the default autocommit value when user invokes the connect(). If user want to disable the autocommit, the set_autocommit(False) should be invoked. Do you think so?
        Hide
        ovidiu.veliscu Veliscu Ovidiu added a comment -

        Yes, I agree. The user should call set_autocommit(False) explicitly if he wishes to set the change the default value.

        Show
        ovidiu.veliscu Veliscu Ovidiu added a comment - Yes, I agree. The user should call set_autocommit(False) explicitly if he wishes to set the change the default value.
        Hide
        jinhu 李金虎 added a comment - - edited

        Add set_autocommit() and get_autocommit() in CUBRIDdb.

        The way to Invoke:

        {code}
        con = CUBRIDdb.connect('CUBRID:localhost:33000:demodb', 'dba', '')
        con.set_autocommit(False)
        if con.get_autocommit():
        print "Autocommit is ON"
        else:
        print "Autocommit is OFF"{code}

        Modified:
        CUBRIDdb/connections.py
        test_CUBRIDdb.py
        Committed revision 951. Fixed in 8.4.1.

        Merge into 8.4.3
        Merge into 9.0.0
        Merge into trunk.

        Done.

        Show
        jinhu 李金虎 added a comment - - edited Add set_autocommit() and get_autocommit() in CUBRIDdb. The way to Invoke: {code} con = CUBRIDdb.connect('CUBRID:localhost:33000:demodb', 'dba', '') con.set_autocommit(False) if con.get_autocommit(): print "Autocommit is ON" else: print "Autocommit is OFF"{code} Modified: CUBRIDdb/connections.py test_CUBRIDdb.py Committed revision 951. Fixed in 8.4.1. Merge into 8.4.3 Merge into 9.0.0 Merge into trunk. Done.
        Hide
        jinhu 李金虎 added a comment -

        Resolved

        Show
        jinhu 李金虎 added a comment - Resolved

          People

          • Assignee:
            jinhu 李金虎
            Reporter:
            ovidiu.veliscu Veliscu Ovidiu
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: