Page 1 of 1

how mysql_affected_rows() should be called in stored procedures.

Posted: Mon 26 May 2008 08:43
by charbel
Dear Dimon,
im trying to create a stored procedure that when posting a table , it update or create records in another table . here is my code:

DELIMITER $$

DROP PROCEDURE IF EXISTS `jmg_acc2007`.`LdgB4Post_CreateClt` $$
CREATE PROCEDURE `jmg_acc2007`.`LdgB4Post_CreateClt` (LNumb varchar(10), LName varchar(50),LCur varchar (6), LBlngGrp int(11) )
BEGIN


update clients
set Ledger_name = LName
where Ledger_number = LNumb;

if mysql_affected_rows() = 0 then
insert into clients(Ledger_number, Ledger_name, Currency_Code, Client_BelongsToGroup)
values (LNumb, LName, LCur, LBlngGrp);
end if;
END $$

DELIMITER ;

executing this procedure in the MySqlBrowser is working properly , but once i call this procedure from Borland developper studion 2006, it kept giving me that function mysql_affected_rows() does not exist in my database. i know that. its a mysql function. what should i do?

Posted: Tue 27 May 2008 09:31
by Dimon
mysql_affected_rows() is a C API function that can not be called from stored pocedure.
You can use the ROW_COUNT() MySQL function that returns the same value as mysql_affected_rows().

Posted: Tue 27 May 2008 10:05
by charbel
thanks for ur help.