List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:February 15 2009 6:09pm
Subject:Re: How to execute prepare statement when the placeholder is a
specific table name?
View as plain text  
On Feb 14, 2009, at 8:00 PM, Moon's Father wrote:

> Thanks for your fast reply.
>
> Do you know MySQL will support  this feature in the future?

It doesn't need to. Baron indicated how you can solve this problem.

If you look at prepared statements in general (not just for MySQL),  
placeholders are for data values, not identifiers.

> On Sun, Feb 15, 2009 at 12:59 AM, Baron Schwartz <baron@stripped>  
> wrote:
>
>> Hello,
>>
>> On Sat, Feb 14, 2009 at 11:15 AM, Moon's Father
>> <yueliangdao0608@stripped> wrote:
>>> Here is my routine.
>>> DELIMITER $$
>>>
>>> CREATE
>>>   PROCEDURE `t_girl`.`sp_join2`()
>>>   BEGIN
>>>   set @a = 'a';
>>>   set @b = 'g';
>>>   set @stmt = concat('select * from ?,? where a.id = g.id');
>>>   prepare s1 from @stmt;
>>>   execute s1;
>>>   drop prepare s1;
>>>   END$$
>>>
>>> DELIMITER ;
>>>
>>> But it didn't work for me.
>>> So what I want to know is how to table name when there're a  
>>> placeholder
>>> within sproc.
>>
>> You can't use placeholders for identifiers, only for literal values.
>> So you will need to use CONCAT() to build the string with the
>> identifiers already in it, before you PREPARE.
>>
>>
>> --
>> Baron Schwartz, Director of Consulting, Percona Inc.
>> Our Blog: http://www.mysqlperformanceblog.com/
>> Our Services: http://www.percona.com/services.html
>>
>
>
>
> -- 
> I'm a MySQL DBA in china.
> More about me just visit here:
> http://yueliangdao0608.cublog.cn

-- 
Paul DuBois
Sun Microsystems / MySQL Documentation Team
Madison, Wisconsin, USA
www.mysql.com

Thread
How to execute prepare statement when the placeholder is a specific table name?Moon's Father14 Feb
  • Re: How to execute prepare statement when the placeholder is a specific table name?Baron Schwartz14 Feb
    • Re: How to execute prepare statement when the placeholder is a specific table name?Moon's Father15 Feb
      • Re: How to execute prepare statement when the placeholder is aspecific table name?Paul DuBois15 Feb
        • Re: How to execute prepare statement when the placeholder is aspecific table name?Joerg Bruehe15 Feb
          • Re: How to execute prepare statement when the placeholder is aspecific table name?Joerg Bruehe15 Feb