Page 1 of 1
ExecuteScalar
Posted: Mon 13 Dec 2004 22:40
by joshmouch
This may sound like a dumb question, but does the MySqlDirect.Net driver support the MysqlCommand.ExecuteScalar function?
I have some very simple code:
Code: Select all
Dim cmd as new MySqlCommand("SELECT 1", connection)
dim i as integer = cmd.ExecuteScalar
The function always returns a 0. This is only one test case I've tried. The more important one is executing "SELECT @@IDENTITY" after an insert, which also returns a 0.
As a reference, I run the same code on Mysql's provider without any problems.
Test case
Posted: Mon 13 Dec 2004 23:33
by joshmouch
I wrote up a test case in .Net 2.0 beta 1 using the latest version of your driver:
Code: Select all
Dim cn As New MySqlConnection("connectionstring")
cn.Open()
Dim cmd As New MySqlCommand("SELECT 1", cn)
Dim i As Integer = cmd.ExecuteScalar
cn.Close()
Console.WriteLine(i)
Console.ReadLine()
This code prints a 0 intead of a 1.
Re: Test case
Posted: Tue 14 Dec 2004 08:51
by Oleg
Thank you for information.
This problem was in beta version but we have already released MySQLDirect .NET 2.70 and it doesn't have this problem.
Re: Test case
Posted: Tue 14 Dec 2004 13:04
by Guest
Thank you for the reply.
I have version 2.70.1.0 of the MySqlDirect.Net Driver, 2.0 beta1 of .Net, and 4.0 of mysql server.
Any other ideas?
Oleg wrote:Thank you for information.
This problem was in beta version but we have already released MySQLDirect .NET 2.70 and it doesn't have this problem.
Re: Test case
Posted: Tue 14 Dec 2004 15:42
by Oleg
The problem is in .NET Framework 2.0 beta. To check it just decompile System.Data.ProviderBase.DbCommandBase.ExecuteScalar method and you can see the next code:
Code: Select all
Public Overrides Function ExecuteScalar() As Object
Using reader1 As IDataReader = MyBase.ExecuteReader
Dim flag1 As Boolean = False
Do
If (0 < reader1.FieldCount) Then
flag1 = True
Exit Do
End If
Loop reader1.NextResult
If (flag1 AndAlso reader1.Read) Then
reader1.GetValue(0)
End If
End Using
Return Nothing
End Function
It always returns Nothing. If this problem remains in the further versions of .NET Framework 2.0 we'll solve it at the level of our provider.
Posted: Thu 16 Dec 2004 15:39
by Guest
I don't think that beta 2 will be out until well into next year. Until then, couldn't you add your own implementation of ExecuteScalar to get it working correctly? Something similar to this:
Code: Select all
public object ExecuteScalar()
{
object val = null;
MySqlDataReader reader = ExecuteReader();
if (reader.Read())
val = reader.GetValue(0);
reader.Close();
return val;
}
Posted: Fri 17 Dec 2004 13:50
by Oleg
We'll fix this problem at the next build of MySQLDirect .NET.