Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that the <code>IF</code> control flow construct only works in stored procedures (Just like all other <a href="http://dev.mysql.com/doc/refman/5.0/en/flow-control-constructs.html" rel="nofollow">Flow Control Constructs</a>... So you'd need to define a procedure to do what you're asking...</p> <p>So here's how to define sample procedure to do what you want:</p> <pre><code>DELIMITER // CREATE PROCEDURE myProcedure() BEGIN SET @cv = (SELECT `value` FROM `configs` WHERE `name` = 'cvDate'); IF @cv &lt;= STR_TO_DATE("2010/11/10 12:15:00") THEN ALTER TABLE `feeds` ADD `tone` VARCHAR( 255 ) NOT NULL AFTER `type` , ADD `authority` DECIMAL( 2, 1 ) NOT NULL DEFAULT '0.0' AFTER `tone`; END IF; UPDATE `configs` SET `value` = NOW() WHERE `name` = "cvDate"; END// DELIMITER ; </code></pre> <p>That will create it, then to run it, just do:</p> <pre><code>CALL myProcedure(); </code></pre> <p>See <a href="http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html" rel="nofollow">the docs</a> for more info.</p> <p>You can actually even make it take parameters so you don't need to hard-code everything. But I'm not sure how you would do that based upon what you provided (I'm not sure what exactly you're trying to accomplish)...</p> <p>If you want to make it take a sql statement as a parameter (using <a href="http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html" rel="nofollow">Prepared Statements</a> ):</p> <pre><code>DELIMITER // CREATE PROCEDURE myInputProcedure(IN updateDate DATETIME, IN sql TEXT) BEGIN SET @cv = (SELECT `value` FROM `configs` WHERE `name` = 'cvDate'); IF @cv &lt;= updateDate THEN PREPARE stmt1 FROM sql; EXECUTE stmt1; END IF; UPDATE `configs` SET `value` = NOW() WHERE `name` = "cvDate"; END// DELIMITER ; </code></pre> <p>Then, simply call it like this:</p> <pre><code>@sql = 'ALTER TABLE `feeds` ADD `tone` VARCHAR( 255 ) NOT NULL AFTER `type` , ADD `authority` DECIMAL( 2, 1 ) NOT NULL DEFAULT '0.0' AFTER `tone`;'; @date = STR_TO_DATE("2010/11/10 12:15:00"); CALL myInputProcedure(@date, @sql); </code></pre> <p>(Note that I added <code>@sql</code> and <code>@date</code> for readability, not because they are necessary)...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload