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

[Python] Fetchone get bit varying data is not correct

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: Python 9.1.0.p1
    • Component/s: Python Driver
    • Labels:
      None
    • Environment:
      1. CUBRID: 2008 R4.1 (8.4.1.0561) (64bit release build for linux_gnu)
      2. OS: Linux 64bit

      Description

      1. Brief:
        1. Insert bit data B'1' into database and use fetchone method to get the data, but the return data is not correct.
      2. Test Steps:
        1. insert a bit data B'1' into table
        2. select the data and check it
      3. Result:
        1. Expect result is '8'
        2. Actual result is '80'
      4. Code reference:
        import CUBRIDdb
        import unittest
        
        class FetchoneTest(unittest.TestCase):
                def test_bit(self):
                        self.con = CUBRIDdb.connect("CUBRID:localhost:33011:demodb", "dba","")
                        self.cur = self.con.cursor()
                        sqlCreate = "create table bit_db(c_bit bit varying(8))"
                        self.cur.execute(sqlCreate)
                        data = 'B\'1\''
                        dataCheck = '8'
                        sqlInsert = "insert into bit_db(c_bit) values (" +data +")"
                        self.cur.execute(sqlInsert)
                        sqlSelect = "select * from bit_db"
                        self.cur.execute(sqlSelect)
                        dataReturn = self.cur.fetchone()
                        self.assertEquals(dataCheck, dataReturn[0])
        
        if __name__ == '__main__':
                unittest.main()
        

        Activity

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

        When data type is bit,we process it as string.

        The Implementation function:_cubrid_CursorObject_dbval_to_pyvalue

        The exactly data type should be CCI_A_TYPE_BIT

        Show
        cn15800 谢韦华[Bert] added a comment - When data type is bit,we process it as string. The Implementation function:_cubrid_CursorObject_dbval_to_pyvalue The exactly data type should be CCI_A_TYPE_BIT
        Hide
        cn15800 谢韦华[Bert] added a comment - - edited

        Attachment is screenshot that the value return by cci

        Show
        cn15800 谢韦华[Bert] added a comment - - edited Attachment is screenshot that the value return by cci
        Hide
        cn15800 谢韦华[Bert] added a comment -

        Python can not support get data type of bit, so now we process bit as string.

        If the value is b'1', cci will return '80'.

        So we will set result as '\0' when value is '0'.

        Show
        cn15800 谢韦华[Bert] added a comment - Python can not support get data type of bit, so now we process bit as string. If the value is b'1', cci will return '80'. So we will set result as '\0' when value is '0'.
        Hide
        cn15800 谢韦华[Bert] added a comment -

        c.execute("drop table t_bit")
        c.execute('create table t_bit(v bit(128))')
        c.execute('''insert into t_bit(v) values(B'111111111111')''')

        result:
        [u'FFF']

        Show
        cn15800 谢韦华[Bert] added a comment - c.execute("drop table t_bit") c.execute('create table t_bit(v bit(128))') c.execute('''insert into t_bit(v) values(B'111111111111')''') result: [u'FFF']
        Hide
        cn15800 谢韦华[Bert] added a comment -

        result:

        [u'8']
        [u'8']
        [u'8']
        [u'0']
        [u'0']

        Show
        cn15800 谢韦华[Bert] added a comment - result: [u'8'] [u'8'] [u'8'] [u'0'] [u'0']
        Hide
        ryin005 Ray Yin added a comment -

        I have tested the same problem on ODBC driver, it also returns the same results (i.e. b'1' returns '80', b'1111' returns 'f0')

        So the returned (bit data) value is obtained from CCI and is treated as a string

        ODBC Test case:

        [Test, Description("Test APIs issue 92 on ODBC-9.1.0")]
        public void ReviewIssueTest_APIs92()
        {
            string strConn = @"Driver={CUBRID Driver};db_name=test_python;uid=dba;pwd=;server=10.34.64.61;port=33188;fetch_size=100;charset=UTF-8;";
            OdbcConnection connCubrid = new OdbcConnection(strConn);
            connCubrid.Open();
        
            string testTable = "bit_db2";
            string data = "B\'1\'";
            string data2 = "B\'1111\'";
            string data3 = "B\'11111111\'";
            string strCreateTable = string.Format("CREATE TABLE {0}(c_bit bit varying(12))", testTable);
            string strDropTable = string.Format("DROP TABLE IF EXISTS {0}", testTable);
            string strSqlInsert = string.Format("INSERT INTO {0}(c_bit) VALUE({1})", testTable, data);
            string strSqlInsert2 = string.Format("INSERT INTO {0}(c_bit) VALUE({1})", testTable, data2);
            string strSqlInsert3 = string.Format("INSERT INTO {0}(c_bit) VALUE({1})", testTable, data3);
        
            ExecuteMultiQueries(connCubrid, new string[] { strDropTable, strCreateTable, strSqlInsert, strSqlInsert2, strSqlInsert3 });
        
            string strSqlSelect = string.Format("SELECT * FROM {0};", testTable);
        
            OdbcCommand command = new OdbcCommand();
            command.Connection = connCubrid;
            command.CommandText = strSqlSelect;
        
            OdbcDataReader odbcReader = command.ExecuteReader();
            while (odbcReader.Read())
            {
                Console.WriteLine(odbcReader.GetString(0));
            }
        
            connCubrid.Close();
        
        }
        

        Results: '80' 'F0' 'FF'

        Summary: the test results are identical between the CUBRID drivers, so it is not a python driver's bug

        Show
        ryin005 Ray Yin added a comment - I have tested the same problem on ODBC driver, it also returns the same results (i.e. b'1' returns '80', b'1111' returns 'f0') So the returned (bit data) value is obtained from CCI and is treated as a string ODBC Test case: [Test, Description("Test APIs issue 92 on ODBC-9.1.0")] public void ReviewIssueTest_APIs92() { string strConn = @"Driver={CUBRID Driver};db_name=test_python;uid=dba;pwd=;server=10.34.64.61;port=33188;fetch_size=100;charset=UTF-8;"; OdbcConnection connCubrid = new OdbcConnection(strConn); connCubrid.Open(); string testTable = "bit_db2"; string data = "B\'1\'"; string data2 = "B\'1111\'"; string data3 = "B\'11111111\'"; string strCreateTable = string.Format("CREATE TABLE {0}(c_bit bit varying(12))", testTable); string strDropTable = string.Format("DROP TABLE IF EXISTS {0}", testTable); string strSqlInsert = string.Format("INSERT INTO {0}(c_bit) VALUE({1})", testTable, data); string strSqlInsert2 = string.Format("INSERT INTO {0}(c_bit) VALUE({1})", testTable, data2); string strSqlInsert3 = string.Format("INSERT INTO {0}(c_bit) VALUE({1})", testTable, data3); ExecuteMultiQueries(connCubrid, new string[] { strDropTable, strCreateTable, strSqlInsert, strSqlInsert2, strSqlInsert3 }); string strSqlSelect = string.Format("SELECT * FROM {0};", testTable); OdbcCommand command = new OdbcCommand(); command.Connection = connCubrid; command.CommandText = strSqlSelect; OdbcDataReader odbcReader = command.ExecuteReader(); while (odbcReader.Read()) { Console.WriteLine(odbcReader.GetString(0)); } connCubrid.Close(); } Results: '80' 'F0' 'FF' Summary: the test results are identical between the CUBRID drivers, so it is not a python driver's bug

          People

          • Assignee:
            cn15800 谢韦华[Bert]
            Reporter:
            guorui 郭瑞
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: