Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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