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

[ODBC] The OdbcReader GetString() doesn't work correctly if withdraw a bit data

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: ODBC-9.2.0.0001
    • Fix Version/s: None
    • Component/s: ODBC
    • Labels:
    • Environment:
      • OS: Windows 7 32bit
      • CUBRID: 9.2.0.0108
      • ODBC: cubrid-odbc 9.2.0 (2013-07-25)
      • .NET: 4.0 framework, VS2010

      Description

      • Brief: The OdbcReader GetString() doesn't return a correct string value when withdrawing a bit data, it always append an extra '0' if the bit column length is not a multiple of 8

      For example

      {code}
      string strConn = @"Driver={CUBRID Driver};db_name=test_odbc;uid=dba;pwd=;server=10.34.64.57;port=33069;fetch_size=100;charset=UTF-8;";
      OdbcConnection connCubrid = new OdbcConnection(strConn);
      connCubrid.Open();

      OdbcCommand odbc_command = new OdbcCommand("", connCubrid);

      // Test 1: GetString() from BIT(4)
      string strCreateTable = "CREATE TABLE t_type_bit1(f_bit BIT(4))";
      odbc_command.CommandText = strCreateTable;
      odbc_command.ExecuteNonQuery();

      string strSqlInsert = " INSERT INTO t_type_bit1 VALUES(B'1010')";
      odbc_command.CommandText = strSqlInsert;
      odbc_command.ExecuteNonQuery();

      string strSqlSelect = "SELECT f_bit FROM t_type_bit1";
      odbc_command.CommandText = strSqlSelect;
      OdbcDataReader odbcReader = odbc_command.ExecuteReader();
      odbcReader.Read();
      Console.WriteLine(odbcReader.GetString(0));
      odbcReader.Close();

      // Test 2: GetString() from BIT(8)
      strCreateTable = "CREATE TABLE t_type_bit2(f_bit BIT(8))";
      odbc_command.CommandText = strCreateTable;
      odbc_command.ExecuteNonQuery();

      strSqlInsert = " INSERT INTO t_type_bit2 VALUES(B'1010')";
      odbc_command.CommandText = strSqlInsert;
      odbc_command.ExecuteNonQuery();

      strSqlSelect = "SELECT f_bit FROM t_type_bit2";
      odbc_command.CommandText = strSqlSelect;
      odbcReader = odbc_command.ExecuteReader();
      odbcReader.Read();
      Console.WriteLine(odbcReader.GetString(0));
      odbcReader.Close();

      // Test 3: GetString() from BIT(12)
      strCreateTable = "CREATE TABLE t_type_bit3(f_bit BIT(12))";
      odbc_command.CommandText = strCreateTable;
      odbc_command.ExecuteNonQuery();

      strSqlInsert = " INSERT INTO t_type_bit3 VALUES(B'1010')";
      odbc_command.CommandText = strSqlInsert;
      odbc_command.ExecuteNonQuery();

      strSqlSelect = "SELECT f_bit FROM t_type_bit3";
      odbc_command.CommandText = strSqlSelect;
      odbcReader = odbc_command.ExecuteReader();
      odbcReader.Read();
      Console.WriteLine(odbcReader.GetString(0));
      odbcReader.Close();{code}

      Actual Output:

      A0
      A0
      A000
      

      Expected Ouput:

      A
      A0
      A00
      
      • Csql Output:
        csql> select f_bit from t_type_bit1;
        
          f_bit               
        ======================
          X'a'
        
        csql> select f_bit from t_type_bit2;
        
          f_bit               
        ======================
          X'a0'       
        
        csql> select f_bit from t_type_bit3;
        
          f_bit               
        ======================
          X'a00'              
                          
        

        Activity

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

        This is cci's bug:

        char* buf;
        cci_get_data(req, i, CCI_A_TYPE_STR, &buf, &ind) result: t_type_bit1:(char*)a0
        cci_get_data(req, i, CCI_A_TYPE_STR, &buf, &ind) result: t_type_bit2:(char*)a0

        T_CCI_BIT bBuf;
        cci_get_data(req, i, CCI_A_TYPE_BIT, &bBuf, &ind) result: t_type_bit1:b'a0'
        cci_get_data(req, i, CCI_A_TYPE_BIT, &bBuf, &ind) result: t_type_bit2:b'a0'

        ODBC framework(not driver) will pass data type as string even if the actual type is bit, so odbc driver need to call

        {code}
        cci_get_data(req, i, CCI_A_TYPE_STR, &buf, &ind) {code}

        to get bit data.

        Show
        cn15800 谢韦华[Bert] added a comment - - edited This is cci's bug: char* buf; cci_get_data(req, i, CCI_A_TYPE_STR, &buf, &ind) result: t_type_bit1:(char*)a0 cci_get_data(req, i, CCI_A_TYPE_STR, &buf, &ind) result: t_type_bit2:(char*)a0 T_CCI_BIT bBuf; cci_get_data(req, i, CCI_A_TYPE_BIT, &bBuf, &ind) result: t_type_bit1:b'a0' cci_get_data(req, i, CCI_A_TYPE_BIT, &bBuf, &ind) result: t_type_bit2:b'a0' ODBC framework(not driver) will pass data type as string even if the actual type is bit, so odbc driver need to call {code} cci_get_data(req, i, CCI_A_TYPE_STR, &buf, &ind) {code} to get bit data.

          People

          • Assignee:
            cn15800 谢韦华[Bert]
            Reporter:
            ryin005 Ray Yin
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: