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

[ADO.NET] DBNull.Value should be returned by CUBRIDCommand.ExecuteScalar() when the query result is null

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: ADONET-Aprium, ADONET-9.1.0
    • Fix Version/s: ADO.NET 9.2.0.0001
    • Component/s: ADO.NET
    • Labels:

      Description

      Description:
      DBNull.Value should be returned by CUBRIDCommand.ExecuteScalar() when the query result is null. Now CUBRIDCommand.ExecuteScalar() throws an unhandled exception.
      Refer to msdn: http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.executescalar.aspx

      Test case is like this:

                      cmd.CommandText = "select * from tablenotexist";
                      obj = cmd.ExecuteScalar();
      
                      Assert.AreEqual(DBNull.Value, obj);
      

        Activity

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

        1)If table is not exist,driver will throw exception.

        2)If the first column of the first row in the result set is not found(The table is empty),driver will return null(not DBNull.Value).

        3) If the value in the database is null, the query returns DBNull.Value,for example:

        {code}
        select * from aa;

        === <Result of SELECT Command in Line 4> ===

        id
        =============
        NULL{code}
        Show
        cn15800 谢韦华[Bert] added a comment - - edited 1)If table is not exist,driver will throw exception. 2)If the first column of the first row in the result set is not found(The table is empty),driver will return null(not DBNull.Value). 3) If the value in the database is null, the query returns DBNull.Value,for example: {code} select * from aa; === <Result of SELECT Command in Line 4> === id ============= NULL{code}
        Hide
        ryin005 Ray Yin added a comment -
        • Test OS: win 32bit
        • CUBRID: 9.2.0.0149
        • Driver: cubrid-ado.net 9.2.0.0001 (20130911)
        • Framework: .NET 4.0
        • Test Code
          LogTestStep("Test ExecuteScalar - return null");
          cmd.CommandText = "drop table if exists test_scalar;";
          cmd.ExecuteNonQuery();
          cmd.CommandText = "create table test_scalar(a int);";
          cmd.ExecuteNonQuery();
          cmd.CommandText = "insert into test_scalar values(NULL);";
          cmd.ExecuteNonQuery();
          
          cmd.CommandText = "select * from test_scalar";
          obj = cmd.ExecuteScalar();
          Assert.AreEqual(DBNull.Value, obj);
          

        Test Result : Pass

        Show
        ryin005 Ray Yin added a comment - Test OS: win 32bit CUBRID: 9.2.0.0149 Driver: cubrid-ado.net 9.2.0.0001 (20130911) Framework: .NET 4.0 Test Code LogTestStep("Test ExecuteScalar - return null"); cmd.CommandText = "drop table if exists test_scalar;"; cmd.ExecuteNonQuery(); cmd.CommandText = "create table test_scalar(a int);"; cmd.ExecuteNonQuery(); cmd.CommandText = "insert into test_scalar values(NULL);"; cmd.ExecuteNonQuery(); cmd.CommandText = "select * from test_scalar"; obj = cmd.ExecuteScalar(); Assert.AreEqual(DBNull.Value, obj); Test Result : Pass

          People

          • Assignee:
            cn15800 谢韦华[Bert]
            Reporter:
            cn15701 cuiman
            CC (Referrer):
            cuiman, Kai Yang (Inactive), 李应
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: