def parse_bql_string(string): phrases = list(parse.parse_bql_string(string)) phrase_pos = list(parse.parse_bql_string_pos(string)) assert len(phrases) == len(phrase_pos) start = 0 for i in range(len(phrase_pos)): phrase, pos = phrase_pos[i] assert phrases[i] == phrase substring = buffer(string, start, len(string) - start) phrase0, pos0 = parse.parse_bql_string_pos_1(substring) assert phrase0 == phrase assert pos0 == pos - start start = pos return phrases
def _do_execute(self, string, bindings): phrases = parse.parse_bql_string(string) phrase = None try: phrase = phrases.next() except StopIteration: raise ValueError('no BQL phrase in string') try: phrases.next() except StopIteration: pass else: raise ValueError('>1 phrase in string') cursor = bql.execute_phrase(self, phrase, bindings) return self._empty_cursor if cursor is None else cursor
def default(self, line): # XXX What is this idiocy? End-of-input is reported the same # as the line with characters `E', `O', `F'. if line == 'EOF': self.stdout.write('\nMoriturus te querio.\n') return True if self.prompt == self.def_prompt: if line.startswith('.'): cmd = line for i, c in enumerate(line): if c in (' ', '\t'): cmd = line[:i] break self.stdout.write('Unknown command: %s\n' % (cmd, )) return False # Add a line and check whether it finishes a BQL phrase. self.bql.write(line) self.bql.write('\n') string = self.bql.getvalue() if parse.bql_string_complete_p(string): # Reset the BQL input. self.bql = StringIO.StringIO() self.prompt = self.def_prompt try: first = True for phrase in parse.parse_bql_string(string): cursor = bql.execute_phrase(self._bdb, phrase) with txn.bayesdb_caching(self._bdb): # Separate the output tables by a blank line. if first: first = False else: self.stdout.write('\n') if cursor is not None: pretty.pp_cursor(self.stdout, cursor) except (bayeslite.BayesDBException, bayeslite.BQLParseError) as e: self.stdout.write('%s\n' % (e, )) except Exception: self.stdout.write(traceback.format_exc()) else: self.prompt = self.bql_prompt return False
def default(self, line): # XXX What is this idiocy? End-of-input is reported the same # as the line with characters `E', `O', `F'. if line == 'EOF': self.stdout.write('\nMoriturus te querio.\n') return True if self.prompt == self.def_prompt: if line.startswith('.'): cmd = line for i, c in enumerate(line): if c in (' ', '\t'): cmd = line[:i] break self.stdout.write('Unknown command: %s\n' % (cmd,)) return False # Add a line and check whether it finishes a BQL phrase. self.bql.write(line) self.bql.write('\n') string = self.bql.getvalue() if parse.bql_string_complete_p(string): # Reset the BQL input. self.bql = StringIO.StringIO() self.prompt = self.def_prompt try: first = True for phrase in parse.parse_bql_string(string): cursor = bql.execute_phrase(self._bdb, phrase) with txn.bayesdb_caching(self._bdb): # Separate the output tables by a blank line. if first: first = False else: self.stdout.write('\n') if cursor is not None: pretty.pp_cursor(self.stdout, cursor) except (bayeslite.BayesDBException, bayeslite.BQLParseError) as e: self.stdout.write('%s\n' % (e,)) except Exception: self.stdout.write(traceback.format_exc()) else: self.prompt = self.bql_prompt return False