[Mono-list] How do you debug?

Ivan Hawkes blackhawk@ivanhawkes.com
Sat, 5 Jul 2003 00:39:04 +0100


=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 04 Jul 2003 11:06 pm, Miguel de Icaza wrote:
> Lets examine the problem a bit more, because I was as perplexed as you
> were that a conversion from int to int would throw that exception.
>
> What is happening here is that "reader.GetOrdinal
> ("RealContentItemId")" returns an integer.
>
> And here is the problem: the returned int is used as the ColumnValue
> *key* whose value happens to be something different.
>
> Am not a System.Data expert, but this is either a bug on the original
> runtime, or there is a miss-conception in the
> System.Data.SqlClient.GetValue code.
>
> I added some extra information to the exception on CVS
>
> Miguel

Ok, I dropped in more test code again, like so:

Console.WriteLine ("Ord=3D{0}, Value=3D{1}",=20
reader.GetOrdinal("RealContentItemId"),=20
reader.GetOrdinal("RealContentItemId").GetType ());
Console.WriteLine ("Ord=3D{0}, Value=3D{1}",=20
reader.GetOrdinal("OriginalVersionId"),=20
reader.GetOrdinal("OriginalVersionId").GetType ());

Console.WriteLine ("Ord=3D{0}, Value=3D{1}",=20
reader.GetOrdinal("RealContentItemId"), reader.GetDataTypeName=20
(reader.GetOrdinal("RealContentItemId")));
Console.WriteLine ("Ord=3D{0}, Value=3D{1}",=20
reader.GetOrdinal("OriginalVersionId"), reader.GetDataTypeName=20
(reader.GetOrdinal("OriginalVersionId")));

which produced the following results:

Ord=3D2, Value=3DSystem.Int32
Ord=3D1, Value=3DSystem.Int32
Ord=3D2, Value=3Dint
Ord=3D1, Value=3Dint

So it appears as if what is coming back from GetOrdinal is a System.Int32, =
but=20
GetDataTypeName seems to think of it as an Int. In any case, a conversion=20
from System.Int32 or an Int to an Int should not cause any issues. So, a=20
quick check of other things to go wrong has led to the actual culprit.

These lines of code fail:

if (reader.GetValue(reader.GetOrdinal("RealContentItemId")) =3D=3D DBNull.V=
alue)
	uniqueId =3D reader.GetInt32 (reader.GetOrdinal("OriginalVersionId"));
else
	uniqueId =3D reader.GetInt32 (reader.GetOrdinal("RealContentItemId"));

because the GetValue function is not actually returning a DBNull.Value and =
so=20
the final line of code executes, which unfortunately contains a NULL in the=
=20
database field. So, it would appear the code for GetValue on either=20
IDataReader or SqlDataReader is faulty. Meanwhile, I better go put those=20
reader.GetInt32 calls back in.
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iQIVAwUBPwYQGPr1e7bH1pzBAQIHzBAAg6x2D6HACeengXqjF7tHIQwcGfMn3cBF
ekWkOxgJATX7gvmSvATyzHrgBKfRuitT6gGklZl05p9crpRXZyIXRUq+QhT2FCsO
STiQwyNnSnEKJcJ4rO76d89SefAwTI0rboYBh087Z0m1zjaPlwwnZgo5dVDC87gq
gli1GomdZifbxW/23OxUlW4NdpEKoOHJ6bDoHzA0xIHygeO56ZaEGphm6QEcx7o3
7bsWvgBjPRbmOyxzI9YK0iO1atog5fPKmWy46ppXC+0mehq8FiVG2k/ihlVskb2c
AXqs0qDw1gUpDPc4AejQ9jOfOV/ybajMISPZRZdLGf6+vnxOOO9teXb+9+NsI8mp
n9AdecXAV7RAeHGeO+sBJLmBytbc9qhbzxb9BeI0Gqu7Mgn6W58411uFSzKQc0J8
3lVauag0IO7HBTwWtuuZZ50BmwT40+OxCmuIPsuVhqIFlrTBV0VeVtqrmPXVk19H
X6q2xx4vcGrheSUVKJRa7In5K5mjhy++R0xvbeSW5asSgLxdZXqQbZCaXZqwlDag
UV/ccfK0QjOAGPMeXl8E3uiRe7yKW3zPysn3MXZCCi0nNcJnKFWc+pCk+rk4PCr0
4CD/QcqobaRCLhKlF9+0VzBL6vO7h+1KQpL/hzXHi1WAr8XWoGu2IPgrOekWjv8c
JD41dOG43mg=3D
=3DMiP5
=2D----END PGP SIGNATURE-----