List:General Discussion« Previous MessageNext Message »
From:Manasi Save Date:September 14 2009 5:09am
Subject:Mysql prepare statement
View as plain text  
Hi All,

I have a query about prepare statement of mysql. I want to use prepare
stmt for insert-update-delete with a dynamic dbname,So can anyone provide
any input how i can make prepare stmt and then after that provide a value
at runtime. for example :-

prepare stmt from Concat('Insert into ',?,'.IgnoreContact (testid)',
            'Select ',?,',';');

Below is the procedure where i am preparing stmt at runtime. whereas i
want to pass the values at runtime.

If anyone can provide any information and links where i can find
information abt mysql prepare stmt from stored procedure.

DELIMITER $$

DROP PROCEDURE IF EXISTS `SP_Test` $$
CREATE DEFINER=`testuser`@`localhost` PROCEDURE `SP_Test`(InputTestID
Bigint, DBName Varchar(100))
BEGIN

SET @stmt = Concat('Insert into ',DBName,'.IgnoreContact (testid)',
            'Select ',InputTestID,';');

Prepare stmt1 From @stmt;
Execute stmt1;
Deallocate prepare stmt1;

END $$

DELIMITER ;

Thanks in advance.

-- 
Regards,
Manasi Save
Artificial Machines Pvt Ltd.



Thread
Mysql prepare statementManasi Save14 Sep
  • Re: Mysql prepare statementJohan De Meersman14 Sep