[Mono-bugs] [Bug 385025] New: Missing IsNull checks in DbCommandBuilder.Update

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Apr 29 18:46:01 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=385025


           Summary: Missing IsNull checks in DbCommandBuilder.Update
           Product: Mono: Class Libraries
           Version: 1.9.0
          Platform: x86
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.Data
        AssignedTo: bnc-blr-team-mono at forge.provo.novell.com
        ReportedBy: tedu at fogcreek.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


There are some missing IsNull checks.  This results in errors like:

 System.InvalidCastException: Cannot cast from source type to destination type.
  at System.Data.Common.DbCommandBuilder.CreateUpdateCommand (Boolean option)
[0x00000] 
  at System.Data.Common.DbCommandBuilder.GetUpdateCommand () [0x00000] 
  at System.Data.Common.DbCommandBuilder.RowUpdatingHandler
(System.Data.Common.RowUpdatingEventArgs args) [0x00000] 


diff -ru
/home/tedu/orig/mono-1.9.1/mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs
/DbCommandBuilder.cs
---
/home/tedu/orig/mono-1.9.1/mcs/class/System.Data/System.Data.Common/DbCommandBuilder.cs
    2007-11-08 17:13:05.000000000 -0500
+++ ./DbCommandBuilder.cs       2008-04-29 16:42:29.000000000 -0400
@@ -165,7 +166,7 @@

                private bool IncludedInWhereClause (DataRow schemaRow)
                {
-                       if ((bool) schemaRow ["IsLong"])
+                       if (!schemaRow.IsNull ("IsLong") && (bool) schemaRow
["IsLong"])
                                return false;
                        return true;
                }
@@ -186,7 +187,7 @@
                        int parmIndex = 1;

                        foreach (DataRow schemaRow in _dbSchemaTable.Rows) {
-                               if ((bool)schemaRow["IsExpression"] == true)
+                               if (!schemaRow.IsNull ("IsExpression") &&
(bool)schemaRow["IsExpression"] == true)
                                        continue;
                                if (!IncludedInWhereClause (schemaRow))
                                        continue;
@@ -194,7 +195,7 @@
                                if (whereClause.Length > 0)
                                        whereClause.Append (" AND ");

-                               bool isKey = (bool) schemaRow ["IsKey"];
+                               bool isKey = !schemaRow.IsNull ("IsKey") &&
(bool) schemaRow ["IsKey"];
                                DbParameter parameter = null;

                                if (isKey)
@@ -203,8 +204,9 @@
                                //ms.net 1.1 generates the null check for
columns even if AllowDBNull is false
                                //while ms.net 2.0 does not. Anyways, since
both forms are logically equivalent
                                //following the 2.0 approach
-                               bool allowNull = (bool) schemaRow
["AllowDBNull"];
+                               bool allowNull = !schemaRow.IsNull
("AllowDBNull") && (bool) schemaRow ["AllowDBNull"];
                                if (!isKey && allowNull) {
+/*
                                        parameter =
_deleteCommand.CreateParameter ();
                                        if (option) {
                                                parameter.ParameterName =
String.Format ("@{0}",
@@ -338,7 +342,7 @@
                        // Now, create the WHERE clause.  This may be
optimizable, but it would be ugly to incorporate
                        // into the loop above.  "Premature optimization is the
root of all evil." -- Knuth
                        foreach (DataRow schemaRow in _dbSchemaTable.Rows) {
-                               if ((bool) schemaRow ["IsExpression"] == true)
+                               if (!schemaRow.IsNull ("IsExpression") &&
(bool) schemaRow ["IsExpression"] == true)
                                        continue;

                                if (!IncludedInWhereClause (schemaRow))
@@ -347,7 +351,7 @@
                                if (whereClause.Length > 0)
                                        whereClause.Append (" AND ");

-                               bool isKey = (bool) schemaRow ["IsKey"];
+                               bool isKey = !schemaRow.IsNull ("IsKey") &&
(bool) schemaRow ["IsKey"];
                                DbParameter parameter = null;

                                if (isKey)
@@ -356,9 +360,9 @@
                                //ms.net 1.1 generates the null check for
columns even if AllowDBNull is false
                                //while ms.net 2.0 does not. Anyways, since
both forms are logically equivalent
                                //following the 2.0 approach
-                               bool allowNull = (bool) schemaRow
["AllowDBNull"];
+                               bool allowNull = !schemaRow.IsNull
("AllowDBNull") && (bool) schemaRow ["AllowDBNull"];
                                int index;
~


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list