Bug #58714 Query Beautify: NOW() function incorrectly modified
Submitted: 3 Dec 2010 17:53 Modified: 8 Mar 2011 15:51
Reporter: Mark Garrett Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench: SQL Editor Severity:S3 (Non-critical)
Version:5.2.30 OS:Any
Assigned to: Alfredo Kojima CPU Architecture:Any
Tags: plugins, query reformat, workbench

[3 Dec 2010 17:53] Mark Garrett
Description:
The plugin formatter incorrectly modifies the NOW() function to the point it will not execute.

How to repeat:
SELECT * FROM bugs WHERE created_date < NOW()

The formatter outputs:

SELECT 
        *
    FROM
        bugs
    WHERE
        created_date < NOW ( )

Suggested fix:
Remove the space after the W and remove space between empty parentheses 

SELECT 
        *
    FROM
        bugs
    WHERE
        created_date < NOW()
[3 Dec 2010 18:05] Valeriy Kravchuk
Thank you for the bug report. Verified on Mac OS X.
[8 Dec 2010 19:13] Alfredo Kojima
Fixed in repository. Here is the patch if you want to fix in the current version:

--- sql_reformatter.py	2010-11-29 23:04:51 +0000
+++ sql_reformatter.py	2010-12-08 19:11:54 +0000
@@ -308,6 +308,10 @@
                 node = "*simple_expression", flatten_node(node, " "), []
                 c = []
 
+        elif s in ["function_call_keyword", "function_call_nonkeyword", "function_call_generic", "function_call_conflict"]:
+            node = "*"+s, flatten_node(node, ""), []
+            c = []
+
         elif s in ["expr_list"]:
             ok = True
             for n in c:
[15 Feb 2011 22:53] Greg Barker
The Beautify Query also breaks the following:

SELECT SUM(field) FROM table
[3 Mar 2011 13:43] Johannes Taxacher
fix confirmed in repository
[8 Mar 2011 15:51] Tony Bedford
An entry has been added to the 5.2.32 changelog: 

        In the SQL Editor, the code beautifier did not process 
        NOW() correctly. It rendered the function 
        with additional spaces causing a syntax error.
[20 Aug 2014 18:30] Aram Mirzadeh
Using WB 6.1 community edition, this bug is now back: 

SELECT NOW() FROM DUAL;

after beautify: 

SELECT NOW () FROM DUAL;

Error when executed:

Action: SELECT NOW () FROM DUAL LIMIT 0, 100	
Error Code: 1630. FUNCTION TLMA25.NOW does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual	0.078 sec