ExecuteScalar

ExecuteScalar

Postby joshmouch » Mon 13 Dec 2004 22:40

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.
joshmouch
 
Posts: 12
Joined: Sat 11 Dec 2004 05:54

Test case

Postby joshmouch » Mon 13 Dec 2004 23:33

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.
joshmouch
 
Posts: 12
Joined: Sat 11 Dec 2004 05:54

Re: Test case

Postby Oleg » Tue 14 Dec 2004 08:51

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.
Oleg
Devart Team
 
Posts: 264
Joined: Thu 28 Oct 2004 13:56

Re: Test case

Postby Guest » Tue 14 Dec 2004 13:04

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.
Guest
 

Re: Test case

Postby Oleg » Tue 14 Dec 2004 15:42

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.
Oleg
Devart Team
 
Posts: 264
Joined: Thu 28 Oct 2004 13:56

Postby Guest » Thu 16 Dec 2004 15:39

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;
      }
Guest
 

Postby Oleg » Fri 17 Dec 2004 13:50

We'll fix this problem at the next build of MySQLDirect .NET.
Oleg
Devart Team
 
Posts: 264
Joined: Thu 28 Oct 2004 13:56


Return to dotConnect for MySQL