DataTable IsNull() Returns True on zero length strings

DataTable IsNull() Returns True on zero length strings

Postby garychin » Thu 30 Aug 2007 22:59

I have a column of type TEXT and I do a select on that column using either MySqlDataReader to get a reader or MySqlDataAdapter to fill a DataTable, The value returned is a zero length string, but using the reader's IsDBNull(0) and the datatable's method IsNull(0) returns true. They should return false, and only true when NULL is actually being stored in the database. Is there a fix for this or configuration option on the corelab driver to differentiate between these two cases?

Thanks for the help.
garychin
 
Posts: 8
Joined: Thu 30 Aug 2007 22:48

Postby Alexey » Fri 31 Aug 2007 09:02

Which version of MyDirect .NET do you use?
Which method of MySqlDataReader do you use to get value of that column?
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby garychin » Fri 31 Aug 2007 15:29

I am using version 4.0.13.0 of Corelab.MySql.dll and 4.0.11.0 of Corelab.Data.dll.

Here is an example, where column1 has type TEXT. The if statements evaluate to true for zero length strings and null values. It should only happen for Null values. I also wrote statements how I am accessing the data below each if statement in the case of DataTable and MySqlDataReader. Is there a fix for this problem I am having?

MySqlConnection conn = (MySqlConnection)GetConnection();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select column1 FROM table1";

MySqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
if (reader.IsDBNull(0))
MessageBox.Show("Found Null Value");

string temp = reader.GetString(0);
}
reader.Close();


MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);

for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i].IsNull(0))
MessageBox.Show("Found Null Value");

string temp = dt.Rows[i].ItemArray[0].ToString();
}

Thanks again.
garychin
 
Posts: 8
Joined: Thu 30 Aug 2007 22:48

Postby Alexey » Mon 03 Sep 2007 07:20

This is a designed behaviour of MyDirect .NET.
Right decision is to use IsDBNull method first, like you did.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby garychin » Tue 04 Sep 2007 19:55

It seems that IsDBNull and IsNull methods evaluated to true for zero length string values only on embedded databases. When I am running IsDBNull and IsNull on zero length strings on a regular MySQL instance they return false. So the MyDirect.NET driver does not have consistent behavior in regard to zero length strings for embedded databases and a regular non-embedded MySQL instance. Returning false for zero length strings, the way it works in the non-embedded MySQL instance, is desirable for my situation, but I need to use an embedded database. Can you make the behavior consistent across embedded and non-embedded databases or explain why it cannot be this way and give me a workaround for the embedded database. Thank you for your prompt replies.
garychin
 
Posts: 8
Joined: Thu 30 Aug 2007 22:48

Postby Alexey » Wed 05 Sep 2007 11:18

We will investigate this problem and probably fix it.
Look forward to hearing from me soon.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Alexey » Thu 06 Sep 2007 11:10

This problem is fixed.
Look forward to the next build.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby garychin » Thu 06 Sep 2007 17:47

Thank you very much.
garychin
 
Posts: 8
Joined: Thu 30 Aug 2007 22:48

Postby garychin » Mon 10 Sep 2007 15:33

I tested the new build 4.20.18, and this problem is fixed for a regular MySql instance, however embedded database connections (when setting Embedded=true; in the connection string) still causes IsNull to evaluate to true for zero length strings.
garychin
 
Posts: 8
Joined: Thu 30 Aug 2007 22:48

Postby Alexey » Tue 11 Sep 2007 07:52

There was no problem regarding this issue for regular MySQL servers.
The fix for embedded server is not released yet. Please wait a bit.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Alexey » Fri 21 Sep 2007 14:45

Please try new build of MyDirect .NET available for download now!
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for MySQL