Bug #10527 SUM function doesn't work using VB 6.0 / ADO
Submitted: 11 May 2005 3:48 Modified: 11 Jun 2007 15:47
Reporter: Javier Rodriguez Paiva Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:3.51.11,3.51.12 OS:Windows (Windows XP Home SP2)
Assigned to: Bogdan Degtyariov CPU Architecture:Any

[11 May 2005 3:48] Javier Rodriguez Paiva
Description:
The SUM aggregate function doesn't work when using VB 6.0/ ADO to connect to a MySQL 5.0.4-beta Server. I'm using MyODBC 3.51.11-2 as ODBC Driver. It always returns the following error message:
"Multiple-step operation generated errors. check each status value"

The query worked allright when using MySQL 5.0.2-alfa Server.

How to repeat:
Just make any query involving SUM using the configuration described above.
[11 May 2005 4:08] Javier Rodriguez Paiva
10-05-2005 23:08 GMT -0500: Updated Severity
[13 May 2005 19:34] MySQL Verification Team
Could you please submit a test code case (for to be tested using Access)
together with your database schema and dump file with data.

Thanks in advance.
[16 May 2005 20:35] MySQL Verification Team
Yes you can comment in Spanish if you want.

Thank you.
[19 May 2005 14:19] Katja Fahrenholz
I have experiences with a similar problem. Also using VB 6.0 with ado and got this error. Fixed the problem in my case with replacing the summed datatype from integer to double and no more errors occured. I tried several datatypes, but only double worked without errors.
[24 May 2005 5:23] Javier Rodriguez Paiva
how do i generate a dump file?
[24 May 2005 5:45] MySQL Verification Team
Javier,

You can use the mysqldump.exe client which you find in your
bin directory or you can use the MySQL Administrator you
find it at:
http://dev.mysql.com/downloads/administrator/index.html

How to use mysqldump please read:

http://dev.mysql.com/doc/mysql/en/mysqldump.html
[24 May 2005 21:50] Javier Rodriguez Paiva
Hi Miguel, the command fails even using a very simple database schema. Here's a test case:

1. Create a test table and populate it (using MySQL 5.0.4-beta both client and server)

mysql> use test;
mysql> create table T_Prueba ( PruebaID INT AUTO_INCREMENT, data INT, CONSTRAINT PK_T_Prueba PRIMARY KEY (PruebaID));
mysql> INSERT INTO T_Prueba (data) VALUES (100); 
mysql> INSERT INTO T_Prueba (data) VALUES (120);
mysql> INSERT INTO T_Prueba (data) VALUES (180);

2. Check the query works
mysql> SELECT SUM(data) FROM T_Prueba;
Query OK, returns 400.

3. Create a VB6.0 (SP6) Proyect and add a reference to Microsoft ActiveX Data Objects 2.8 Library

4. Put this code into Proyect

Option Explicit

Private Sub Form_Load()
    Dim oCn As New ADODB.Connection
    Dim oRs As New ADODB.Recordset
    
    Dim strSQL As String
    
    oCn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;USER=javier;PASSWORD=javier;"
    oCn.Open
      
    strSQL = "SELECT SUM(data) FROM t_Prueba"
    oRs.CursorLocation = adUseClient
    oRs.Open strSQL, oCn, adOpenForwardOnly, adLockReadOnly
    
    MsgBox oRs.Fields(0)
    
    oRs.Close
    Set oRs = Nothing
    
    oCn.Close
    Set oCn = Nothing
End Sub

5. Run the program and watch it crash: "Multiple-step operation generated errors. check each status value"

It does work if you just use 'SELECT data FROM T_Prueba' instead of using SUM.
[25 May 2005 7:15] Vasily Kishkin
I created test-case and tried to run. oRs.Open() returns the error with we use adUseClient in CursorLocation. if we set adUseServer oRs.Open() returns oRs.Fields(0).Type as adEmpty. 
I attached my test-case.
[25 May 2005 7:16] Vasily Kishkin
Test case

Attachment: 10527.zip (application/x-zip-compressed, text), 3.22 KiB.

