Finish a RHS branch before applying ASC/DESC mods
Peter Rabbitson [Sun, 9 Jun 2013 11:28:35 +0000 (13:28 +0200)]
Changes
lib/SQL/Abstract/Tree.pm
t/10test.t
t/11parser.t

diff --git a/Changes b/Changes
index a9d3acc..94b71b1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for SQL::Abstract
 
+    - Fix false negative comparison of ORDER BY <function> ASC
+
 revision 1.74  2013-06-04
 ----------------------------
     - Fix insufficient parenthesis unroll during operator comparison
index 5c887db..60a1aa2 100644 (file)
@@ -478,6 +478,7 @@ sub _recurse_parse {
 
       # deal with post-fix operators (asc/desc)
       if ($tokens->[0] =~ $asc_desc_re) {
+        return @left if $state == PARSE_RHS;
         @left = [ ('-' . uc (shift @$tokens)) => [ @left ] ];
       }
 
index f3835a1..68de857 100644 (file)
@@ -611,6 +611,13 @@ my @sql_tests = (
         ],
       },
       {
+        equal => 1,
+        statements => [
+          q/ORDER BY colA, colB LIKE ? DESC, colC LIKE ?/,
+          q/ORDER BY colA ASC, colB LIKE ? DESC, colC LIKE ? ASC/,
+        ],
+      },
+      {
         equal => 0,
         opts => { order_by_asc_significant => 1 },
         statements => [
index 8735ffe..eaf5616 100644 (file)
@@ -619,7 +619,7 @@ is_deeply($sqlat->parse("SELECT x, y FROM foo WHERE x IN (?, ?, ?, ?)"), [
   ]
 ], 'Lists parsed correctly');
 
-is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? DESC, unf, baz.g / ? ASC, buzz * 0 DESC, foo DESC, ickk ASC'), [
+is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? DESC, unf, baz.g / ? ASC, buzz * 0 DESC, foo LIKE ? DESC, ickk ASC'), [
   [
     "SELECT",
     [
@@ -776,11 +776,22 @@ is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? D
             "-DESC",
             [
               [
-                "-LITERAL",
+                "LIKE",
                 [
-                  "foo"
-                ]
-              ]
+                  [
+                    "-LITERAL",
+                    [
+                      "foo"
+                    ]
+                  ],
+                  [
+                    "-PLACEHOLDER",
+                    [
+                      "?"
+                    ]
+                  ],
+                ],
+              ],
             ]
           ],
           [
@@ -1109,19 +1120,16 @@ is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz)
             ],
           ],
           [
-            "max",
-            [
-              [
                 "-DESC",
                 [
                   [
                     "-MISC",
                     [
                       [
-                        "-MISC",
+                        "-DESC",
                         [
                           [
-                            "-DESC",
+                            "max",
                             [
                               [
                                 "-PAREN",
@@ -1134,22 +1142,20 @@ is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz)
                                   ]
                                 ]
                               ]
-                            ]
-                          ],
-                          [
-                            "-LITERAL",
-                            [
-                              "x"
-                            ]
-                          ],
+                            ],
+                          ]
                         ]
                       ],
                       [
                         "-LITERAL",
                         [
-                          "z"
+                          "x"
                         ]
-                      ]
+                      ],
+                  [
+                    "-LITERAL",
+                    [
+                      "z"
                     ]
                   ]
                 ]