I had a problem executing a stored procedure with Perl (using the DBI module). If I do a simple SELECT * FROM table , no problem.
SQL code:
DROP FUNCTION IF EXISTS update_current_stock_price; DELIMITER | CREATE FUNCTION update_current_stock_price (symbolIN VARCHAR(20), nameIN VARCHAR(150), currentPriceIN DECIMAL(10,2), currentPriceTimeIN DATETIME) RETURNS INT DETERMINISTIC BEGIN DECLARE outID INT; SELECT `id` INTO outID FROM `mydb449`.`app_stocks` WHERE `symbol` = symbolIN; IF outID > 0 THEN UPDATE `mydb449`.`app_stocks` SET `currentPrice` = currentPriceIN, `currentPriceTime` = currentPriceTimeIN WHERE `id` = outID; ELSE INSERT INTO `mydb449`.`app_stocks` (`symbol`, `name`, `currentPrice`, `currentPriceTime`) VALUES (symbolIN, nameIN, currentPriceIN, currentPriceTimeIN); SELECT LAST_INSERT_ID() INTO outID; END IF; RETURN outID; END| DELIMITER ;
Perl Code:
$sql = "select update_current_stock_price('$csv_result[0]', '$csv_result[1]', '$csv_result[2]', '$currentDateTime') as `id`;"; My::Extra::StandardLog("SQL being used: ".$sql); my $query_handle = $dbh->prepare($sql); $query_handle->execute(); $query_handle->bind_columns(\$returnID); $query_handle->fetch();
If I execute select update_current_stock_price('aapl', 'Apple Corp', '264.4', '2010-03-17 00:00:00') as id ; using the mysql CLI client, it correctly executes the stored function and returns an existing identifier or a new identifier.
However, Perl will only return a new identifier (an increment of 1 each time it starts). It also does not save the result in the database. It appears that it executes DELETE in the new identifier immediately after the update_current_stock_price function is update_current_stock_price .
Any help? Does Perl do anything interesting for procedures that I should know about?
Before you ask, I do not have access to the binary log, sorry.