[25 May 2005 15:01] Javier Rodriguez Paiva
I'm not really sure whether the problem is the connector or the database server, because the problem only appears since from 5.0.3-beta and on (I'm having a production server running on 5.0.2-alfa!!!!) , yet, if you make the query directly from the client, it works without problems (in 5.0.4-beta).
[30 May 2005 6:16] Vasily Kishkin
Anyway oRs.Fields(0) is returned with bad value. I set this is as a bug.
Tested on Win 2000 Sp4, MySQL server 5.0.6 beta,Microsoft Visual Basic .NET,
MyODBC 3.51.11
[1 Jun 2005 17:31] Javier Rodriguez Paiva
Have you guys already found out whether this is a server bug or a connector bug?
[7 Jun 2005 16:10] Marek Srom
I have similar problem when i open recordset adUseclient just like select sum(X) from t_table (t_table is empty - no rows). When i use adUseServer, it works good, but it does not return 1 row with NULL value as it should, but returns empty recordset. For example select COUNT(x)  from t_table returns 1 row with 0, and select count(x), sum(x) from t_table returns empty recordset... I guess here is something wrong.

Marek
[9 Jun 2005 18:47] Bogdan Degtyariov
Added new data type MYSQL_TYPE_NEWDECIMAL. (Changeset@1.476)

This example works well with the  MySQL 5.0.4, but if the similar problems will appear it is strongly recommended to use MySQL 5.0.6.
[9 Jun 2005 20:51] Javier Rodriguez Paiva
When will this patch be released? Is a connector or a server patch?
[20 Jun 2005 16:25] Javier Rodriguez Paiva
I just saw the patch in the development tree, when will it be released as a binary?
[18 Jul 2005 9:38] Bogdan Degtyariov
Hi Javier,

MYSQL_TYPE_NEWDECIMAL patch will be applied in the version 3.51.12.
We expect to make this release in about 2 weeks
[5 Aug 2005 15:36] Luis A S Junior Camargo
Only for the commentary, I already had reported this error in following bugs:

http://bugs.mysql.com/bug.php?id=10103 (MyODBC)
and
http://bugs.mysql.com/bug.php?id=10293 (Server)
[28 Aug 2005 17:43] Armando Basile
I try a sum function on mySQL 5.0.11 beta from an ASP page

	Dim myConn
	Set myConn = Server.CreateObject("ADODB.Connection")

	Dim myRSet
	Set myRSet = Server.CreateObject("ADODB.Recordset")

	Dim laRisposta

	myConn.Open "DRIVER={MySQL ODBC 3.51 Driver}; " & _
                "SERVER=xxxxxxxxx; " & _
                "DATABASE=prova; " & _
                "UID=root; PWD=xxxxxxx; option=3 "

	theSQL = "SELECT sum(qtain) AS QIN, sum(scarti) AS QFAILS " & _
			 "FROM avanzamento " & _
			 "WHERE id_prodotto = 1 AND " & _
	         "id_fase = 1"

	myRSet.Open theSQL, myConn

but NOTHING, the Recordset is EMPTY, but if i use Query Browser, it's ok. So is possible that the problem is in OPTION value ????
[30 Aug 2005 4:55] Luis A S Junior Camargo
Hi Armando Basile,

The problem is in the MyODBC, the Query Browser don't use the MyODBC, the patch already has approved, but only in the next version 3.51.12

good bye
[30 Aug 2005 6:16] Javier Rodriguez Paiva
Is there an estimate date for the release of myODBC 3.51.12?
[1 Sep 2005 12:44] Armando Basile
also i would like to know when will be release the version .12, approximately of course
[8 Sep 2005 19:09] Armando Basile
Can we know an estimate date for the release of myODBC 3.51.12?

I would like to use mysql on my website, but if odbc connector don't work... how can i do ?

:-)
[28 Sep 2005 4:44] Mark Neil Borromeo
Can I possibly use this?

Connect.open = "Provider=MySqlProv;eng=;datasource;dbn=dbname;uid;balh;pwd;blah")

in Visual Basic.. :) But anyway, I successfully used MyODBC but I am
curious in it..
[7 Nov 2005 17:21] Gerson Alvarez
i`m waiting for the release of the ODBC wich solves this case.
While we wait, can someone tell me if there is a oledb provider designed for mysql?
[8 Nov 2005 17:46] Gerson Alvarez
hey, i have downloaded and installed all the official releases of server, tools and odbc and the problem persists, am i doing something wrong or the bug has not been solved
[22 Dec 2005 20:46] Howard Chiu
A work around for this problem is to create a view and grab the information from the view.  That way you don't need to use the SUM function in the ODBC driver.
[18 Jan 2006 20:45] Peter Hansson
This is not working for me either.
I also tested the workaround by using a view. This only results in that the MySQL server terminate and has to be restarted. I should really need the Aggregate functions to work over MyODBC....
[12 May 2006 12:53] Peter Ensor
Still does not work with ODBC connect 3.51.12 and server 5.0.21.

The test case I used was
create table test (data as int);
insert into test values (4),(5),(6);

The visual studio 2005 express code was

            long hithere;
            MySqlConnection connSource = new MySqlConnection("database=peter;host=10.101.0.164;user id=remote2;password=hello;");
            connSource.Open();

            //MySqlCommand command = new MySqlCommand("select CAST( avg(data) as SIGNED INTEGER) from test", connSource);
            MySqlCommand command = new MySqlCommand("select avg(data) from test", connSource);

            MySqlDataReader reader  = command.ExecuteReader();
				MySqlDataReader queryReader;

                while (reader.Read())
                {
                    hithere = (long) reader.GetInt64(0);
                }

The version with the CAST in it does work but the version without it doesn't.
It works fine on version 4 of the server as the other bug reports also point out.

When I capture the MySQL protocol in ethereal I get
0000  00 05 9a 3c 78 00 da e7  20 00 01 00 08 00 45 00   ...<x...  .....E.
0010  00 6d 64 b8 40 00 80 06  80 33 0a 65 00 a4 0a 65   .md.@... .3.e...e
0020  00 32 0c ea 06 34 16 c2  50 30 69 22 48 82 50 18   .2...4.. P0i"H.P.
0030  ff 34 50 30 00 00 01 00  00 01 01 1f 00 00 02 03   .4P0.... ........
0040  64 65 66 00 00 00 09 61  76 67 28 64 61 74 61 29   def....a vg(data)
0050  00 0c 3f 00 10 00 00 00  f6 80 00 04 00 00 05 00   ..?..... ........
0060  00 03 fe 00 00 22 00 07  00 00 04 06 35 2e 30 30   .....".. ....5.00
0070  30 30 05 00 00 05 fe 00  00 22 00                  00...... .". 

In particular byte 58 states that the field is a LONGLONG but byte 5B gives the integer 4 decimal places.

The dump from version 4 server is
0000  00 05 9a 3c 78 00 da e7  20 00 01 00 08 00 45 00   ...<x...  .....E.
0010  00 69 89 05 40 00 80 06  5b eb 0a 65 00 a3 0a 65   .i..@... [..e...e
0020  00 32 0c ea 06 3f 2b 55  b0 61 d4 2a 5a fc 50 18   .2...?+U .a.*Z.P.
0030  fb 4c 8d 6e 00 00 01 00  00 01 01 1f 00 00 02 03   .L.n.... ........
0040  64 65 66 00 00 00 09 61  76 67 28 64 61 74 61 29   def....a vg(data)
0050  00 0c 08 00 11 00 00 00  05 00 00 04 00 00 01 00   ........ ........
0060  00 03 fe 07 00 00 04 06  35 2e 30 30 30 30 05 00   ........ 5.0000..
0070  00 05 fe 00 00 22 00                               .....". 
and this is different because it identifies the result in byte 58 as a decimal and with 4 decimal places.

It appears that the change to version 5 has changed the values put into the protocol.
[23 Apr 2007 19:16] Rebeca Betsabe Alvarez Chavez
hola tengo varias dudas en realidad con lo que respecta a la conexion de mysql hacia visual basic 6.0. Como funciona exactamente la conexion entre ambos... pueden poner un poco de informacion sobre mysql en espaƱol? ya que a veces como estudiantes no tenemos mucho tiempo de traducir!
[11 Jun 2007 13:17] Bogdan Degtyariov
The last fragment of code seems to be working with Connector/.NET but not ODBC.
[11 Jun 2007 13:39] Bogdan Degtyariov
MyODBC 3.51.14/3.51.15 display the correct results for both VB6 and VB.NET test cases
[11 Jun 2007 15:47] Jim Winstead
Nothing to be documented here, closing the bug.