MySQL does support preparing some DDL statements, However…

Bill Kar­win gives some insight into some work arounds when cre­at­ing func­tions, trig­gers and pro­ce­dures using Zend Framework;

MySQL does sup­port prepar­ing some DDL state­ments, even in older ver­sions. See http://dev.mysql.com/doc/refman/5.1/en/sql-syntax-prepared-statements.html
for lists of what state­ments can be prepared.

How­ever, some DDL state­ments are still not sup­ported as pre­pared state­ments, for exam­ple CREATE FUNCTION, CREATE TRIGGER, CREATE PROCEDURE.

DELIMITER is not sup­ported as an exe­cutable state­ment at all, whether you pre­pare it or whether you do an imme­di­ate exe­cute. State­ments like DELIMITER, PAGER, SOURCE, CONNECT, and QUIT and oth­ers are builtins of the mysql command-line client. These com­mands are not rec­og­nized by the MySQL server.

You need to set the DELIMITER only if you’re run­ning the CREATE FUNCTION state­ment in an SQL script. The default API for SQL state­ments does not sup­port mul­ti­ple state­ments per call. So you don’t have to delimit state­ments and you don’t have to change the delimiter.

So Nils’s solu­tion should be the following:

1. Don’t worry about DELIMITER, you don’t need it.

2. You must DROP and CREATE in two sep­a­rate statements.

3. Bypass the default ZF query method. Go directly to the
PDO::query() method when you exe­cute a state­ment that isn’t prepara­ble. You can access the PDO object using the get­Con­nec­tion() method of your ZF Db adapter:

$db->getConnection()->query( $drop_function_statement );
$db->getConnection()->query( $create_function_statement );

Regards,
Bill Karwin

Tags: , ,

Leave a Comment

*

Get Adobe Flash playerPlugin by wpburn.com wordpress themes