Mysql prepare statement
am 14.09.2009 07:09:45 von Manasi Save
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.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org
Re: Mysql prepare statement
am 14.09.2009 10:44:47 von Johan De Meersman
You can't make the database, table or field names dynamic with
prepare, only values. Prepare allows you to cache the execution plan,
which wouldn't be valid on a different table.
On Mon, Sep 14, 2009 at 7:09 AM, Manasi Save
wrote:
> 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)',
> =A0 =A0 =A0 =A0 =A0 =A0'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=3D`testuser`@`localhost` PROCEDURE `SP_Test`(InputTestID
> Bigint, DBName Varchar(100))
> BEGIN
>
> SET @stmt =3D Concat('Insert into ',DBName,'.IgnoreContact (testid)',
> =A0 =A0 =A0 =A0 =A0 =A0'Select ',InputTestID,';');
>
> Prepare stmt1 From @stmt;
> Execute stmt1;
> Deallocate prepare stmt1;
>
> END $$
>
> DELIMITER ;
>
> Thanks in advance.
>
> --
> Regards,
> Manasi Save
> Artificial Machines Pvt Ltd.
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: =A0 =A0http://lists.mysql.com/mysql?unsub=3Dvegivamp@tuxe=
ra.be
>
>
--=20
That which does not kill you was simply not permitted to do so for the
purposes of the plot.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg