Page 1 of 1

Select returns: Query OK, -1 rows affected

Posted: 25.02.2007, 13:00
by waheed
I have a select statement with a function call in MySQL 5.0.
It doesn't return any data with Query OK, -1 rows affected as a result, but I remove the function it returns the data I asked for. The result without using the function get 65000 records.

What could be the problem?
The function is listed in Integer field treated as Largeint

I tried doing a search on google but -1 is seen as 1!! and I don't find an answer.

This is not related to the zeos bug, but it uses the same function.

Posted: 25.02.2007, 13:50
by mdaems
From the mysql C API reference :
25.2.3.1. mysql_affected_rows()
my_ulonglong mysql_affected_rows(MYSQL *mysql)

Description

Returns the number of rows changed by the last UPDATE, deleted by the last DELETE or inserted by the last INSERT statement. May be called immediately after mysql_query() for UPDATE, DELETE, or INSERT statements. For SELECT statements, mysql_affected_rows() works like mysql_num_rows().

Return Values

An integer greater than zero indicates the number of rows affected or retrieved. Zero indicates that no records were updated for an UPDATE statement, no rows matched the WHERE clause in the query or that no query has yet been executed. -1 indicates that the query returned an error or that, for a SELECT query, mysql_affected_rows() was called prior to calling mysql_store_result(). Because mysql_affected_rows() returns an unsigned value, you can check for -1 by comparing the return value to (my_ulonglong)-1 (or to (my_ulonglong)~0, which is equivalent).
So, my best guess is : function error on one of your data rows. We don't have your data, so we can't find that out ourselves.
I suppose you already tried your query with a where clause that limits to one row?

It worked (at least : didn't fail) when I debugged Bug 16.

Success!!
Mark

Posted: 25.02.2007, 14:12
by waheed
You're right. Thanks again. Data was wrong.