DbCommand.ExecuteReader()

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
steph215
Posts: 1
Joined: Mon 29 Oct 2012 17:17

DbCommand.ExecuteReader()

Post by steph215 » Mon 29 Oct 2012 18:30

I'm working on a project which uses ODBC driver for database connection, and now I'm trying to replace that with Devart dotConnect for mySQL. I have the following lines of code where strQuery can be anything such as a SELECT statement from a VIEW or a SELECT statement from joined tables.


DbDataReader dreader = null;
DbCommand cmd = getCommand();
cmd.CommandText = strQuery;
cmd.Connection = dbConn;
dreader = cmd.ExecuteReader(CommandBehavior.Keyinfo);
DataTable.Load(dreader);

private DbCommand getCommand(){
if (CONNECTION_PROVIDER == "Devart.Data.MySql")
{
Devart.Data.MySql.MySqlCommand cmd = (Devart.Data.MySql.MySqlCommand)dbfactory.CreateCommand();
cmd.FetchAll = true;
return cmd;
}
else if (CONNECTION_PROVIDER == "ODBC"){
...
}
}


When I run the application, I checked the schemaTable of dreader and I get the following results.
Running with Devart and CommandBehavior.Keyinfo:
-ColumnName = ACCOUNT_ID
-IsUnique = False
-IsKey = True
Running with Devart and CommandBehavior.Default:
-ColumnName = ACCOUNT_ID
-IsUnique = False
-IsKey = True

First of all, I do not understand how dreader picks ACCOUNT_ID as the primary key since I have no primary keys in the view used in my SELECT statement. Secondly, say if ACCOUNT_ID was somehow set to be the primary key, the IsUnique field here should be true whenever IsKey is true, but we see that this is not the case. Lastly, ExecuteReader(CommandBehavior.Default) should not be getting the key info, yet IsKey still returns True here.


However, I get the expected result when running with ODBC. The results are as following.
Running with ODBC and CommandBehavior.Keyinfo:
-ColumnName = ACCOUNT_ID
-IsUnique = True
-IsKey = True
Running with ODBC and CommandBehavior.Default:
-ColumnName = ACCOUNT_ID
-IsUnique = False
-IsKey = False


What am I missing here? Please help. Thanks.

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Re: DbCommand.ExecuteReader()

Post by Pinturiccio » Thu 01 Nov 2012 11:47

We have reproduced the issue. We will investigate it and notify you about the results as soon as possible.

Post Reply