From c1d71213bdb6f5d326f5cc5a55e645a8edf2e589 Mon Sep 17 00:00:00 2001 From: Aleksey Yeschenko Date: Mon, 8 Jul 2013 22:57:35 +0300 Subject: [PATCH] cqlsh: fix handling of semicolons inside BATCH queries patch by Aleksey Yeschenko; reviewed by Brandon Williams for CASSANDRA-5697 --- CHANGES.txt | 1 + pylib/cqlshlib/cql3handling.py | 4 ++-- pylib/cqlshlib/cqlhandling.py | 10 ++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7c16cd0382..65dd404d34 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -9,6 +9,7 @@ * Fix skipping range tombstones with reverse queries (CASSANDRA-5712) * Expire entries out of ThriftSessionManager (CASSANRDA-5719) * Don't keep ancestor information in memory (CASSANDRA-5342) + * cqlsh: fix handling of semicolons inside BATCH queries (CASSANDRA-5697) 1.2.6 diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index 0e631ea5ff..92701d61bc 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -986,8 +986,8 @@ syntax_rules += r''' ::= "BEGIN" ( "UNLOGGED" | "COUNTER" )? "BATCH" ( "USING" [batchopt]= ( "AND" [batchopt]= )* )? - [batchstmt]= ";" - ( [batchstmt]= ";" )* + [batchstmt]= ";"? + ( [batchstmt]= ";"? )* "APPLY" "BATCH" ; ::= diff --git a/pylib/cqlshlib/cqlhandling.py b/pylib/cqlshlib/cqlhandling.py index 83e1dc2fd8..7d36301e36 100644 --- a/pylib/cqlshlib/cqlhandling.py +++ b/pylib/cqlshlib/cqlhandling.py @@ -189,13 +189,11 @@ class CqlParsingRuleSet(pylexotron.ParsingRuleSet): output[-1].extend(stmt) else: output.append(stmt) - if len(stmt) > 1 \ - and stmt[0][0] == 'identifier' and stmt[1][0] == 'identifier' \ - and stmt[1][1].lower() == 'batch': - if stmt[0][1].lower() == 'begin': - in_batch = True - elif stmt[0][1].lower() == 'apply': + if len(stmt) > 2: + if stmt[-3][0] == 'K_APPLY': in_batch = False + elif stmt[0][0] == 'K_BEGIN': + in_batch = True return output, in_batch def cql_complete_single(self, text, partial, init_bindings={}, ignore_case=True,