[Gambas-user] How to get the number of affected rows in mysql?

Bruce bbruen at ...2308...
Thu Jul 4 06:51:32 CEST 2013


On Thu, 2013-07-04 at 00:25 -0400, Zach Smith wrote:
> Hi,
> 
> How can one get the number of affected rows from a mysql query in gambas?
> 
> See https://dev.mysql.com/doc/refman/5.1/en/mysql-affected-rows.html
> "It returns the number of rows changed, deleted, or inserted by the
> last statement if it was an UPDATE, DELETE, or INSERT"
> 
> I've experimented with running SELECT ROW_COUNT() after an update
> query but I am unable to get a result that is the number of rows
> changed.
> 
> See https://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_row-count
> 
> Thanks,
> Zach
> 
Presumeably you are using an Exec(query) call to do your update.

The short answer is, you can't.  There are various reasons for this and
in any case if you read the mysql documentation and forums carefully
you'll find that this approach is not actually guaranteed to return the
"correct" value in all cases.

Probably the best approach is to use a SELECT query followed by your
update query and wrap it all in a commit block.  The result count from
the select query will give you the right answer.

hth
Bruce






More information about the User mailing list