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

[OLEDB]if use Reader.GetBoolean to get a bit data, it will throw an exception

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: OLEDB-9.1.0.p1
    • Fix Version/s: OLEDB-9.1.0.p1
    • Component/s: OLEDB
    • Labels:
      None
    • Environment:
      • OS: Window7 32bit
      • Server Version:CUBRID 9.1 (9.1.0.0212) (64bit release build for linux_gnu) (Mar 14 2013 00:16:33)
      • Driver Version:OLEDB driver 9.1 (timestamp:20130422-14175366)

      Description

      • Brief:
        • if use Reader.GetBoolean to get a bit data, it will throw an exception
        • Excetion: System.InvalidCastException : 由于符号不匹配或数据溢出以外的其他原因,未能转换数据值。例如,数据在数据存储区中已损坏,但该行仍可以检索。
      • Test Code
        public void DataReader_GetBoolean_Bit(){
        	string strTable = "t_type_bit";
        	string strConnection="Provider=CUBRIDProvider;Data Source=testdb;Location=127.0.0.1;User ID=dba;Password=xxx;Port= 33000"
                string strCreateTable = string.Format("Create table {0}(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,f_bit bit)", strTable);
                    string strDropTable = string.Format("Drop table {0}", strTable);
                    string strInsert = string.Format("insert into {0} value(NULL,{1})", strTable, "B'0'");
                    string strSelect = string.Format("select * from {0} order by id desc", strTable);
                    OleDbConnection connCubrid = new OleDbConnection(strConnection);
        
                    ReaderDataPrepare(connCubrid, new string[] { strDropTable, strCreateTable, strInsert });
        
                    OleDbCommand cmdCubrid = new OleDbCommand(strSelect, connCubrid);
        	    OleDbDataReader reader = cmdCubrid.ExecuteReader();
        						reader.Read();
        				reader.Read(); 
                        Assert.AreEqual(0, reader.GetBoolean(1));
        	   }
        
        private void ReaderDataPrepare(OleDbConnection conn, params string[] cmdText)
                {
                    for (int i = 0; i < cmdText.Length; i++)
                    {
                        try
                        {
                            ExecuteNonQuery(conn, cmdText[i]);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }
        
        	
        public static int ExecuteNonQuery(OleDbConnection conn,string strSql)
                {
                    OleDbCommand cmd = new OleDbCommand(strSql, conn);
                    try
                    {
                        return cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        cmd.Dispose();
                        Console.WriteLine("Exception of ExecuteNonQuery: " + ex.Message);
                    }
        
                    return -1;
                }
        

        Activity

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

        Bool is not bit.

        Bool is a class in c#.

        for example:

        bool fb;
        int a = 0;
        fb = a;

        F:\03CUBRID\05Driver\issues\apis-535\apis-535\Program.cs(87,18): error CS0029: Cannot implicitly convert type 'int' to 'bool'

        Class can not convert to bit.

        Show
        cn15800 谢韦华[Bert] added a comment - Bool is not bit. Bool is a class in c#. for example: bool fb; int a = 0; fb = a; F:\03CUBRID\05Driver\issues\apis-535\apis-535\Program.cs(87,18): error CS0029: Cannot implicitly convert type 'int' to 'bool' Class can not convert to bit.
        Hide
        cn15800 谢韦华[Bert] added a comment -

        I have test the problem with mysql oledb driver.

        Error message:
        Unhandled Exception: System.InvalidCastException: Specified cast is not valid.
        at System.Data.OleDb.ColumnBinding.ValueBoolean()
        at System.Data.OleDb.OleDbDataReader.GetBoolean(Int32 ordinal)
        at oledb_test.Program.DataReader_GetBoolean_Bit() in F:\03CUBRID\05Driver\iss
        ues\apis-535\apis-535\Program.cs:line 34
        at oledb_test.Program.Main(String[] args) in F:\03CUBRID\05Driver\issues\apis
        -535\apis-535\Program.cs:line 106

        Show
        cn15800 谢韦华[Bert] added a comment - I have test the problem with mysql oledb driver. Error message: Unhandled Exception: System.InvalidCastException: Specified cast is not valid. at System.Data.OleDb.ColumnBinding.ValueBoolean() at System.Data.OleDb.OleDbDataReader.GetBoolean(Int32 ordinal) at oledb_test.Program.DataReader_GetBoolean_Bit() in F:\03CUBRID\05Driver\iss ues\apis-535\apis-535\Program.cs:line 34 at oledb_test.Program.Main(String[] args) in F:\03CUBRID\05Driver\issues\apis -535\apis-535\Program.cs:line 106
        Hide
        cn15800 谢韦华[Bert] added a comment - - edited

        after modify, There is not Overflow,but you can,t get bit by GetBoolean.
        you should get data as follow:

        Byte[] value = new Byte[1];
        reader.GetBytes(0, 0, value, 0, 1);

        There is a new problem:
        1. insert into t value(1,B'1');
        2. select * from t;
        result:
        128 or 0x80

        you can inquiry by cubrid manager, it is same result. i found the data(0x80) which return by cci.so it is not the oledb/odbc driver's problem

        Show
        cn15800 谢韦华[Bert] added a comment - - edited after modify, There is not Overflow,but you can,t get bit by GetBoolean. you should get data as follow: Byte[] value = new Byte [1] ; reader.GetBytes(0, 0, value, 0, 1); There is a new problem: 1. insert into t value(1,B'1'); 2. select * from t; result: 128 or 0x80 you can inquiry by cubrid manager, it is same result. i found the data(0x80) which return by cci.so it is not the oledb/odbc driver's problem

          People

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

            Dates

            • Created:
              Updated:
              Resolved: