Bug #9972 Client
Submitted: 18 Apr 2005 14:16 Modified: 19 May 2005 7:56
Reporter: Popescu Cosmin Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / ODBC Documentation Severity:S2 (Serious)
Version:5.0.3 beta OS:Windows (Windows)
Assigned to: CPU Architecture:Any

[18 Apr 2005 14:16] Popescu Cosmin
Description:
When I use sum function in a query from Visual Basic (MyODBC 3.1), I get the error Multiple-step operation generated errors. Example: 

select sum(employee) from table;

But, if I create the function:

create function correction(n double(15,3)) returns double(15,3)
begin
  return n;
end;

and then I try

select correction(sum(employee)) from table, everything it's OK. 

I mention that I tested 5.0.2 alpha version and I did not have this problem. 

I try everything and nothing seems to work. 

The only solution is (from vb) to use a server side cursor. But then, the recordcount property won't work. 

Also, if I try select sum(field_name) from table_name in client line editor, it works just fine. 

How to repeat:
select sum(field_name) from table_name;

Suggested fix:
I suppose the problem is from the ODBC connector.
[18 Apr 2005 16:01] MySQL Verification Team
I wasn't able to repeat using ADO with Access 2003 and 3.51.11-1.
Could you please provide a code test case like you are
using ?

Thanks in advance.
[19 Apr 2005 7:56] Popescu Cosmin
The exact query is

select (sum(intrare-iesire)) as mstoc from nir where cod_p=911

I use VB .NET. 

I didn't try this from Access. 

The connection string is 

DRIVER={MySQL ODBC 3.51 Driver};database=dbname;server=server;uid=UserID;pwd=UserPassword;

I pass this string to an ADODB.Connection:

dim cnstr as string="DRIVER={MySQL ODBC 3.51 Driver};database=dbname;server=server;uid=UserID;pwd=UserPassword;"
dim db as new adodb.connection
db.connectionstring=cnstr

Try
  db.Open()
Catch err As System.Exception
  MsgBox(err.Message)
  Application.Exit()
  Exit Sub
End Try

dim rec as new adodb.recordset
dim sql as string="select (sum(intrare-iesire)) as mstoc from nir where cod_p=911"

rec.ActiveConnection = db
rec.CursorLocation = ADODB.CursorLocationEnum.adUseClient
rec.Open(sql, db, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockPessimistic)

This is the code. After rec.open, I get the error Multiple-step operation generated errors. 
If i change rec.CursorLocation = ADODB.CursorLocationEnum.adUseClient to rec.CursorLocation = ADODB.CursorLocationEnum.adUseServer, then the query works, but the RecordCount property returns -1. 
Also, if I change the query to 
sql=select correction(sum(intrare-iesire)) as mstoc from nir where cod_p=911 it works, but then I have a huge program. I can't change all the queries that use sum function. I hope there is a workaround without having to change my code. 

Thank you for the reply.
[19 May 2005 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".